Crates.io | ckydb |
lib.rs | ckydb |
version | 0.0.5 |
source | src |
created_at | 2022-07-05 02:50:08.117932 |
updated_at | 2022-07-05 02:50:08.117932 |
description | A simple fast memory-first thread-safe key-value embedded database that persists data on disk. |
homepage | |
repository | https://github.com/sopherapps/ckydb |
max_upload_size | |
id | 619394 |
size | 92,064 |
A simple fast memory-first thread-safe key-value embedded database that persists data on disk.
It is read as 'skydb' This the rust implementation of ckydb
cargo new ckydb_example
Cargo.toml
as a dependency[dependencies]
ckydb = { version = "0.0.5" } # put the appropriate version. 0.1.0 is just an example
src/main.rs
fileuse ckydb::{connect, Controller};
fn main() {
let mut db = connect("db", 4.0, 60.0).unwrap();
let keys = ["hey", "hi", "yoo-hoo", "bonjour"].to_vec();
let values = ["English", "English", "Slang", "French"].to_vec();
// Setting the values
println!("[Inserting key-value pairs]");
for (k, v) in keys.clone().into_iter().zip(values) {
let _ = db.set(k, v);
}
// Getting the values
println!("[After insert]");
for k in keys.clone() {
let got = db.get(k).unwrap();
println!("For key: {:?}, Got: {:?}", k, got);
}
// Deleting some values
for k in &keys[2..] {
let removed = db.delete(*k);
println!("Removed: key: {:?}, resp: {:?}", k, removed);
}
for k in &keys {
let got = db.get(*k);
println!("[After delete: For key: {:?}, Got: {:?}", k, got);
}
// Deleting all values
let cleared = db.clear();
println!("Cleared: {:?}", cleared);
println!("[After clear]");
for k in &keys {
let got = db.get(*k);
println!("For key: {:?}, Got: {:?}", k, got);
}
db.close().expect("close");
}
cargo run
Some examples can be found in the /examples folder.
cargo run --example hello_ckydb
git clone git@github.com:sopherapps/ckydb.git
cd ckydb/implementations/rs_ckydb
cargo test
key: TIMESTAMPED-key
memtable
memtable
refreshed and a new log file created.data_files
that is kept updated everytime a ".log" file is
converted into ".cky".current_log_file
) file is also kept in memory, and updated when a new log file is
created.key: TIMESTAMPED-key
pairs that have been marked for deletion.key: TIMESTAMPED-key
pairs found in the ".del" file. Each deleted pair is then removed from
the ".del" file.On ckydb.set(key, value)
:
memtable
.memtable
refreshed.memtable
and the current log file are updatedOn ckydb.delete(key)
:
key: TIMESTAMPED-key
pair is removed from the in-memory index.key: TIMESTAMPED-key
pair is removed from the ".idx" filekey: TIMESTAMPED-key
is added to the ".del" fileOn ckydb.get(key)
:
memtable
in memory. If for some crazy reason, it does
not exist there, a CorruptedDataError is thrown/raised/returned.cache
, if it falls there in, its value is got from cache
. If the value is not found for some reason, a
CorruptedDataError is thrown/raise/returneddata_files
list, is later than TIMESTAMP is loaded into an in-memory cache
whose range is set
to two ".cky" filenames between which it falls.cache
's data. If it is not found for some reason, a CorruptedDataError is
thrown/raise/returnedOn ckydb.clear()
:
memtable
is resetcache
is resetindex
in memory is resetdata_files
in memory is resetgoat[><?&(^#]1655304770518678-goat{&*/%}hen[><?&(^#]1655304670510698-hen{&*/%}pig[><?&(^#]1655304770534578-pig{&*/%}fish[><?&(^#]1655303775538278-fish$%#@*&^&
1655304770518678-goat{&*/%}1655304670510698-hen{&*/%}1655304770534578-pig{&*/%}1655303775538278-fish$%#@*&^&
1655304770518678-goat[><?&(^#]678 months{&*/%}1655304670510698-hen[><?&(^#]567 months{&*/%}1655304770534578-pig[><?&(^#]70 months{&*/%}1655303775538278-fish[><?&(^#]8990 months$%#@*&^&
Note: There is configuration that one can enable to escape the "token" in any user-defined key or value just to avoid weird errors. However, the escaping is expensive and it is thus turned off by default.
Copyright (c) 2022 Martin Ahindura. All implementations are licensed under the MIT License