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>
impl<'db, DB> Transaction<'db, DB>
sourcepub fn commit(self) -> Result<(), Error>
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
).
pub fn set_name(&self, name: &[u8]) -> Result<(), Error>
pub fn get_name(&self) -> Option<Vec<u8>>
pub fn prepare(&self) -> Result<(), Error>
sourcepub fn snapshot(&self) -> SnapshotWithThreadMode<'_, Self>
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.
sourcepub fn set_savepoint(&self)
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.
sourcepub fn rollback_to_savepoint(&self) -> Result<(), Error>
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
.
sourcepub fn get<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<Vec<u8>>, Error>
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.
pub fn get_pinned<K: AsRef<[u8]>>( &self, key: K, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
sourcepub fn get_cf<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
) -> Result<Option<Vec<u8>>, Error>
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.
pub fn get_pinned_cf<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
sourcepub fn get_for_update<K: AsRef<[u8]>>(
&self,
key: K,
exclusive: bool,
) -> Result<Option<Vec<u8>>, Error>
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.
pub fn get_pinned_for_update<K: AsRef<[u8]>>( &self, key: K, exclusive: bool, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
sourcepub fn get_for_update_cf<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
exclusive: bool,
) -> Result<Option<Vec<u8>>, Error>
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.
pub fn get_pinned_for_update_cf<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, exclusive: bool, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
sourcepub fn get_opt<K: AsRef<[u8]>>(
&self,
key: K,
readopts: &ReadOptions,
) -> Result<Option<Vec<u8>>, Error>
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.
pub fn get_pinned_opt<K: AsRef<[u8]>>( &self, key: K, readopts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
sourcepub fn get_cf_opt<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
readopts: &ReadOptions,
) -> Result<Option<Vec<u8>>, Error>
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.
pub fn get_pinned_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
sourcepub fn get_for_update_opt<K: AsRef<[u8]>>(
&self,
key: K,
exclusive: bool,
opts: &ReadOptions,
) -> Result<Option<Vec<u8>>, Error>
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.
pub fn get_pinned_for_update_opt<K: AsRef<[u8]>>( &self, key: K, exclusive: bool, opts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
sourcepub fn get_for_update_cf_opt<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
exclusive: bool,
opts: &ReadOptions,
) -> Result<Option<Vec<u8>>, Error>
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]
.
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>
sourcepub fn multi_get<K, I>(&self, keys: I) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get<K, I>(&self, keys: I) -> Vec<Result<Option<Vec<u8>>, Error>>
Return the values associated with the given keys.
sourcepub fn multi_get_opt<K, I>(
&self,
keys: I,
readopts: &ReadOptions,
) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get_opt<K, I>( &self, keys: I, readopts: &ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
Return the values associated with the given keys using read options.
sourcepub fn multi_get_cf<'a, 'b: 'a, K, I, W>(
&'a self,
keys: I,
) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get_cf<'a, 'b: 'a, K, I, W>( &'a self, keys: I, ) -> Vec<Result<Option<Vec<u8>>, Error>>
Return the values associated with the given keys and column families.
sourcepub fn multi_get_cf_opt<'a, 'b: 'a, K, I, W>(
&'a self,
keys: I,
readopts: &ReadOptions,
) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get_cf_opt<'a, 'b: 'a, K, I, W>( &'a self, keys: I, readopts: &ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
Return the values associated with the given keys and column families using read options.
sourcepub fn put<K: AsRef<[u8]>, V: AsRef<[u8]>>(
&self,
key: K,
value: V,
) -> Result<(), Error>
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.
sourcepub fn put_cf<K: AsRef<[u8]>, V: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
value: V,
) -> Result<(), Error>
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.
sourcepub fn merge<K: AsRef<[u8]>, V: AsRef<[u8]>>(
&self,
key: K,
value: V,
) -> Result<(), Error>
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.
sourcepub fn merge_cf<K: AsRef<[u8]>, V: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
value: V,
) -> Result<(), Error>
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.
sourcepub fn delete<K: AsRef<[u8]>>(&self, key: K) -> Result<(), Error>
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.
sourcepub fn delete_cf<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
) -> Result<(), Error>
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.
pub fn iterator<'a: 'b, 'b>( &'a self, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'b, Self> ⓘ
pub fn iterator_opt<'a: 'b, 'b>( &'a self, mode: IteratorMode<'_>, readopts: ReadOptions, ) -> DBIteratorWithThreadMode<'b, Self> ⓘ
sourcepub fn iterator_cf_opt<'a: 'b, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
readopts: ReadOptions,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, Self> ⓘ
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.
sourcepub fn full_iterator<'a: 'b, 'b>(
&'a self,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, Self> ⓘ
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.
pub fn prefix_iterator<'a: 'b, 'b, P: AsRef<[u8]>>( &'a self, prefix: P, ) -> DBIteratorWithThreadMode<'b, Self> ⓘ
pub fn iterator_cf<'a: 'b, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'b, Self> ⓘ
pub fn full_iterator_cf<'a: 'b, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'b, Self> ⓘ
pub fn prefix_iterator_cf<'a, P: AsRef<[u8]>>( &'a self, cf_handle: &impl AsColumnFamilyRef, prefix: P, ) -> DBIteratorWithThreadMode<'a, Self> ⓘ
sourcepub fn raw_iterator<'a: 'b, 'b>(
&'a self,
) -> DBRawIteratorWithThreadMode<'b, Self>
pub fn raw_iterator<'a: 'b, 'b>( &'a self, ) -> DBRawIteratorWithThreadMode<'b, Self>
Opens a raw iterator over the database, using the default read options
sourcepub fn raw_iterator_cf<'a: 'b, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
) -> DBRawIteratorWithThreadMode<'b, Self>
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
sourcepub fn raw_iterator_opt<'a: 'b, 'b>(
&'a self,
readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'b, Self>
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
sourcepub fn raw_iterator_cf_opt<'a: 'b, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'b, Self>
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