-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
LiteDatabase.Shrink throws 'System.Collections.Generic.KeyNotFoundException' #892
Comments
@mbdavid any updates on this one? maybe you need extra context or some other info? |
Hi @shorstok, sorry, but I will check you case this weekend. During week days is more complicate debug some codes. I will return soon with an answert |
Hi @shorstok, your collection |
We're using LiteDB v 4.1.1 Actually, after ~2 days of trial and error, i'm able to reproduce database corruption in isolated test. It may seem a little contrived (I took queries and record structure from our original desktop app for reproduction), but it breaks database pretty reliably. Key points I guess:
Sample below is a console app, that, when launched, spawns 15 copies of itself working with single database. Maybe it would be necessary to run it 3 or 4 times to get error, but I doubt more than 5.
|
Hi @shorstok, thanks too much for this code. I will try get an hdd disk to test. Here I have only ssd. If this occurs only in HDD can be somethink about how normal disk are write. In master branch I added a new parameter in string connection (flush=true). With this, all write operation will flush just after finish - will very slow solution (in HDD, not in SSD), but less OS dependency. Also, shrink operation create another database (in memory) and than copy all data from this new file overwritten original datafile. This override can be loose file lock (I will test this). I will try all options with your code. |
@mbdavid removing |
A single line fix for me. I was in shrink method. But, in one of many attempt, I got _id duplicate key - I still investigate this. And again, thanks for you code: it would be extremely difficult to find the error without your code |
@mbdavid you're welcome :) |
Hi @mbdavid. |
Hi @Bounz, this bug was fixed but it's not on nuget... I forgot about him.. 😨 I will release new version this weekend. |
Hi @mbdavid, is it fixed on 4.1.4 version (last one)? For me it throws KeyNotFoundException in both 4.1.1.0 and 4.1.4.0 versions. |
Hi @md-zamolxis, yes, that bug was fixed in 4.1.3.... if you getting in 4.1.4 maybe it's another problem. Is your datafile has private data? Can be shared to me to find whats going on? |
Just checked - it does not contain private data. |
@md-zamolxis, which version of LiteDB do you use to create this database? You have a corrupted IndexNode link pointer.... maybe from and old v4 version. |
@mbdavid, this database was created by 4.1.1.0 version and I tried to shrink it in both versions. |
@md-zamolxis, your problem is not about shrink, your data is corrupted. I made this code and got an exception about IndexNode:
I will try recovery your data... and run over 4.1.4 |
@mbdavid, thanks a lot, maybe it is broken, but on my live env everything works as expected. |
Hi @md-zamolxis, I made a So, I recovery your data and works fine in master branch (with shrink too). You can get lastest version of LiteDB and run over your datafile to check. If you got any problem, please, open another issue about this. |
I get
KeyNotFoundException
upon any attempt to load/view database.Database file that raises
KeyNotFoundException
is generated by more than one process accessing one database, so this may be concurrency issue.Snippet to reproduce:
or
etc.
Database file in question included:
sample.zip
Please tell me what the possible cause is and how to avoid it in future.
The text was updated successfully, but these errors were encountered: