Struct rocksdb::TransactionDB

source ·
pub struct TransactionDB<T: ThreadMode = SingleThreaded> { /* private fields */ }
Expand description

RocksDB TransactionDB.

Please read the official guide to learn more about RocksDB TransactionDB.

The default thread mode for TransactionDB is SingleThreaded if feature multi-threaded-cf is not enabled.

use rocksdb::{DB, Options, TransactionDB, SingleThreaded};
let path = "_path_for_transaction_db";
{
    let db: TransactionDB = TransactionDB::open_default(path).unwrap();
    db.put(b"my key", b"my value").unwrap();

    // create transaction
    let txn = db.transaction();
    txn.put(b"key2", b"value2");
    txn.put(b"key3", b"value3");
    txn.commit().unwrap();
}
let _ = DB::destroy(&Options::default(), path);

Implementations§

source§

impl<T: ThreadMode> TransactionDB<T>

source

pub fn open_default<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Opens a database with default options.

source

pub fn open<P: AsRef<Path>>( opts: &Options, txn_db_opts: &TransactionDBOptions, path: P ) -> Result<Self, Error>

Opens the database with the specified options.

source

pub fn open_cf<P, I, N>( opts: &Options, txn_db_opts: &TransactionDBOptions, path: P, cfs: I ) -> Result<Self, Error>
where P: AsRef<Path>, I: IntoIterator<Item = N>, N: AsRef<str>,

Opens a database with the given database options and column family names.

Column families opened using this function will be created with default Options.

source

pub fn open_cf_descriptors<P, I>( opts: &Options, txn_db_opts: &TransactionDBOptions, path: P, cfs: I ) -> Result<Self, Error>

Opens a database with the given database options and column family descriptors.

source

pub fn list_cf<P: AsRef<Path>>( opts: &Options, path: P ) -> Result<Vec<String>, Error>

source

pub fn destroy<P: AsRef<Path>>(opts: &Options, path: P) -> Result<(), Error>

source

pub fn repair<P: AsRef<Path>>(opts: &Options, path: P) -> Result<(), Error>

source

pub fn path(&self) -> &Path

source

pub fn transaction(&self) -> Transaction<'_, Self>

Creates a transaction with default options.

source

pub fn transaction_opt<'a>( &'a self, write_opts: &WriteOptions, txn_opts: &TransactionOptions ) -> Transaction<'a, Self>

Creates a transaction with options.

source

pub fn prepared_transactions(&self) -> Vec<Transaction<'_, Self>>

Get all prepared transactions for recovery.

This function is expected to call once after open database. User should commit or rollback all transactions before start other transactions.

source

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

Returns the bytes associated with a key value.

source

pub fn get_cf<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K ) -> Result<Option<Vec<u8>>, Error>

Returns the bytes associated with a key value and the given column family.

source

pub fn get_opt<K: AsRef<[u8]>>( &self, key: K, readopts: &ReadOptions ) -> Result<Option<Vec<u8>>, Error>

Returns the bytes associated with a key value with read options.

source

pub fn get_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions ) -> Result<Option<Vec<u8>>, Error>

Returns the bytes associated with a key value and the given column family with read options.

source

pub fn get_pinned<K: AsRef<[u8]>>( &self, key: K ) -> Result<Option<DBPinnableSlice<'_>>, Error>

source

pub fn get_pinned_cf<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K ) -> Result<Option<DBPinnableSlice<'_>>, Error>

Returns the bytes associated with a key value and the given column family.

source

pub fn get_pinned_opt<K: AsRef<[u8]>>( &self, key: K, readopts: &ReadOptions ) -> Result<Option<DBPinnableSlice<'_>>, Error>

Returns the bytes associated with a key value with read options.

source

pub fn get_pinned_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions ) -> Result<Option<DBPinnableSlice<'_>>, Error>

Returns the bytes associated with a key value and the given column family with read options.

source

pub fn multi_get<K, I>(&self, keys: I) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Return the values associated with the given keys.

source

pub fn multi_get_opt<K, I>( &self, keys: I, readopts: &ReadOptions ) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Return the values associated with the given keys using read options.

source

pub fn multi_get_cf<'a, 'b: 'a, K, I, W>( &'a self, keys: I ) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = (&'b W, K)>, W: 'b + AsColumnFamilyRef,

Return the values associated with the given keys and column families.

source

pub fn multi_get_cf_opt<'a, 'b: 'a, K, I, W>( &'a self, keys: I, readopts: &ReadOptions ) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = (&'b W, K)>, W: 'b + AsColumnFamilyRef,

Return the values associated with the given keys and column families using read options.

source

pub fn put<K, V>(&self, key: K, value: V) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

source

pub fn put_cf<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

source

pub fn put_opt<K, V>( &self, key: K, value: V, writeopts: &WriteOptions ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

source

pub fn put_cf_opt<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V, writeopts: &WriteOptions ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

source

pub fn write(&self, batch: WriteBatchWithTransaction<true>) -> Result<(), Error>

source

pub fn write_opt( &self, batch: WriteBatchWithTransaction<true>, writeopts: &WriteOptions ) -> Result<(), Error>

source

pub fn merge<K, V>(&self, key: K, value: V) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

source

pub fn merge_cf<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

source

pub fn merge_opt<K, V>( &self, key: K, value: V, writeopts: &WriteOptions ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

source

pub fn merge_cf_opt<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V, writeopts: &WriteOptions ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

source

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

source

pub fn delete_cf<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K ) -> Result<(), Error>

source

pub fn delete_opt<K: AsRef<[u8]>>( &self, key: K, writeopts: &WriteOptions ) -> Result<(), Error>

source

pub fn delete_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, writeopts: &WriteOptions ) -> Result<(), Error>

source

pub fn iterator<'a: 'b, 'b>( &'a self, mode: IteratorMode<'_> ) -> DBIteratorWithThreadMode<'b, Self>

source

pub fn iterator_opt<'a: 'b, 'b>( &'a self, mode: IteratorMode<'_>, readopts: ReadOptions ) -> DBIteratorWithThreadMode<'b, Self>

source

pub fn iterator_cf_opt<'a: 'b, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, readopts: ReadOptions, mode: IteratorMode<'_> ) -> DBIteratorWithThreadMode<'b, Self>

Opens an iterator using the provided ReadOptions. This is used when you want to iterate over a specific ColumnFamily with a modified ReadOptions

source

pub fn full_iterator<'a: 'b, 'b>( &'a self, mode: IteratorMode<'_> ) -> DBIteratorWithThreadMode<'b, Self>

Opens an iterator with set_total_order_seek enabled. This must be used to iterate across prefixes when set_memtable_factory has been called with a Hash-based implementation.

source

pub fn prefix_iterator<'a: 'b, 'b, P: AsRef<[u8]>>( &'a self, prefix: P ) -> DBIteratorWithThreadMode<'b, Self>

source

pub fn iterator_cf<'a: 'b, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, mode: IteratorMode<'_> ) -> DBIteratorWithThreadMode<'b, Self>

source

pub fn full_iterator_cf<'a: 'b, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, mode: IteratorMode<'_> ) -> DBIteratorWithThreadMode<'b, Self>

source

pub fn prefix_iterator_cf<'a, P: AsRef<[u8]>>( &'a self, cf_handle: &impl AsColumnFamilyRef, prefix: P ) -> DBIteratorWithThreadMode<'a, Self>

source

pub fn raw_iterator<'a: 'b, 'b>( &'a self ) -> DBRawIteratorWithThreadMode<'b, Self>

Opens a raw iterator over the database, using the default read options

source

pub fn raw_iterator_cf<'a: 'b, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef ) -> DBRawIteratorWithThreadMode<'b, Self>

Opens a raw iterator over the given column family, using the default read options

source

pub fn raw_iterator_opt<'a: 'b, 'b>( &'a self, readopts: ReadOptions ) -> DBRawIteratorWithThreadMode<'b, Self>

Opens a raw iterator over the database, using the given read options

source

pub fn raw_iterator_cf_opt<'a: 'b, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, readopts: ReadOptions ) -> DBRawIteratorWithThreadMode<'b, Self>

Opens a raw iterator over the given column family, using the given read options

source

pub fn snapshot(&self) -> SnapshotWithThreadMode<'_, Self>

source§

impl TransactionDB<SingleThreaded>

source

pub fn create_cf<N: AsRef<str>>( &mut self, name: N, opts: &Options ) -> Result<(), Error>

Creates column family with given name and options.

source

pub fn cf_handle(&self, name: &str) -> Option<&ColumnFamily>

Returns the underlying column family handle.

source

pub fn drop_cf(&mut self, name: &str) -> Result<(), Error>

Drops the column family with the given name

source§

impl TransactionDB<MultiThreaded>

source

pub fn create_cf<N: AsRef<str>>( &self, name: N, opts: &Options ) -> Result<(), Error>

Creates column family with given name and options.

source

pub fn cf_handle(&self, name: &str) -> Option<Arc<BoundColumnFamily<'_>>>

Returns the underlying column family handle.

source

pub fn drop_cf(&self, name: &str) -> Result<(), Error>

Drops the column family with the given name by internally locking the inner column family map. This avoids needing &mut self reference

Trait Implementations§

source§

impl<T: ThreadMode> DBAccess for TransactionDB<T>

source§

unsafe fn create_snapshot(&self) -> *const rocksdb_snapshot_t

source§

unsafe fn release_snapshot(&self, snapshot: *const rocksdb_snapshot_t)

source§

unsafe fn create_iterator( &self, readopts: &ReadOptions ) -> *mut rocksdb_iterator_t

source§

unsafe fn create_iterator_cf( &self, cf_handle: *mut rocksdb_column_family_handle_t, readopts: &ReadOptions ) -> *mut rocksdb_iterator_t

source§

fn get_opt<K: AsRef<[u8]>>( &self, key: K, readopts: &ReadOptions ) -> Result<Option<Vec<u8>>, Error>

source§

fn get_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions ) -> Result<Option<Vec<u8>>, Error>

source§

fn get_pinned_opt<K: AsRef<[u8]>>( &self, key: K, readopts: &ReadOptions ) -> Result<Option<DBPinnableSlice<'_>>, Error>

source§

fn get_pinned_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions ) -> Result<Option<DBPinnableSlice<'_>>, Error>

source§

fn multi_get_opt<K, I>( &self, keys: I, readopts: &ReadOptions ) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

source§

fn multi_get_cf_opt<'b, K, I, W>( &self, keys_cf: I, readopts: &ReadOptions ) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = (&'b W, K)>, W: AsColumnFamilyRef + 'b,

source§

impl<T: ThreadMode> Drop for TransactionDB<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: ThreadMode> Send for TransactionDB<T>

source§

impl<T: ThreadMode> Sync for TransactionDB<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for TransactionDB<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for TransactionDB<T>
where T: Unpin,

§

impl<T> UnwindSafe for TransactionDB<T>
where T: UnwindSafe,

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, 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.