LsmEngine

Struct LsmEngine 

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

LSM engine with 256-way striping (Phase 1.6+)

Implementations§

Source§

impl LsmEngine

Source

pub fn create(dir: impl AsRef<Path>) -> Result<Self>

Create a new database

Source

pub fn create_with_schema( dir: impl AsRef<Path>, schema: TableSchema, ) -> Result<Self>

Create a new database with a table schema (Phase 3.1+)

Source

pub fn create_with_config( dir: impl AsRef<Path>, config: DatabaseConfig, schema: TableSchema, ) -> Result<Self>

Create a new database with custom configuration (Phase 8+)

Source

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

Open existing database

Source

pub fn put(&self, key: Key, item: Item) -> Result<()>

Put an item

Source

pub fn put_conditional( &self, key: Key, item: Item, condition: &Expr, context: &ExpressionContext, ) -> Result<()>

Put an item with a condition expression (Phase 2.5+)

Source

pub fn get(&self, key: &Key) -> Result<Option<Item>>

Get an item

Source

pub fn delete(&self, key: Key) -> Result<()>

Delete an item

Source

pub fn delete_conditional( &self, key: Key, condition: &Expr, context: &ExpressionContext, ) -> Result<()>

Delete an item with a condition expression (Phase 2.5+)

Source

pub fn update( &self, key: &Key, actions: &[UpdateAction], context: &ExpressionContext, ) -> Result<Item>

Update an item using update expression (Phase 2.4+)

Source

pub fn update_conditional( &self, key: &Key, actions: &[UpdateAction], condition: &Expr, context: &ExpressionContext, ) -> Result<Item>

Update an item with a condition expression (Phase 2.5+)

Source

pub fn query(&self, params: QueryParams) -> Result<QueryResult>

Query items within a partition (Phase 2.1+)

Source

pub fn batch_get(&self, keys: &[Key]) -> Result<HashMap<Key, Option<Item>>>

Batch get multiple items (Phase 2.6+)

Source

pub fn batch_write(&self, operations: &[(Key, Option<Item>)]) -> Result<usize>

Batch write multiple items (Phase 2.6+)

Source

pub fn transact_get(&self, keys: &[Key]) -> Result<Vec<Option<Item>>>

Transaction get - read multiple items atomically (Phase 2.7+)

Source

pub fn transact_write( &self, operations: &[(Key, TransactWriteOperation)], context: &ExpressionContext, ) -> Result<usize>

Transaction write - write multiple items atomically with conditions (Phase 2.7+)

Source

pub fn scan(&self, params: ScanParams) -> Result<ScanResult>

Scan all items across all stripes (Phase 2.2+)

Source

pub fn read_stream( &self, after_sequence_number: Option<u64>, ) -> Result<Vec<StreamRecord>>

Read stream records (Phase 3.4+)

Returns all stream records in the buffer, ordered by sequence number (oldest first). Optionally filter to only records with sequence number > after_sequence_number.

Source

pub fn flush(&self) -> Result<()>

Force flush all stripes (for testing/shutdown)

Source

pub fn set_compaction_config(&self, config: CompactionConfig)

Set compaction configuration (Phase 1.7+)

§Examples
use kstone_core::{LsmEngine, CompactionConfig};
use tempfile::TempDir;

let dir = TempDir::new().unwrap();
let db = LsmEngine::create(dir.path()).unwrap();

// Disable compaction
db.set_compaction_config(CompactionConfig::disabled());

// Or customize compaction settings
let config = CompactionConfig::new()
    .with_sst_threshold(5)
    .with_check_interval(30);
db.set_compaction_config(config);
Source

pub fn compaction_config(&self) -> CompactionConfig

Get current compaction configuration (Phase 1.7+)

Source

pub fn compaction_stats(&self) -> CompactionStats

Get compaction statistics (Phase 1.7+)

Returns a snapshot of current compaction statistics including:

  • Total number of compactions performed
  • SSTs merged and created
  • Bytes read, written, and reclaimed
  • Records deduplicated and tombstones removed
§Examples
use kstone_core::LsmEngine;
use tempfile::TempDir;

let dir = TempDir::new().unwrap();
let db = LsmEngine::create(dir.path()).unwrap();

// Get compaction statistics
let stats = db.compaction_stats();
println!("Total compactions: {}", stats.total_compactions);
println!("SSTs merged: {}", stats.total_ssts_merged);
println!("Bytes reclaimed: {}", stats.total_bytes_reclaimed);
Source

pub fn trigger_compaction(&self, stripe_id: usize) -> Result<()>

Trigger manual compaction on a specific stripe (Phase 1.7+)

This is primarily for testing or manual database maintenance. Compaction will only occur if the stripe has enough SSTs.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more