欢迎大家赞助一杯啤酒🍺 我们准备了下酒菜:Formal mathematics/Isabelle/ML, Formal verification/Coq/ACL2/Agda, C++/Lisp/Haskell
TwinDB
简介
TwinDB is an embedded key/value database based on BerkeleyDB. It basically adds security from database corruption on top of the non-transactional version of BerkeleyDB. I wrote it because the transactional version of Berkeley DB is expensive ($100,000 for a commercial license).
It accomplishes this by maintaining twin BerkeleyDB databases and using "lock" files to indicate when a set of writes are in progress.
Put and delete entries are cached in memory until TwinDB_sync() is called or a read occurs (by calling TwinDB_get()). Then, it:
- 1. locks the first database
- 2. writes to it
- 3. unlocks it
and repeats this process for the backup database. Upon startup, it checks to see if a lock is on either file. If so, it assumes that database file is corrupt and replaces it with the other.
Cons:
- writes are 1/2 as fast
- database is 2x as big
Pros:
- the database cannot be corrupted
- it's still *very* fast
- it's free for commercial use
- the size difference might not matter (current hard disks are typically over 100G, so a 500M database will still only take up less than 1% of the drive if doubled)