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] Rebuild operation requires no log file #2152

Open NoiseHustler opened 2 years ago

NoiseHustler commented 2 years ago

Litedb 5.0.10, Windows 10, .Net Core 3.1, WPF Checkpoint set to 0 (manual)

At application start we creating database connection to exist database and perform Checkpoint and after that Rebuild. Now on some clients I have exception on rebuild operation.

` var cs = new ConnectionString { Filename = fileName };

        try
        {
            db = new LiteDatabase(cs);

            db.Checkpoint();
            db.Rebuild();
            db.CheckpointSize = 0;
        }
        catch (Exception e)
        {
            Log.Fatal(e, "Database init error");

            throw;
        }`

Expected behavior: successfull rebuild

Stacktrace: LiteDB.LiteException: Rebuild operation requires no log file - run Checkpoint before continue at LiteDB.Engine.LiteEngine.Rebuild(RebuildOptions options) at LiteDB.LiteDatabase.Rebuild(RebuildOptions options)

Database log not truncated at all after checkpoint (~35 mb log, 90mb db).

BenWoodford commented 1 year ago

Did you ever work out how to fix this, or what causes it? We run Rebuild as well on start to detect some page errors but this has just popped up for the first time ever

lzziaini commented 1 year ago

Hello. I have the same question befor , but I found that i do rebuild Success while used LiteDb.Studio. Finally I identified the problem is, I didn't call db.Dispose() manually before closing the program。the log files will auto clear while call "db.Dispose()". And One more thing is you should make sure that dispose func run completed while closing you program.(I call dispose in destructor,but my program exit faster ,so dispose was not completed and log file still exist) Hope can help you. Good Luck.