Crate sanakirja [−] [src]
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
- dynamic loading of pages not in the map, which is especially useful on 32-bits platforms.
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().unwrap(); let mut root = txn.root(0).unwrap_or_else(|| txn.create_db().unwrap()); txn.put(&mut rng, &mut root, b"test key", b"test value").unwrap(); txn.set_root(0,root); txn.commit().unwrap(); let txn = env.txn_begin().unwrap(); let root = txn.root(0).unwrap(); assert!(txn.get(&root, b"test key",None).and_then(|mut x| x.next()) == Some(b"test value")) }
Reexports
pub use transaction::{Statistics, Error}; |
Modules
transaction |
Structs
Db |
A database identifier. A |
Env |
Environment, essentially containing locks and mmaps. |
Iter | |
MutTxn |
Mutable transaction |
Txn |
Immutable transaction |
Enums
Value |
Iterator over parts of a value. On values of size at most 4096 bytes, the iterator will run exactly once. On larger values, it returns all parts of the value, in order. |
Traits
Transaction |