Bitcasky
Bitcasky is a Rust implementation of the Bitcask key-value store. It is an ACID-compliant, append-only key-value store that provides high write throughput. It is optimized for write-heavy workloads, and is commonly used for applications such as log storage and time-series data.
Features
- Append-only storage for durability and consistency
- Memory-mapped files for efficient I/O
- Key-value storage with O(1) read and write performance
- Store expirable values
Usage
Basic usage
To use Bitcasky, simply add it to your Cargo.toml
file:
= "0.1.2"
bitcasky
Then, in your Rust code, import the bitcasky
crate and start using the key-value store:
use Bitcasky;
Store expirable value
db.put_with_ttl.unwrap;
// 60 seconds later
assert!;
Delete some value or the entire database
db.put.unwrap;
db.put.unwrap;
// delete some value
db.delete.unwrap;
assert!;
// drop database
db.drop.unwrap;
assert!;
Iterate database
Iterate all keys.
// iterate and print all keys in database
bc.foreach_key.unwrap;
// fold all keys by concatenate them
let ret = bc.fold_key
.unwrap;
assert!;
println!;
Iterate all keys and values.
// iterate and print all keys and values in database
bc.foreach
.unwrap;
// fold all keys and values by concatenate them
let ret = bc
.fold
.unwrap;
assert!;
println!;
Sync strategy
By choosing a sync strategy, you can configure the durability of writes by specifying when to synchronize data to disk.
The following sync strategies are available:
- None — lets the operating system manage syncing writes
- OSync — uses the O_SYNC flag, which forces syncs on every write
- Time interval — sync at specified intervals (default: 60 secs)
For example, create a Bitcasky database which sync on every 35 secs as follows:
let db = open.unwrap;
Merge process
Bitcasky need to call merge periodically to reduce disk usage. The merge process traverses data files and reclaims space by eliminating out-of-date of deleted key/value pairs, writing only the current key/value pairs to a new set of files within the directory.
Start merge process by calling merge
on Bitcaksy instance like this:
db.merge.unwrap;
License
This project is licensed under the MIT license.