Skip to main content

DB

Struct DB 

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

The core database handle.

Implementations§

Source§

impl DB

Source

pub fn open(options: DbOptions, path: impl AsRef<Path>) -> Result<Self>

Open or create a database.

Source

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

Source

pub fn put_with_options( &self, write_options: &WriteOptions, key: &[u8], value: &[u8], ) -> Result<()>

Source

pub fn delete(&self, key: &[u8]) -> Result<()>

Source

pub fn delete_with_options( &self, write_options: &WriteOptions, key: &[u8], ) -> Result<()>

Source

pub fn delete_range(&self, begin: &[u8], end: &[u8]) -> Result<()>

Delete all keys in the range [begin, end).

Source

pub fn delete_range_with_options( &self, write_options: &WriteOptions, begin: &[u8], end: &[u8], ) -> Result<()>

Source

pub fn write(&self, batch: WriteBatch) -> Result<()>

Source

pub fn write_with_options( &self, batch: WriteBatch, write_options: &WriteOptions, ) -> Result<()>

Source

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

Source

pub fn get_with_options( &self, options: &ReadOptions, key: &[u8], ) -> Result<Option<Vec<u8>>>

Source

pub fn iter(&self) -> Result<DBIterator>

Create a forward iterator over the database.

Source

pub fn iter_with_options(&self, options: &ReadOptions) -> Result<DBIterator>

Create a forward iterator with options.

Uses streaming TableIterators for SST files (O(1 block) memory per SST) instead of loading entire tables into memory.

Source

pub fn iter_with_range( &self, options: &ReadOptions, lower_bound: Option<&[u8]>, upper_bound: Option<&[u8]>, ) -> Result<DBIterator>

Create a forward iterator that only includes sources overlapping [lower_bound, upper_bound]. SST files outside this range are skipped entirely, avoiding costly block reads. None bounds mean unbounded in that direction.

WARNING: Does NOT use prefix bloom filters. For prefix-scoped queries, prefer iter_with_prefix() which is significantly faster.

Bounds from ReadOptions::iterate_lower_bound / iterate_upper_bound are also applied if set, using the tighter of the two.

Source

pub fn iter_with_prefix( &self, prefix: &[u8], options: &ReadOptions, ) -> Result<DBIterator>

Create a prefix-bounded iterator with full options support.

Uses prefix bloom filters to skip SST files that don’t contain the prefix, and stops iteration as soon as the prefix boundary is crossed. Significantly faster than iter_with_range() for prefix-scoped queries.

Supports ReadOptions::iterate_lower_bound / iterate_upper_bound for sub-range queries within a prefix, and snapshot for historical reads.

Source

pub fn iter_with_batch(&self, batch: &WriteBatchWithIndex) -> Result<DBIterator>

Create a forward iterator that merges uncommitted batch writes with the current DB state. Batch entries appear with sequence numbers above the current snapshot so they take precedence over existing data.

Source

pub fn snapshot_seq(&self) -> SequenceNumber

Source

pub fn snapshot(&self) -> Snapshot<'_>

Acquire a snapshot with RAII guard. The snapshot is automatically released when the Snapshot is dropped — no manual release_snapshot() needed.

Source

pub fn release_snapshot(&self, seq: SequenceNumber)

Release a previously acquired snapshot so compaction can reclaim its data.

Source

pub fn path(&self) -> &Path

Source

pub fn get_property(&self, name: &str) -> Option<String>

Get a database property.

Supported properties:

  • "num-files-at-level{N}" — number of SST files at level N
  • "total-sst-size" — total size of all SST files in bytes
  • "block-cache-usage" — approximate block cache entry count
  • "compaction-pending" — “1” if compaction is needed, “0” otherwise
  • "stats.bytes_written" — total user bytes written
  • "stats.bytes_read" — total user bytes read
  • "stats.compactions_completed" — number of compactions completed
  • "stats.compaction_bytes_written" — total bytes written during compaction
  • "stats.flushes_completed" — number of memtable flushes
  • "stats.block_cache_hits" — block cache hit count
  • "stats.block_cache_misses" — block cache miss count
  • "stats.cache_hit_rate" — block cache hit rate (0.0 to 1.0)
Source

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

Force flush the active MemTable to SST.

Source

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

Run compaction if needed (L0 → L1 or Ln → Ln+1). Runs inline while holding locks for deterministic behavior.

Source

pub fn compact_range( &self, begin: Option<&[u8]>, end: Option<&[u8]>, ) -> Result<()>

Compact all keys in the given range across all levels. If begin is None, starts from the beginning. If end is None, goes to the end.

Source

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

Close the database.

Trait Implementations§

Source§

impl Drop for DB

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for DB

Source§

impl Sync for DB

Auto Trait Implementations§

§

impl !Freeze for DB

§

impl !RefUnwindSafe for DB

§

impl Unpin for DB

§

impl UnsafeUnpin for DB

§

impl !UnwindSafe for DB

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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