pub struct SnapshotWithThreadMode<'a, D: DBAccess> { /* private fields */ }Expand description
A consistent view of the database at the point of creation.
§Examples
use rust_rocksdb::{DB, IteratorMode, Options};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage3")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage3");
let path = tempdir.path();
{
let db = DB::open_default(path).unwrap();
let snapshot = db.snapshot(); // Creates a longer-term snapshot of the DB, but closed when goes out of scope
let mut iter = snapshot.iterator(IteratorMode::Start); // Make as many iterators as you'd like from one snapshot
}
let _ = DB::destroy(&Options::default(), path);A Snapshot must not outlive the DB it was created from:
use rust_rocksdb::DB;
let _snapshot = {
let db = DB::open_default("foo").unwrap();
db.snapshot()
};An iterator created from a snapshot must not outlive the snapshot either:
RocksDB keeps the const Snapshot* inside the iterator’s ReadOptions.
use rust_rocksdb::{DB, IteratorMode};
let db = DB::open_default("foo").unwrap();
let mut iter = {
let snapshot = db.snapshot();
snapshot.iterator(IteratorMode::Start)
};
let _ = iter.next();Implementations§
Source§impl<'a, D: DBAccess> SnapshotWithThreadMode<'a, D>
impl<'a, D: DBAccess> SnapshotWithThreadMode<'a, D>
Sourcepub fn sequence_number(&self) -> Option<u64>
pub fn sequence_number(&self) -> Option<u64>
Returns the sequence number of the snapshot, or None if there is no
underlying snapshot.
A Transaction that was not started with
TransactionOptions::set_snapshot(true)
still hands out a snapshot handle, but that handle wraps a null
rocksdb::Snapshot*. Upstream’s
rocksdb_snapshot_get_sequence_number dereferences it unconditionally,
so this used to be a null dereference reachable from safe code:
let txn = db.transaction(); // no set_snapshot(true)
assert_eq!(txn.snapshot().sequence_number(), None);Sourcepub fn read_options(&self) -> SnapshotReadOptions<'_, 'a, D>
pub fn read_options(&self) -> SnapshotReadOptions<'_, 'a, D>
Creates reusable default read options bound to this snapshot.
Sourcepub fn read_options_opt(
&self,
readopts: ReadOptions,
) -> SnapshotReadOptions<'_, 'a, D>
pub fn read_options_opt( &self, readopts: ReadOptions, ) -> SnapshotReadOptions<'_, 'a, D>
Creates reusable custom read options bound to this snapshot.
Any snapshot already configured on readopts is replaced with this
snapshot.
Sourcepub fn iterator(
&self,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'_, D> ⓘ
pub fn iterator( &self, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'_, D> ⓘ
Creates an iterator over the data in this snapshot, using the default read options.
The iterator borrows the snapshot: the ReadOptions handed to RocksDB
carry a const Snapshot* that the iterator keeps, so it must not outlive
the snapshot.
Sourcepub fn iterator_cf(
&self,
cf_handle: &impl AsColumnFamilyRef,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'_, D> ⓘ
pub fn iterator_cf( &self, cf_handle: &impl AsColumnFamilyRef, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'_, D> ⓘ
Creates an iterator over the data in this snapshot under the given column family, using the default read options.
Sourcepub fn iterator_opt(
&self,
mode: IteratorMode<'_>,
readopts: ReadOptions,
) -> DBIteratorWithThreadMode<'_, D> ⓘ
pub fn iterator_opt( &self, mode: IteratorMode<'_>, readopts: ReadOptions, ) -> DBIteratorWithThreadMode<'_, D> ⓘ
Creates an iterator over the data in this snapshot, using the given read options.
The iterator borrows the snapshot; see Self::iterator.
Sourcepub fn iterator_cf_opt(
&self,
cf_handle: &impl AsColumnFamilyRef,
readopts: ReadOptions,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'_, D> ⓘ
pub fn iterator_cf_opt( &self, cf_handle: &impl AsColumnFamilyRef, readopts: ReadOptions, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'_, D> ⓘ
Creates an iterator over the data in this snapshot under the given column family, using the given read options.
Sourcepub fn raw_iterator(&self) -> DBRawIteratorWithThreadMode<'_, D>
pub fn raw_iterator(&self) -> DBRawIteratorWithThreadMode<'_, D>
Creates a raw iterator over the data in this snapshot, using the default read options.
Sourcepub fn raw_iterator_cf(
&self,
cf_handle: &impl AsColumnFamilyRef,
) -> DBRawIteratorWithThreadMode<'_, D>
pub fn raw_iterator_cf( &self, cf_handle: &impl AsColumnFamilyRef, ) -> DBRawIteratorWithThreadMode<'_, D>
Creates a raw iterator over the data in this snapshot under the given column family, using the default read options.
Sourcepub fn raw_iterator_opt(
&self,
readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'_, D>
pub fn raw_iterator_opt( &self, readopts: ReadOptions, ) -> DBRawIteratorWithThreadMode<'_, D>
Creates a raw iterator over the data in this snapshot, using the given read options.
Sourcepub fn raw_iterator_cf_opt(
&self,
cf_handle: &impl AsColumnFamilyRef,
readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'_, D>
pub fn raw_iterator_cf_opt( &self, cf_handle: &impl AsColumnFamilyRef, readopts: ReadOptions, ) -> DBRawIteratorWithThreadMode<'_, D>
Creates a raw iterator over the data in this snapshot under the given column family, using the given read options.
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>
Returns the bytes associated with a key value with default read options.
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>
Returns the bytes associated with a key value and given column family with default read options.
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 and given read options.
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>
Returns the bytes associated with a key value, given column family and read options.
Sourcepub fn get_pinned<K: AsRef<[u8]>>(
&self,
key: K,
) -> Result<Option<DBPinnableSlice<'_>>, Error>
pub fn get_pinned<K: AsRef<[u8]>>( &self, key: K, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
Return the value associated with a key using RocksDB’s PinnableSlice so as to avoid unnecessary memory copy. Similar to get_pinned_opt but leverages default options.
Sourcepub fn get_pinned_cf<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
) -> Result<Option<DBPinnableSlice<'_>>, Error>
pub fn get_pinned_cf<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
Return the value associated with a key using RocksDB’s PinnableSlice so as to avoid unnecessary memory copy. Similar to get_pinned_cf_opt but leverages default options.
Sourcepub fn get_pinned_opt<K: AsRef<[u8]>>(
&self,
key: K,
readopts: ReadOptions,
) -> Result<Option<DBPinnableSlice<'_>>, Error>
pub fn get_pinned_opt<K: AsRef<[u8]>>( &self, key: K, readopts: ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
Return the value associated with a key using RocksDB’s PinnableSlice so as to avoid unnecessary memory copy.
Sourcepub fn get_pinned_cf_opt<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
readopts: ReadOptions,
) -> Result<Option<DBPinnableSlice<'_>>, Error>
pub fn get_pinned_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
Return the value associated with a key using RocksDB’s PinnableSlice so as to avoid unnecessary memory copy. Similar to get_pinned_opt but allows specifying ColumnFamily.
Sourcepub fn multi_get<K: AsRef<[u8]>, I>(
&self,
keys: I,
) -> Vec<Result<Option<Vec<u8>>, Error>>where
I: IntoIterator<Item = K>,
pub fn multi_get<K: AsRef<[u8]>, I>(
&self,
keys: I,
) -> Vec<Result<Option<Vec<u8>>, Error>>where
I: IntoIterator<Item = K>,
Returns the bytes associated with the given key values and default read options.
Sourcepub fn multi_get_cf<'b, K, I, W>(
&self,
keys_cf: I,
) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get_cf<'b, K, I, W>( &self, keys_cf: I, ) -> Vec<Result<Option<Vec<u8>>, Error>>
Returns the bytes associated with the given key values and default read options.
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>>
Returns the bytes associated with the given key values and given read options.
Sourcepub fn multi_get_cf_opt<'b, K, I, W>(
&self,
keys_cf: I,
readopts: ReadOptions,
) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get_cf_opt<'b, K, I, W>( &self, keys_cf: I, readopts: ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
Returns the bytes associated with the given key values, given column family and read options.
Trait Implementations§
Source§impl<D: DBAccess> Drop for SnapshotWithThreadMode<'_, D>
impl<D: DBAccess> Drop for SnapshotWithThreadMode<'_, D>
impl<D: DBAccess + Sync> Send for SnapshotWithThreadMode<'_, D>
Send and Sync implementations for SnapshotWithThreadMode are safe, because SnapshotWithThreadMode is
immutable and can be safely shared between threads.