[][src]Trait exonum_merkledb::Database

pub trait Database: Send + Sync + 'static {
    fn snapshot(&self) -> Box<dyn Snapshot>;
fn merge(&self, patch: Patch) -> Result<()>;
fn merge_sync(&self, patch: Patch) -> Result<()>; fn fork(&self) -> Fork { ... } }

Low-level storage backend implementing a collection of named key-value stores (aka column families).

A Database instance is shared across different threads, so it must be Sync and Send.

There is no way to directly interact with data in the database; use snapshot, fork and merge methods for indirect interaction. See the module documentation for more details.

Note that Database effectively has interior mutability; merge and merge_sync methods take a shared reference to the database (&self) rather than an exclusive one (&mut self). This means that the following code compiles:

use exonum_merkledb::{Database, TemporaryDB, IndexBuilder};

// not declared as `mut db`!
let db: Box<Database> = Box::new(TemporaryDB::new());
let fork = db.fork();
{
    let (mut view, _state) = IndexBuilder::new(&fork)
        .index_name("index_name")
        .build::<()>();
    view.put(&vec![1, 2, 3], vec![123]);
}

db.merge(fork.into_patch()).unwrap();

Required methods

fn snapshot(&self) -> Box<dyn Snapshot>

Creates a new snapshot of the database from its current state.

fn merge(&self, patch: Patch) -> Result<()>

Atomically applies a sequence of patch changes to the database.

Note that this method may be called concurrently from different threads, the onus to guarantee atomicity is on the implementor of the trait.

Errors

If this method encounters any form of I/O or other error during merging, an error variant will be returned. In case of an error, the method guarantees no changes are applied to the database.

fn merge_sync(&self, patch: Patch) -> Result<()>

Atomically applies a sequence of patch changes to the database with fsync.

Note that this method may be called concurrently from different threads, the onus to guarantee atomicity is on the implementor of the trait.

Errors

If this method encounters any form of I/O or other error during merging, an error variant will be returned. In case of an error, the method guarantees no changes are applied to the database.

Loading content...

Provided methods

fn fork(&self) -> Fork

Creates a new fork of the database from its current state.

Loading content...

Trait Implementations

impl Debug for dyn Database[src]

Implementors

impl Database for RocksDB[src]

impl Database for TemporaryDB[src]

Loading content...