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

LiteDB ENSURE: ReadFull must read PAGE_SIZE bytes [0] #2379

Open Chr1st1anAML opened 1 year ago

Chr1st1anAML commented 1 year ago

LiteDB v5.16 .NET 4.8

How can if fix that? Itryed litteraly EVERYTHING. Nothing worked.

GobGeeklord commented 1 year ago

Hi there,

Same problem here, running on .NET 6 on armv7 (LiteDB v5.0.15 and v5.0.17) and there are 2 complete diferent paths:

[ERROR][14][2023-11-07 11:03:59][Error] System.Exception: LiteDB ENSURE: ReadFull must read PAGE_SIZE bytes [0] at LiteDB.Constants.ENSURE(Boolean conditional, String message) at LiteDB.Engine.DiskService.ReadFull(FileOrigin origin)+MoveNext() at LiteDB.Engine.WalIndexService.<>c__DisplayClass19_0.<g__source|0>d.MoveNext() at LiteDB.Engine.DiskService.Write(IEnumerable`1 pages, FileOrigin origin) at LiteDB.Engine.WalIndexService.CheckpointInternal() at LiteDB.Engine.WalIndexService.TryCheckpoint() at LiteDB.Engine.LiteEngine.Dispose(Boolean disposing) at LiteDB.Engine.LiteEngine.Dispose() at LiteDB.LiteDatabase.Dispose(Boolean disposing) at LiteDB.LiteDatabase.Dispose() (...)

and

[ERROR][1][2023-11-07 10:13:07][Error] System.Exception: LiteDB ENSURE: ReadFull must read PAGE_SIZE bytes [0] at LiteDB.Constants.ENSURE(Boolean conditional, String message) at LiteDB.Engine.DiskService.ReadFull(FileOrigin origin)+MoveNext() at LiteDB.Engine.WalIndexService.RestoreIndex(HeaderPage& header) at LiteDB.Engine.LiteEngine..ctor(EngineSettings settings) at LiteDB.ConnectionString.CreateEngine() at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper) (...)

Context:

I was using LiteDB inside a static class, which had a Initialized method called once, that instantiates a global access LiteDatabase object, and the application always reuses the same object. This method never had the above exception, but sometimes the application has big data losses, where the database saves no documents. As this is an embedded restricted device, i have no runtime exception logs on if there is an exception when this happens.

After that, I've change this same class to declare

using var db = new LiteDatabase(_dbFilePath);

In every method to access database, and since then this exception occurrs very often.

Geektoolkit commented 1 month ago

What are people doing about this? I just moved my work to LiteDB, and will be moving away from it due to this issue. In this line num = 0, so it catches. I have one method on one thread which does all of my crud operations and opens it for read/write, the rest of them open it read only on another thread. There seems to be no guidance on the numerous issues I've seen opened on this other than 'delete all ' is slow, but I'm not deleting anything yet, just adding objects and trying to read them. Constants.ENSURE(num == 8192, "ReadFull must read PAGE_SIZE bytes [{0}]", num);