mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.62k stars 1.25k forks source link

[BUG] #1925

Open laurenceSaes opened 3 years ago

laurenceSaes commented 3 years ago

Version LiteDB 5.0.9 Windows 10 .NET framework 4.8

Describe the bug Upgrading a database from version 4 to 5 often (but not always) results in a corrupt liteDB. This can be reproduced with the following database:

liteDatabase

The following error is given when querying data inside the database.

Error

The upgrade will result in the following corrupt database:

Corrupt LiteDatabase

Code to Reproduce

The also can be reproduced with LiteDB.Studio. Load the database and select the upgrade option. Try to browse any collection. The error is returned in the query window (when the database is corrupted by the upgrade).

Screenshots/Stacktrace

image

laurenceSaes commented 3 years ago

We resolved the issue. It appears that upgrading works when removing the config-log.litedb file next to the config.litedb. I assume that the log file was from another database.

What happens when a new database is created when an old log file still exists in the directory? Is the logfile reset before being used by the new database?

laurenceSaes commented 3 years ago

In summary, a write-ahead log of a different database or the log from a different state will prevent the database from loading. Is it possible to detect that the write-ahead log mismatches with the database and ignore the log if so?