Crate sanakirja [] [src]

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

Features

  • ACID semantics, using a separable transactions module, reusable for other structure.

  • B-trees with copy-on-write.

  • Support for referential transparency (interface still missing).

  • No read locks. The only three cases of locks are (1) on the first transaction of a thread, (2) when starting concurrent writers, or (3) when starting a writer in parallel with a reader started before the last commit on the file.

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)

For future versions

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

  • merging pages to rebalance more (delete).

  • 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()).unwrap();
   let mut txn = env.mut_txn_begin();
   let mut root = txn.root().unwrap_or_else(|| txn.create_db());
   txn.put(&mut rng, &mut root, b"test key", b"test value");
   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"))
}

Structs

Db
Env

Environment, containing in particular a pointer to the memory-mapped file.

MutTxn

Mutable transaction

Statistics
Txn

Immutable transaction

Value

Traits

Transaction

Type Definitions

Error