sanakirja 0.3.0

A key-value dictionary, using copy-on-write and B trees.
Documentation

Fast and reliable key-value store, under the Mozilla Public License (link as you like, share modifications).

Features

  • ACID semantics.

  • B trees with copy-on-write.

  • Support for referential transparency: databases can be cloned in time O(1).

  • Ultimately, we'd like to have no locks. Right now, there is a cross-process read write lock, that only commit takes exclusively (other parts of a mutable transaction need just a read access).

This version is only capable of inserting and retrieving keys in the database, allowing several bindings for the same key (get will retrieve the first one).

Implementation details, in particular the file format, are documented in the file.

Todo-list

  • check that all dereferences are converted to/from little-endian. (easy)

  • improve error handling

  • dynamic loading of pages not in the map, especially on 32-bits platforms ('transaction.rs', half-easy)

  • Check freeing.

For future versions

  • implement advertised lock model (right now, committing a writer excludes readers, there's no other lock).

  • combined "CoW + delete".

Example

extern crate rand;
extern crate tempdir;
extern crate sanakirja;
use self::sanakirja::Transaction;

fn main() {
   let mut rng = rand::thread_rng();
   let dir = tempdir::TempDir::new("pijul").unwrap();
   let env = sanakirja::Env::new(dir.path(),100).unwrap();
   let mut txn = env.mut_txn_begin();
   let mut root = txn.root().unwrap_or_else(|| txn.create_db().unwrap());
   txn.put(&mut rng, &mut root, b"test key", b"test value").unwrap();
   txn.set_root(root);
   txn.commit().unwrap();

   let txn = env.txn_begin();
   let root = txn.root().unwrap();
   assert!(txn.get(&root, b"test key",None).and_then(|mut x| x.next()) == Some(b"test value"))
}