Struct kvdb_rocksdb::Database
source · [−]pub struct Database { /* private fields */ }
Expand description
Key-Value database.
Implementations
sourceimpl Database
impl Database
sourcepub fn open(config: &DatabaseConfig, path: &str) -> Result<Database>
pub fn open(config: &DatabaseConfig, path: &str) -> Result<Database>
Open database file. Creates if it does not exist.
Safety
The number of config.columns
must not be zero.
sourcepub fn transaction(&self) -> DBTransaction
pub fn transaction(&self) -> DBTransaction
Helper to create new transaction for this database.
sourcepub fn write(&self, tr: DBTransaction) -> Result<()>
pub fn write(&self, tr: DBTransaction) -> Result<()>
Commit transaction to database.
sourcepub fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option<Box<[u8]>>
pub fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option<Box<[u8]>>
Get value by partial key. Prefix size should match configured prefix size.
sourcepub fn iter<'a>(
&'a self,
col: u32
) -> impl Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a
pub fn iter<'a>(
&'a self,
col: u32
) -> impl Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a
Iterator over the data in the given database column index. Will hold a lock until the iterator is dropped preventing the database from being closed.
sourcepub fn restore(&self, new_db: &str) -> Result<()>
pub fn restore(&self, new_db: &str) -> Result<()>
Restore the database from a copy at given path.
sourcepub fn num_columns(&self) -> u32
pub fn num_columns(&self) -> u32
The number of column families in the db.
sourcepub fn remove_last_column(&self) -> Result<()>
pub fn remove_last_column(&self) -> Result<()>
Remove the last column family in the database. The deletion is definitive.
sourcepub fn add_column(&self) -> Result<()>
pub fn add_column(&self) -> Result<()>
Add a new column family to the DB.
sourcepub fn get_statistics(&self) -> HashMap<String, RocksDbStatsValue>
pub fn get_statistics(&self) -> HashMap<String, RocksDbStatsValue>
Get RocksDB statistics.
sourcepub fn try_catch_up_with_primary(&self) -> Result<()>
pub fn try_catch_up_with_primary(&self) -> Result<()>
Try to catch up a secondary instance with the primary by reading as much from the logs as possible.
Guaranteed to have changes up to the the time that try_catch_up_with_primary
is called
if it finishes succesfully.
Blocks until the MANIFEST file and any state changes in the corresponding Write-Ahead-Logs are applied to the secondary instance. If the manifest files are very large this method could take a long time.
If Write-Ahead-Logs have been purged by the primary instance before the secondary is able to open them, the secondary will not be caught up until this function is called again and new Write-Ahead-Logs are identified.
If called while the primary is writing, the catch-up may fail.
If the secondary is unable to catch up because of missing logs, this method fails silently and no error is returned.
Calling this as primary will return an error.
Trait Implementations
sourceimpl KeyValueDB for Database
impl KeyValueDB for Database
sourcefn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option<Box<[u8]>>
fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option<Box<[u8]>>
Get the first value matching the given prefix.
sourcefn write(&self, transaction: DBTransaction) -> Result<()>
fn write(&self, transaction: DBTransaction) -> Result<()>
Write a transaction of changes to the backing store.
sourcefn iter<'a>(
&'a self,
col: u32
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>
fn iter<'a>(
&'a self,
col: u32
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>
Iterate over the data for a given column.
sourcefn iter_with_prefix<'a>(
&'a self,
col: u32,
prefix: &'a [u8]
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>
fn iter_with_prefix<'a>(
&'a self,
col: u32,
prefix: &'a [u8]
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>
Iterate over the data for a given column, returning all key/value pairs where the key starts with the given prefix. Read more
sourcefn restore(&self, new_db: &str) -> Result<()>
fn restore(&self, new_db: &str) -> Result<()>
Attempt to replace this database with a new one located at the given path.
sourcefn io_stats(&self, kind: IoStatsKind) -> IoStats
fn io_stats(&self, kind: IoStatsKind) -> IoStats
Query statistics. Read more
sourcefn transaction(&self) -> DBTransaction
fn transaction(&self) -> DBTransaction
Helper to create a new transaction.
sourceimpl MallocSizeOf for Database
impl MallocSizeOf for Database
sourcefn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Measure the heap usage of all descendant heap-allocated structures, but
not the space taken up by the value itself.
If T::size_of
is a constant, consider implementing constant_size
as well. Read more
sourcefn constant_size() -> Option<usize>
fn constant_size() -> Option<usize>
Used to optimize MallocSizeOf
implementation for collections
like Vec
and HashMap
to avoid iterating over them unnecessarily.
The Self: Sized
bound is for object safety. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> MallocSizeOfExt for T where
T: MallocSizeOf,
impl<T> MallocSizeOfExt for T where
T: MallocSizeOf,
sourcefn malloc_size_of(&self) -> usize
fn malloc_size_of(&self) -> usize
Method to launch a heapsize measurement with a fresh state. Read more