[][src]Trait sc_service::config::KeyValueDB

pub trait KeyValueDB: Send + Sync + MallocSizeOf {
    fn get(&self, col: u32, key: &[u8]) -> Result<Option<Vec<u8>>, Error>;
fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option<Box<[u8]>>;
fn write_buffered(&self, transaction: DBTransaction);
fn flush(&self) -> Result<(), Error>;
fn iter(
        &'a self,
        col: u32
    ) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>;
fn iter_from_prefix(
        &'a self,
        col: u32,
        prefix: &'a [u8]
    ) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>;
fn restore(&self, new_db: &str) -> Result<(), Error>; fn transaction(&self) -> DBTransaction { ... }
fn write(&self, transaction: DBTransaction) -> Result<(), Error> { ... }
fn io_stats(&self, _kind: Kind) -> IoStats { ... } }

Generic key-value database.

This makes a distinction between "buffered" and "flushed" values. Values which have been written can always be read, but may be present in an in-memory buffer. Values which have been flushed have been moved to backing storage, like a RocksDB instance. There are certain operations which are only guaranteed to operate on flushed data and not buffered, although implementations may differ in this regard.

The contents of an interior buffer may be explicitly flushed using the flush method.

The KeyValueDB also deals in "column families", which can be thought of as distinct stores within a database. Keys written in one column family will not be accessible from any other. The number of column families must be specified at initialization, with a differing interface for each database. The None argument in place of a column index is always supported.

The API laid out here, along with the Sync bound implies interior synchronization for implementation.

Required methods

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

Get a value by key.

fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option<Box<[u8]>>

Get a value by partial key. Only works for flushed data.

fn write_buffered(&self, transaction: DBTransaction)

Write a transaction of changes to the buffer.

fn flush(&self) -> Result<(), Error>

Flush all buffered data.

fn iter(
    &'a self,
    col: u32
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>

Iterate over flushed data for a given column.

fn iter_from_prefix(
    &'a self,
    col: u32,
    prefix: &'a [u8]
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>

Iterate over flushed data for a given column, starting from a given prefix.

fn restore(&self, new_db: &str) -> Result<(), Error>

Attempt to replace this database with a new one located at the given path.

Loading content...

Provided methods

fn transaction(&self) -> DBTransaction

Helper to create a new transaction.

fn write(&self, transaction: DBTransaction) -> Result<(), Error>

Write a transaction of changes to the backing store.

fn io_stats(&self, _kind: Kind) -> IoStats

Query statistics.

Not all kvdb implementations are able or expected to implement this, so by default, empty statistics is returned. Also, not all kvdb implementation can return every statistic or configured to do so (some statistics gathering may impede the performance and might be off by default).

Loading content...

Implementations on Foreign Types

impl KeyValueDB for Database[src]

impl KeyValueDB for InMemory[src]

Loading content...

Implementors

Loading content...