Skip to main content

StrataKV

Struct StrataKV 

Source
pub struct StrataKV { /* private fields */ }
Expand description

Pure-Rust Bitcask key-value store with append-only WAL.

Implementations§

Source§

impl StrataKV

Source

pub fn open(wal_path: impl AsRef<Path>) -> Result<Self>

Opens or creates a StrataKV database at the specified WAL file path.

Source

pub fn get(&mut self, key: &str) -> Result<Option<Vec<u8>>>

Retrieves a value by key.

Source

pub fn put(&mut self, key: &str, val: &[u8]) -> Result<()>

Stores a key-value pair, appending to the WAL and updating the in-memory index.

Source

pub fn delete(&mut self, key: &str) -> Result<bool>

Deletes a key by appending a tombstone record.

Source

pub fn len(&self) -> usize

Number of active non-deleted keys.

Source

pub fn is_empty(&self) -> bool

Whether the database is empty.

Source

pub fn keys(&self) -> Vec<String>

Returns a list of all active keys.

Source

pub fn total_bytes(&self) -> Result<u64>

Returns total file size on disk in bytes.

Source

pub fn live_data_bytes(&self) -> u64

Returns the sum of bytes utilized by all live keys, values, and frame headers.

Source

pub fn dead_bytes_ratio(&self) -> Result<f64>

Ratio of dead/reclaimable bytes in the WAL (0.0 to 1.0).

Source

pub fn maybe_compact(&mut self, threshold: f64) -> Result<bool>

Compacts the log if the dead bytes ratio exceeds the specified threshold.

Source

pub fn compact(&mut self) -> Result<()>

Compacts the log by writing all current active entries into a fresh compacted file.

Source

pub fn sync(&mut self) -> Result<()>

Flushes and syncs WAL file data to underlying physical storage for durability guarantees.

Source

pub fn verify_wal_integrity(wal_path: impl AsRef<Path>) -> Result<(usize, u64)>

Verifies the integrity of the WAL file, checking CRC checksums for each frame. Returns the number of valid records and the valid byte offset, allowing detection and recovery of torn writes.

Trait Implementations§

Source§

impl Drop for StrataKV

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.