mkrd / DictDataBase

A python NoSQL dictionary database, with concurrent access and ACID compliance
MIT License
231 stars 11 forks source link

Improve behavior to prevent data loss #60

Open BoboTiG opened 2 months ago

BoboTiG commented 2 months ago

Hello,

I really like the project, and using it quite intensively (my program runs 24/24, all weeks, without interruption).

And from time to time (it happened 3 times in the past 6 months), databases are messed up. The first time, some files were simply emptied. Other times, it is like if the writing into the file was interrupted at some point. The latter might be an issue when writting to the file while a computer is having hard time with the HDD or simply shutting down.

To give more details, I do not use threads into that program. But I might have the program running at the same time twice. And most of the time, it works just fine because database files are accessed only on-demand (they are not kept in-memory for the whole runtime, correct?).

I did not succeed at producing some code to help reproducing the issue. But it is quite a big issue for me, as I store sensible data in those files, and loosing that is not an option. I added regular backups since the first "crash", but still, I think a solution could be found to improve the robustness of the library.

Without being able to reproduce on-demand, it's not easy to think about a solution. What I've come up so far: 1) ensure locks are goods, efficient, and persistent (cf #12 if I understood correctly?) 2) when writing to the file, maybe using a temporary one that can be renamed in a second time to replace the original one (while writing the idea, I get it could be not what we want haha) 3) tell me you have ideas? :)

Anyway, great library!

BoboTiG commented 2 months ago

I am using the latest version (2.5.0), and hit the same issue when using older ones too (I keep my dependencies up-to-date via dependabot).