mina_tree/ondisk/
mod.rs

1//! # Database
2//!
3//! Database is a lightweight, single append-only file, key-value store designed as an
4//! alternative to RocksDB.
5//!
6//! ## Storage Format
7//!
8//! Each entry in the Database has the following structure:
9//!
10//! ```ignored
11//! +------------+-----------+-----------+
12//! |    HDR     |    KEY    |   VALUE   |
13//! | (17 bytes) | (X bytes) | (X bytes) |
14//! +------------+-----------+-----------+
15//!       ^
16//!       |
17//!       |
18//! +------------+--------------+-----------+------------+
19//! | KEY_LENGTH | VALUE_LENGTH | BITFLAGS  |   CRC32    |
20//! | (4 bytes)  | (8 bytes)    | (1 byte)  | (4 bytes)  |
21//! +------------+--------------+-----------+------------+
22//! ```
23//!
24//! Where:
25//! - `HDR`: A 17 bytes header
26//!   - `KEY_LENGTH`: Length of the key, stored in 4 bytes.
27//!   - `VALUE_LENGTH`: Length of the value, stored in 8 bytes.
28//!   - `BITFLAGS`: A 1 byte bitflags including:
29//!      - `key_is_compressed`: A flag indicating if the key is compressed.
30//!      - `value_is_compressed`: A flag indicating if the value is compressed.
31//!      - `is_removed`: A flag indicating if the entry has been removed.
32//!   - `CRC32`: The CRC32 checksum of the entry (including its header), stored in 4 bytes.
33//! - `KEY`: The key data
34//! - `VALUE`: The value data
35//!
36//! ## Example Usage
37//!
38//! Create an instance of MyDatabase:
39//!
40//! ```rust
41//! # use mina_tree::ondisk::Database;
42//! # fn usage() -> std::io::Result<()> {
43//! # let k = |s: &str| Box::<[u8]>::from(s.as_bytes());
44//! # let v = k;
45//! let mut db = Database::create("/tmp/my_database")?;
46//!
47//! // Insert a key-value pair:
48//! db.set(k("key1"), v("value1"))?;
49//!
50//! // Retrieve a value by key:
51//! let result = db.get(&k("key1"))?;
52//! assert_eq!(result, Some(v("value1")));
53//! # Ok(())
54//! # }
55//! ```
56
57pub mod batch;
58mod compression;
59mod database;
60mod lock;
61
62pub use batch::Batch;
63pub use database::*;