Skip to content

jiangyinzuo/KVLite

Repository files navigation

KVLite

Build Status codecov

A toy key-value storage for DB study

Examples

get, set and remove command

use kvlite::db::key_types::InternalKey;
use kvlite::db::no_transaction_db::NoTransactionDB;
use kvlite::db::DB;
use kvlite::memory::SkipMapMemTable;
use kvlite::wal::simple_wal::SimpleWriteAheadLog;
use tempfile::TempDir;

fn main() {
    let temp_dir = TempDir::new().unwrap();
    let db = NoTransactionDB::<
        InternalKey,
        InternalKey,
        SkipMapMemTable<InternalKey>,
        SimpleWriteAheadLog,
    >::open(temp_dir.path())
        .unwrap();

    let hello = Vec::from("hello");
    let value = Vec::from("value1");
    db.set(hello.clone(), value).unwrap();

    println!("{:?}", db.get(&"hello".into()).unwrap()); // Some("value1")
    db.remove(hello).unwrap();
    assert!(db.get(&"hello".into()).unwrap().is_none());
}

Run tests

RUST_LOG=debug RUSTFLAGS="-Z sanitizer=leak" cargo test --target x86_64-unknown-linux-gnu

Performance

Unbuntu20.04
Linux version 5.4.0-70-generic
Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz

insert query
10^5 522ms 32ms
10^6 5.07s 4.38s

References

About

A toy key-value storage based on LSM-tree

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published