Struct rocksdb::TransactionDB

pub struct TransactionDB<T = SingleThreaded>
where T: ThreadMode,
{ /* 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§

§

impl<T> TransactionDB<T>
where T: ThreadMode,

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

Opens a database with default options.

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

Opens the database with the specified options.

pub fn open_cf<P, I, N>( opts: &Options, txn_db_opts: &TransactionDBOptions, path: P, cfs: I, ) -> Result<TransactionDB<T>, 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.

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

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

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

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

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

pub fn path(&self) -> &Path

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

Creates a transaction with default options.

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

Creates a transaction with options.

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

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.

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

Returns the bytes associated with a key value.

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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.

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

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

pub fn multi_get_cf_opt<'a, 'b, K, I, W>( &'a self, keys: I, readopts: &ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
where 'b: 'a, 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

§

impl TransactionDB

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

Creates column family with given name and options.

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

Returns the underlying column family handle.

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

Drops the column family with the given name

§

impl TransactionDB<MultiThreaded>

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

Creates column family with given name and options.

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

Returns the underlying column family handle.

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§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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,

§

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

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

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

§

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

Auto Trait Implementations§

§

impl<T = SingleThreaded> !Freeze for TransactionDB<T>

§

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.