GrausDb
GrausDb is a high-performance, thread-safe key-value embedded data store written in Rust. It is designed for simplicity, efficiency, and reliability.
Features
- Lock-Free Concurrency: GrausDb leverages lock-free data structures for high-performance concurrent access.
- Persistence: Data is persisted to disk for durability.
- Log-Based Storage: Key-value pairs are stored in log files.
- Benchmarks: Benchmarks included to assess the performance.
Installation
To use GrausDb in your Rust project, simply add it as a dependency in your Cargo.toml
file:
[]
= "0.1.0"
Quick start
Here's a quick example of how to use GrausDb in your Rust application:
let store = open?;
store.set?;
let val = store.get?;
It can also be called from multiple threads:
let store = open?;
// Calls set method from 8 different threads
for i in 0..8
API
GrausDb provides a simple and intuitive API for interacting with the key-value store. Below are some of the key functions and methods exposed by GrausDb, along with usage examples.
GrausDb::open
open
is used to open a GrausDb instance, creating a new database if it doesn't exist at the specified path.
Example:
use ;
set
The set
method is used to store a key-value pair in the database.
Example:
use ;
get
The get
method retrieves the value associated with a given key.
Example:
use ;
remove
The remove
method deletes a key and its associated value from the database.
Example:
use ;
update_if
The update_if
method updates the value of an existing key atomically, allowing you to provide a custom update function.
An optional predicate can be passed, the value will only be updated if the predicate is satisfied.
Example:
use ;
For more details on how to use GrausDb, please refer to the tests.
Architecture and Implementation
GrausDb's architecture is built around the principles of log-based storage and lock-free concurrency:
-
Log-Based Storage: GrausDb stores key-value pairs in log files. Log files are named after monotonically increasing generation numbers with a log extension. This design ensures that data is durably persisted to disk.
-
Lock-Free Concurrency: GrausDb uses lock-free data structures to provide high-performance concurrent access to the data. This enables multiple threads to interact with the database efficiently.
-
In-Memory Index: GrausDb maintains an in-memory index that maps keys to their positions in the log. This index allows for fast lookups and efficient data retrieval.
-
Compaction: To maintain efficient storage and reduce disk space usage, GrausDb performs compaction when a threshold is reached. Compaction involves rewriting log files, removing stale data, and reclaiming disk space.
Benchmarks
GrausDb includes built-in benchmarking tools to evaluate its efficiency and to help you make data-driven decisions.
Future Development
Next features:
- Multithread benchmark
- Range get
- Sync API (journal)
- Internal threadpool + futures
License
GrausDb is licensed under the MIT License.
Happy coding with GrausDb!
Contact
GrausDb is created and maintained by Ricardo Pallas.
Website: https://rpallas92.github.io/