Trait exonum::storage::Database [] [src]

pub trait Database: Send + Sync + 'static {
    fn snapshot(&self) -> Box<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::storage::{Database, MemoryDB};

// not declared as `mut db`!
let db: Box<Database> = Box::new(MemoryDB::new());
let mut fork = db.fork();
fork.put("index_name", vec![1, 2, 3], vec![123]);
db.merge(fork.into_patch()).unwrap();

Required Methods

Important traits for Box<W>

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

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 were applied to the database.

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 were applied to the database.

Provided Methods

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

Implementors