Struct rocksdb::Transaction

source ·
pub struct Transaction<'db, DB> { /* private fields */ }
Expand description

RocksDB Transaction.

To use transactions, you must first create a TransactionDB or OptimisticTransactionDB.

Implementations§

source§

impl<'db, DB> Transaction<'db, DB>

source

pub fn commit(self) -> Result<(), Error>

Write all batched keys to the DB atomically.

May return any error that could be returned by DB::write.

If this transaction was created by a TransactionDB, an error of the Expired kind may be returned if this transaction has lived longer than expiration time in TransactionOptions.

If this transaction was created by an OptimisticTransactionDB, an error of the Busy kind may be returned if the transaction could not guarantee that there are no write conflicts. An error of the TryAgain kind may be returned if the memtable history size is not large enough (see Options::set_max_write_buffer_size_to_maintain).

source

pub fn set_name(&self, name: &[u8]) -> Result<(), Error>

source

pub fn get_name(&self) -> Option<Vec<u8>>

source

pub fn prepare(&self) -> Result<(), Error>

source

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

Returns snapshot associated with transaction if snapshot was enabled in TransactionOptions. Otherwise, returns a snapshot with nullptr inside which doesn’t effect read operations.

source

pub fn rollback(&self) -> Result<(), Error>

Discard all batched writes in this transaction.

source

pub fn set_savepoint(&self)

Record the state of the transaction for future calls to rollback_to_savepoint. May be called multiple times to set multiple save points.

source

pub fn rollback_to_savepoint(&self) -> Result<(), Error>

Undo all operations in this transaction since the most recent call to set_savepoint and removes the most recent set_savepoint.

Returns error if there is no previous call to set_savepoint.

source

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

Get the bytes associated with a key value.

See get_cf_opt for details.

source

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

source

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

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

See get_cf_opt for details.

source

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

source

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

Get the key and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).

See get_for_update_cf_opt for details.

source

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

source

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

Get the key in the given column family and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).

See get_for_update_cf_opt for details.

source

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

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.

See get_cf_opt for details.

source

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

source

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

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

This function will also read pending changes in this transaction. Currently, this function will return an error of the MergeInProgress kind if the most recent write to the queried key in this batch is a Merge.

source

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

source

pub fn get_for_update_opt<K: AsRef<[u8]>>( &self, key: K, exclusive: bool, opts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>

Get the key with read options and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).

See get_for_update_cf_opt for details.

source

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

source

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

Get the key in the given column family with read options and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).

Currently, this function will return an error of the MergeInProgress if the most recent write to the queried key in this batch is a Merge.

If this transaction was created by a TransactionDB, it can return error of kind:

  • Busy if there is a write conflict.
  • TimedOut if a lock could not be acquired.
  • TryAgain if the memtable history size is not large enough.
  • MergeInProgress if merge operations cannot be resolved.
  • or other errors if this key could not be read.

If this transaction was created by an [OptimisticTransactionDB], get_for_update_opt can cause commit to fail. Otherwise, it could return any error that could be returned by [DB::get].

source

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

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: AsRef<[u8]>, V: AsRef<[u8]>>( &self, key: K, value: V, ) -> Result<(), Error>

Put the key value in default column family and do conflict checking on the key.

See put_cf for details.

source

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

Put the key value in the given column famuly and do conflict checking on the key.

If this transaction was created by a TransactionDB, it can return error of kind:

  • Busy if there is a write conflict.
  • TimedOut if a lock could not be acquired.
  • TryAgain if the memtable history size is not large enough.
  • MergeInProgress if merge operations cannot be resolved.
  • or other errors on unexpected failures.
source

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

Merge value with existing value of key, and also do conflict checking on the key.

See merge_cf for details.

source

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

Merge value with existing value of key in the given column family, and also do conflict checking on the key.

If this transaction was created by a TransactionDB, it can return error of kind:

  • Busy if there is a write conflict.
  • TimedOut if a lock could not be acquired.
  • TryAgain if the memtable history size is not large enough.
  • MergeInProgress if merge operations cannot be resolved.
  • or other errors on unexpected failures.
source

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

Delete the key value if it exists and do conflict checking on the key.

See delete_cf for details.

source

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

Delete the key value in the given column family and do conflict checking.

If this transaction was created by a TransactionDB, it can return error of kind:

  • Busy if there is a write conflict.
  • TimedOut if a lock could not be acquired.
  • TryAgain if the memtable history size is not large enough.
  • MergeInProgress if merge operations cannot be resolved.
  • or other errors on unexpected failures.
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 get_writebatch(&self) -> WriteBatchWithTransaction<true>

source

pub fn rebuild_from_writebatch( &self, writebatch: &WriteBatchWithTransaction<true>, ) -> Result<(), Error>

Trait Implementations§

source§

impl<'db, DB> DBAccess for Transaction<'db, DB>

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<'db, DB> Drop for Transaction<'db, DB>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'db, DB> Send for Transaction<'db, DB>

Auto Trait Implementations§

§

impl<'db, DB> Freeze for Transaction<'db, DB>

§

impl<'db, DB> RefUnwindSafe for Transaction<'db, DB>
where DB: RefUnwindSafe,

§

impl<'db, DB> !Sync for Transaction<'db, DB>

§

impl<'db, DB> Unpin for Transaction<'db, DB>

§

impl<'db, DB> UnwindSafe for Transaction<'db, DB>
where DB: RefUnwindSafe,

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.