A toy key-value storage for DB study
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());
}
RUST_LOG=debug RUSTFLAGS="-Z sanitizer=leak" cargo test --target x86_64-unknown-linux-gnu
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 |