Skip to main content

DBCommon

Struct DBCommon 

Source
pub struct DBCommon<T: ThreadMode, D: DBInner> { /* private fields */ }
Expand description

A helper type to implement some common methods for DBWithThreadMode and OptimisticTransactionDB.

When using SingleThreaded mode, create_cf requires &mut self, preventing multiple immutable references from calling it concurrently:

ⓘ
use rust_rocksdb::{DBWithThreadMode, Options, SingleThreaded};

let db = DBWithThreadMode::<SingleThreaded>::open_default("/path/to/dummy").unwrap();
let db_ref1 = &db;
let db_ref2 = &db;
let opts = Options::default();
db_ref1.create_cf("cf1", &opts).unwrap();
db_ref2.create_cf("cf2", &opts).unwrap();

Implementations§

Source§

impl<T: ThreadMode> DBCommon<T, DBWithThreadModeInner>

Methods of DBWithThreadMode.

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, path: P) -> Result<Self, Error>

Opens the database with the specified options.

Source

pub fn open_for_read_only<P: AsRef<Path>>( opts: &Options, path: P, error_if_log_file_exist: bool, ) -> Result<Self, Error>

Opens the database for read only with the specified options.

Source

pub fn open_as_secondary<P: AsRef<Path>>( opts: &Options, primary_path: P, secondary_path: P, ) -> Result<Self, Error>

Opens the database as a secondary.

Source

pub fn open_with_ttl<P: AsRef<Path>>( opts: &Options, path: P, ttl: Duration, ) -> Result<Self, Error>

Opens the database with a Time to Live compaction filter.

This applies the given ttl to all column families created without an explicit TTL. See DB::open_cf_descriptors_with_ttl for more control over individual column family TTLs.

RocksDB stores the TTL as a 32-bit second count, so a ttl longer than i32::MAX seconds (about 68 years) is clamped to that maximum rather than wrapping.

Source

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

Opens the database with a Time to Live compaction filter and column family names.

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

Source

pub fn open_cf_descriptors_with_ttl<P, I>( opts: &Options, path: P, cfs: I, ttl: Duration, ) -> Result<Self, Error>

Opens a database with the given database with a Time to Live compaction filter and column family descriptors.

Applies the provided ttl as the default TTL for all column families. Column families will inherit this TTL by default, unless their descriptor explicitly sets a different TTL using ColumnFamilyTtl::Duration or opts out using ColumnFamilyTtl::Disabled.

NOTE: The default column family is opened with Options::default() unless explicitly configured within the cfs iterator. To customize the default column family’s options, include a ColumnFamilyDescriptor with the name “default” in the cfs iterator.

If you want to open default cf with different options, set them explicitly in cfs.

Source

pub fn open_cf_and_trim_history<P, I, N>( opts: &Options, path: P, cfs: I, trim_ts: &[u8], ) -> Result<Self, Error>
where P: AsRef<Path>, I: IntoIterator<Item = N>, N: AsRef<str>,

Opens the database and drops everything written after trim_ts.

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

§Errors

See open_cf_descriptors_and_trim_history.

Source

pub fn open_cf_descriptors_and_trim_history<P, I>( opts: &Options, path: P, cfs: I, trim_ts: &[u8], ) -> Result<Self, Error>

Opens the database and drops everything written after trim_ts, given column family descriptors.

This is for recovering a column family that uses user-defined timestamps, where writes past a known good point have to be undone before anything reads them. Entries with a timestamp greater than trim_ts are gone once this returns. trim_ts is compared with the column family’s comparator, so it has to be encoded the way that comparator expects. Column families without user-defined timestamps are left alone.

The trim is permanent, so open a copy first if the discarded writes still matter.

RocksDB marks the underlying API experimental and subject to change.

NOTE: The default column family is opened with Options::default() unless explicitly configured within the cfs iterator. A column family that uses user-defined timestamps carries its comparator in its own options, so it has to be named here with those options even when it is the default one. Opening it with Options::default() instead fails with a comparator mismatch.

§Errors

Returns the RocksDB error if the database cannot be opened, which includes leaving out a column family that exists on disk. Also errors if a column family name contains an interior NUL byte, or if the directory cannot be created.

Source

pub fn open_cf<P, I, N>(opts: &Options, 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_with_opts<P, I, N>( opts: &Options, path: P, cfs: I, ) -> Result<Self, Error>
where P: AsRef<Path>, I: IntoIterator<Item = (N, Options)>, N: AsRef<str>,

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

Column families opened using given Options.

Source

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

Opens a database for read only with the given database options and column family names. NOTE: default column family is opened with Options::default(). If you want to open default cf with different options, set them explicitly in cfs.

Source

pub fn open_cf_with_opts_for_read_only<P, I, N>( db_opts: &Options, path: P, cfs: I, error_if_log_file_exist: bool, ) -> Result<Self, Error>
where P: AsRef<Path>, I: IntoIterator<Item = (N, Options)>, N: AsRef<str>,

Opens a database for read only with the given database options and column family names. NOTE: default column family is opened with Options::default(). If you want to open default cf with different options, set them explicitly in cfs.

Source

pub fn open_cf_descriptors_read_only<P, I>( opts: &Options, path: P, cfs: I, error_if_log_file_exist: bool, ) -> Result<Self, Error>

Opens a database for ready only with the given database options and column family descriptors. NOTE: default column family is opened with Options::default(). If you want to open default cf with different options, set them explicitly in cfs.

Source

pub fn open_cf_as_secondary<P, I, N>( opts: &Options, primary_path: P, secondary_path: P, cfs: I, ) -> Result<Self, Error>
where P: AsRef<Path>, I: IntoIterator<Item = N>, N: AsRef<str>,

Opens the database as a secondary with the given database options and column family names. NOTE: default column family is opened with Options::default(). If you want to open default cf with different options, set them explicitly in cfs.

Source

pub fn open_cf_descriptors_as_secondary<P, I>( opts: &Options, path: P, secondary_path: P, cfs: I, ) -> Result<Self, Error>

Opens the database as a secondary with the given database options and column family descriptors. NOTE: default column family is opened with Options::default(). If you want to open default cf with different options, set them explicitly in cfs.

Source

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

Opens a database with the given database options and column family descriptors. NOTE: default column family is opened with Options::default(). If you want to open default cf with different options, set them explicitly in cfs.

Source

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

Removes the database entries in the range ["from", "to") using given write options.

Source

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

Removes the database entries in the range ["from", "to") using default write options.

Source

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

Source

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

Source

pub fn write_without_wal(&self, batch: &WriteBatch) -> Result<(), Error>

Source

pub fn write_wbwi(&self, wbwi: &WriteBatchWithIndex) -> Result<(), Error>

Source

pub fn write_wbwi_opt( &self, wbwi: &WriteBatchWithIndex, writeopts: &WriteOptions, ) -> Result<(), Error>

Source§

impl<T: ThreadMode, D: DBInner> DBCommon<T, D>

Common methods of DBWithThreadMode and OptimisticTransactionDB.

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 resume(&self) -> Result<(), Error>

Tries to clear a background error and resume writes.

Returns Ok right away if no background error is stopping writes or background work. Recovering waits for running flushes and compactions to finish and then flushes every column family, so this can block for a while.

Out of space is the only kind of I/O error this can recover from on the built-in filesystems: a full disk, or going over SstFileManager::set_max_allowed_space_usage. Other I/O errors are fatal with the default paranoid_checks and corruption is unrecoverable, so for those this returns the error and the DB has to be reopened.

RocksDB normally recovers from out-of-space errors on its own. Every DB gets an SstFileManager even if you don’t set one, and it retries every few seconds until enough space is free. While that is running this returns Busy. To recover manually instead, set the &mut bool passed to EventListener::on_error_recovery_begin to false, and only call this once space has been freed. A recovery flush that fails because the disk is still full can make the error fatal, and then only reopening helps.

Options::set_max_bgerror_resume_count only applies to errors a filesystem marks as retryable, and the built-in ones never produce any that take that path.

See also https://github.com/facebook/rocksdb/wiki/Background-Error-Handling.

§Errors
  • Busy if automatic recovery is running. This doesn’t wait for it.
  • The stored background error if it is fatal or unrecoverable.
  • The new error if the recovery flush fails, e.g. the disk is still full.
Source

pub fn path(&self) -> &Path

Source

pub fn flush_wal(&self, sync: bool) -> Result<(), Error>

Flushes the WAL buffer. If sync is set to true, also syncs the data to disk.

Source

pub fn flush_wal_with_options( &self, opts: &FlushWalOptions, ) -> Result<(), Error>

Flushes the WAL buffer, taking the rate limiter priority as well as sync.

flush_wal covers the common case. Reach for this one to give the flush a priority other than the default, which decides how the WAL write is charged against a configured rate limiter.

§Errors

Returns the RocksDB error if the flush or the sync fails.

Source

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

Stops background flushes and compactions and waits for the ones already running to finish.

Writes are not blocked, so they keep filling memtables that cannot be flushed. Enough of them and the DB stalls or hits the stop trigger, so pair this with continue_background_work and keep the gap short.

Calls nest. Background work resumes once as many continue calls have been made as pause calls.

§Errors

Returns the RocksDB error if the DB is shutting down.

Source

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

Undoes one pause_background_work call.

§Errors

Returns the RocksDB error if background work was not paused, or if the DB is shutting down.

Source

pub fn enable_manual_compaction(&self)

Undoes one disable_manual_compaction call.

This is a counter, so it takes as many calls here as there were calls there before manual compactions start running again.

Pair the two. RocksDB decrements without a floor, and the assertion that would catch it is compiled out of this build, so calling this more often than disable_manual_compaction drives the counter below zero. That reads as not paused, which looks fine, but it means the next disable_manual_compaction only brings the counter back to zero and does not actually pause anything.

Source

pub fn disable_manual_compaction(&self)

Cancels running manual compactions and makes later ones return immediately.

Affects only manual compactions, so compact_range, compact_files and the like. Automatic background compaction keeps going. Use it to get out of a long manual compaction during shutdown without waiting for it.

This increments a counter, so it needs a matching enable_manual_compaction call for each call here.

Source

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

Reads every live SST and blob file and checks its block checksums.

Reads the whole DB, so it is as slow as the data is large.

§Errors

Returns the RocksDB error naming the first corrupt file found.

Source

pub fn verify_checksum_opt(&self, readopts: &ReadOptions) -> Result<(), Error>

Like verify_checksum, reading through readopts.

Worth setting when the default read path is not what you want for a full scan, for instance to keep the verification from filling the block cache or to give it a rate limiter priority.

§Errors

See verify_checksum.

Source

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

Recomputes each live file’s whole file checksum and compares it against the one recorded in the manifest.

This is the file level check, as opposed to the per block one verify_checksum does. It requires the DB to have been written with a file checksum generator, see Options::set_file_checksum_gen_factory.

§Errors

Returns the RocksDB error naming the first file whose checksum does not match what the manifest recorded. Also errors when no generator is configured, since then there is nothing recorded to compare against, rather than treating that as having nothing to check.

Source

pub fn verify_file_checksums_opt( &self, readopts: &ReadOptions, ) -> Result<(), Error>

Like verify_file_checksums, reading through readopts.

§Errors

See verify_file_checksums.

Source

pub fn suggest_compact_range<S: AsRef<[u8]>, E: AsRef<[u8]>>( &self, start: Option<S>, end: Option<E>, ) -> Result<(), Error>

Marks the files overlapping [start, end) for compaction and returns without compacting anything.

Background compaction picks the marked files up on its own schedule, so this returns as soon as the marking is done. That makes it the cheap way to hint that a range is worth compacting, as opposed to compact_range, which does the work before it returns.

None for either bound means unbounded in that direction. An empty slice is a real empty key, not the same thing.

§Errors

Returns the RocksDB error if the range cannot be marked.

Source

pub fn suggest_compact_range_cf<S: AsRef<[u8]>, E: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, start: Option<S>, end: Option<E>, ) -> Result<(), Error>

Like suggest_compact_range, for a single column family.

§Errors

See suggest_compact_range.

Source

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

Reads a key along with the user-defined timestamp its value was written with.

Only meaningful on a column family configured for user-defined timestamps, so one whose comparator carries a timestamp size. The plain get reads the same value but throws the timestamp away, and there is no pinned equivalent of this call in the C API.

readopts decides which timestamp is read. Without a read timestamp set on it RocksDB rejects the read rather than picking one, see ReadOptions::set_timestamp.

§Errors

Returns the RocksDB error if the read fails. A key that is not present is Ok(None), not an error.

Source

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

Like get_with_ts, for a single column family.

§Errors

See get_with_ts.

Source

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

Reads many keys along with the timestamps their values were written with.

One native batch, results in input order, one Result per key so a single bad key does not sink the batch. See get_with_ts for what the timestamp means and what readopts has to carry.

Source

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

Like multi_get_with_ts, for one column family per key.

Source

pub fn set_db_options(&self, opts: &[(&str, &str)]) -> Result<(), Error>

Changes DB wide mutable options at runtime.

Takes the same option names and string values the RocksDB configuration strings use, so max_background_jobs or bytes_per_sync. Only options RocksDB marks mutable at the DB level can be set, and the whole call is rejected if any name or value is not accepted.

set_options is the column family equivalent.

§Aborts

Some unparseable values take the process down instead of returning an error. See set_options for the details and why this is not caught.

§Errors

Returns the RocksDB error if a name is unknown or the option is not changeable at runtime, and for an empty opts, which RocksDB rejects as empty input. Also errors if any name or value contains an interior NUL byte.

Source

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

Suspend deleting obsolete files. Compactions will continue to occur, but no obsolete files will be deleted. To resume file deletions, each call to disable_file_deletions() must be matched by a subsequent call to enable_file_deletions(). For more details, see enable_file_deletions().

Source

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

Resume deleting obsolete files, following up on disable_file_deletions().

File deletions disabling and enabling is not controlled by a binary flag, instead it’s represented as a counter to allow different callers to independently disable file deletion. Disabling file deletion can be critical for operations like making a backup. So the counter implementation makes the file deletion disabled as long as there is one caller requesting so, and only when every caller agrees to re-enable file deletion, it will be enabled. Two threads can call this method concurrently without synchronization – i.e., file deletions will be enabled only after both threads call enable_file_deletions()

Source

pub fn flush_opt(&self, flushopts: &FlushOptions) -> Result<(), Error>

Flushes database memtables to SST files on the disk.

Source

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

Flushes database memtables to SST files on the disk using default options.

Source

pub fn flush_cf_opt( &self, cf: &impl AsColumnFamilyRef, flushopts: &FlushOptions, ) -> Result<(), Error>

Flushes database memtables to SST files on the disk for a given column family.

Source

pub fn flush_cfs_opt( &self, cfs: &[&impl AsColumnFamilyRef], opts: &FlushOptions, ) -> Result<(), Error>

Flushes multiple column families.

If atomic flush is not enabled, it is equivalent to calling flush_cf multiple times. If atomic flush is enabled, it will flush all column families specified in cfs up to the latest sequence number at the time when flush is requested.

Source

pub fn flush_cf(&self, cf: &impl AsColumnFamilyRef) -> Result<(), Error>

Flushes database memtables to SST files on the disk for a given column family using default options.

Source

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

Return the bytes associated with a key value with read options. If you only intend to use the vector returned temporarily, consider using get_pinned_opt to avoid unnecessary memory copy.

Source

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

Return the bytes associated with a key value. If you only intend to use the vector returned temporarily, consider using get_pinned to avoid unnecessary memory copy.

Source

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

Return the bytes associated with a key value and the given column family with read options. If you only intend to use the vector returned temporarily, consider using get_pinned_cf_opt to avoid unnecessary memory.

Source

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

Return the bytes associated with a key value and the given column family. If you only intend to use the vector returned temporarily, consider using get_pinned_cf to avoid unnecessary memory.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn get_into_buffer<K: AsRef<[u8]>>( &self, key: K, buffer: &mut [u8], ) -> Result<GetIntoBufferResult, Error>

Read a value directly into a caller-provided buffer, avoiding memory allocation.

This is the most efficient way to read values when you have a pre-allocated buffer. It completely avoids the allocation overhead of get and even the pinning overhead of get_pinned.

§Arguments
  • key - The key to look up
  • buffer - A mutable byte slice to write the value into. Can be empty if you only want to check if a key exists and get its value size.
§Returns
  • Ok(GetIntoBufferResult::NotFound) - The key doesn’t exist
  • Ok(GetIntoBufferResult::Found(size)) - Value was copied into the buffer. size is the number of bytes written.
  • Ok(GetIntoBufferResult::BufferTooSmall(size)) - The value exists but the buffer is too small. size is the actual value size needed. No data is written.
  • Err(...) - Database error occurred
§Performance

This method is ideal for high-throughput scenarios where you can reuse a buffer:

ⓘ
use rust_rocksdb::{DB, GetIntoBufferResult};

let db: DB = /* open database */;
let keys_to_lookup: Vec<&[u8]> = /* keys to look up */;
let mut buffer = vec![0u8; 4096]; // Reusable buffer

for key in keys_to_lookup {
    match db.get_into_buffer(key, &mut buffer).unwrap() {
        GetIntoBufferResult::Found(len) => {
            process_value(&buffer[..len]);
        }
        GetIntoBufferResult::BufferTooSmall(needed) => {
            buffer.resize(needed, 0);
            // Retry with larger buffer...
        }
        GetIntoBufferResult::NotFound => {}
    }
}
§Example
use rust_rocksdb::{DB, GetIntoBufferResult};

let tempdir = tempfile::Builder::new()
    .prefix("rocksdb_get_into_buffer")
    .tempdir()
    .unwrap();
let db = DB::open_default(tempdir.path()).unwrap();
db.put(b"key", b"value").unwrap();

let mut buffer = [0u8; 100];
match db.get_into_buffer(b"key", &mut buffer).unwrap() {
    GetIntoBufferResult::Found(size) => {
        assert_eq!(&buffer[..size], b"value");
    }
    GetIntoBufferResult::NotFound => panic!("expected value"),
    GetIntoBufferResult::BufferTooSmall(needed) => {
        panic!("buffer too small, need {} bytes", needed)
    }
}
Source

pub fn get_into_buffer_opt<K: AsRef<[u8]>>( &self, key: K, buffer: &mut [u8], readopts: &ReadOptions, ) -> Result<GetIntoBufferResult, Error>

Read a value directly into a caller-provided buffer with custom read options.

This is the same as get_into_buffer but allows specifying custom ReadOptions, such as setting a snapshot or fill cache behavior.

See get_into_buffer for full documentation.

Source

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

Read a value from a column family directly into a caller-provided buffer.

This is the column family variant of get_into_buffer. See that method for full documentation on the zero-allocation buffer API.

§Arguments
  • cf - The column family to read from
  • key - The key to look up
  • buffer - A mutable byte slice to write the value into
Source

pub fn get_into_buffer_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, buffer: &mut [u8], readopts: &ReadOptions, ) -> Result<GetIntoBufferResult, Error>

Read a value from a column family directly into a caller-provided buffer with custom read options.

This is the column family variant of get_into_buffer_opt. See get_into_buffer for full documentation.

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_pinned<K, I>( &self, keys: I, ) -> Vec<Result<Option<DBPinnableSlice<'_>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Returns pinned values associated with the given keys using default read options.

RocksDB processes the keys in one native batch. Results stay in input order.

Source

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

Returns pinned values associated with the given keys using the provided read options.

RocksDB processes the keys in one native batch. Results stay in input order.

Source

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

Returns pinned values associated with the given keys and column families using default read options.

Source

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

Returns pinned values associated with the given keys and column families using the provided read options.

Source

pub fn batched_multi_get_pinned<K, I>( &self, keys: I, sorted_input: bool, ) -> Vec<Result<Option<DBPinnableSlice<'_>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Returns pinned values for default-column-family keys in one native batch.

Set sorted_input only when keys are sorted according to the column family’s comparator. Results stay in input order, including duplicates.

Source

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

Returns pinned values for default-column-family keys in one native batch using the provided read options.

Source

pub fn batched_multi_get_pinned_cf<K, I>( &self, cf: &impl AsColumnFamilyRef, keys: I, sorted_input: bool, ) -> Vec<Result<Option<DBPinnableSlice<'_>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Returns pinned values for keys in one column family using one native batch.

Set sorted_input only when keys are sorted according to the column family’s comparator. Results stay in input order, including duplicates.

Source

pub fn batched_multi_get_pinned_cf_opt<K, I>( &self, cf: &impl AsColumnFamilyRef, keys: I, sorted_input: bool, readopts: &ReadOptions, ) -> Vec<Result<Option<DBPinnableSlice<'_>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Returns pinned values for keys in one column family using one native batch and the provided read options.

Source

pub fn batched_multi_get_pinned_batch<K, I>( &self, keys: I, sorted_input: bool, ) -> Result<DBPinnableBatch<'_>, Error>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Returns one owner for all default-column-family pinned results.

Values borrow from the returned batch, avoiding one native wrapper allocation and one destroy call per successful key.

Source

pub fn batched_multi_get_pinned_batch_opt<K, I>( &self, keys: I, sorted_input: bool, readopts: &ReadOptions, ) -> Result<DBPinnableBatch<'_>, Error>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Returns one owner for all default-column-family pinned results using the provided read options.

Source

pub fn batched_multi_get_pinned_batch_cf<K, I>( &self, cf: &impl AsColumnFamilyRef, keys: I, sorted_input: bool, ) -> Result<DBPinnableBatch<'_>, Error>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Returns one owner for all pinned results from one column family.

Source

pub fn batched_multi_get_pinned_batch_cf_opt<K, I>( &self, cf: &impl AsColumnFamilyRef, keys: I, sorted_input: bool, readopts: &ReadOptions, ) -> Result<DBPinnableBatch<'_>, Error>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Returns one owner for all pinned results from one column family using the provided 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 batched_multi_get_cf<'a, K, I>( &self, cf: &impl AsColumnFamilyRef, keys: I, sorted_input: bool, ) -> Vec<Result<Option<DBPinnableSlice<'_>>, Error>>
where K: AsRef<[u8]> + 'a + ?Sized, I: IntoIterator<Item = &'a K>,

Return the values associated with the given keys and the specified column family where internally the read requests are processed in batch if block-based table SST format is used. It is a more optimized version of multi_get_cf.

Source

pub fn batched_multi_get_cf_opt<'a, K, I>( &self, cf: &impl AsColumnFamilyRef, keys: I, sorted_input: bool, readopts: &ReadOptions, ) -> Vec<Result<Option<DBPinnableSlice<'_>>, Error>>
where K: AsRef<[u8]> + 'a + ?Sized, I: IntoIterator<Item = &'a K>,

Return the values associated with the given keys and the specified column family where internally the read requests are processed in batch if block-based table SST format is used. It is a more optimized version of multi_get_cf_opt.

Source

pub fn batched_multi_get_cf_slice<'a, K, I>( &self, cf: &impl AsColumnFamilyRef, keys: I, sorted_input: bool, ) -> Vec<Result<Option<DBPinnableSlice<'_>>, Error>>
where K: AsRef<[u8]> + 'a + ?Sized, I: IntoIterator<Item = &'a K>,

Return the values associated with the given keys and the specified column family using an optimized slice-based API.

This method uses RocksDB’s optimized rocksdb_batched_multi_get_cf_slice C API, which takes a rocksdb_slice_t array directly. This eliminates the internal overhead of converting keys from separate pointer+size arrays to Slice objects.

§Arguments
  • cf - The column family to read from
  • keys - An iterator of keys to look up
  • sorted_input - If true, indicates the keys are already sorted in ascending order, which allows RocksDB to skip internal sorting and improve performance. Important: If you pass true but keys are not sorted, results may be incorrect.
§Returns

A vector of results in the same order as the input keys. Each element is:

  • Ok(Some(DBPinnableSlice)) if the key was found
  • Ok(None) if the key was not found
  • Err(...) if an error occurred for that key
§Performance

This is the fastest batch lookup method when:

  • You’re looking up many keys (10+) from the same column family
  • You can pre-sort your keys (set sorted_input = true)
  • Block-based table format is used (default)

For small numbers of keys, the overhead of batching may not be worth it. Consider using get_pinned_cf for single key lookups.

§Example
use rust_rocksdb::{DB, Options, ColumnFamilyDescriptor};

let tempdir = tempfile::Builder::new().prefix("batch_slice").tempdir().unwrap();
let mut opts = Options::default();
opts.create_if_missing(true);
opts.create_missing_column_families(true);
let db = DB::open_cf_descriptors(&opts, tempdir.path(),
    vec![ColumnFamilyDescriptor::new("cf", Options::default())]).unwrap();

let cf = db.cf_handle("cf").unwrap();
db.put_cf(&cf, b"k1", b"v1").unwrap();
db.put_cf(&cf, b"k2", b"v2").unwrap();

// Keys are sorted, so we can set sorted_input = true
let keys: Vec<&[u8]> = vec![b"k1", b"k2", b"k3"];
let results = db.batched_multi_get_cf_slice(&cf, keys, true);

assert!(results[0].as_ref().unwrap().is_some()); // k1 found
assert!(results[1].as_ref().unwrap().is_some()); // k2 found
assert!(results[2].as_ref().unwrap().is_none()); // k3 not found
Source

pub fn batched_multi_get_cf_slice_opt<'a, K, I>( &self, cf: &impl AsColumnFamilyRef, keys: I, sorted_input: bool, readopts: &ReadOptions, ) -> Vec<Result<Option<DBPinnableSlice<'_>>, Error>>
where K: AsRef<[u8]> + 'a + ?Sized, I: IntoIterator<Item = &'a K>,

Return the values associated with the given keys and the specified column family using an optimized slice-based API with custom read options.

This is the same as batched_multi_get_cf_slice but allows specifying custom ReadOptions.

See batched_multi_get_cf_slice for full documentation.

Source

pub fn key_may_exist<K: AsRef<[u8]>>(&self, key: K) -> bool

Returns false if the given key definitely doesn’t exist in the database, otherwise returns true. This function uses default ReadOptions.

Source

pub fn key_may_exist_opt<K: AsRef<[u8]>>( &self, key: K, readopts: &ReadOptions, ) -> bool

Returns false if the given key definitely doesn’t exist in the database, otherwise returns true.

Source

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

Returns false if the given key definitely doesn’t exist in the specified column family, otherwise returns true. This function uses default ReadOptions.

Source

pub fn key_may_exist_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> bool

Returns false if the given key definitely doesn’t exist in the specified column family, otherwise returns true.

Source

pub fn key_may_exist_cf_opt_value<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> (bool, Option<CSlice>)

If the key definitely does not exist in the database, then this method returns (false, None), else (true, None) if it may. If the key is found in memory, then it returns (true, Some<CSlice>).

This check is potentially lighter-weight than calling get(). One way to make this lighter weight is to avoid doing any IOs.

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 prefix_exists<P: AsRef<[u8]>>(&self, prefix: P) -> Result<bool, Error>

Returns true if there exists at least one key with the given prefix in the default column family using default read options.

When to use: prefer this for one-shot checks. It enables prefix_same_as_start(true) and bounds the iterator to the prefix via PrefixRange, minimizing stray IO per call.

Source

pub fn prefix_exists_opt<P: AsRef<[u8]>>( &self, prefix: P, readopts: &ReadOptions, ) -> Result<bool, Error>

Returns true if there exists at least one key with the given prefix in the default column family using the provided read options.

Source

pub fn prefix_prober(&self) -> PrefixProber<'_, Self>

Creates a reusable prefix prober over the default column family using read options optimized for prefix probes.

When to use: prefer this in hot loops with many checks per second. It reuses a raw iterator to avoid per-call allocation/FFI overhead. If you need custom tuning (e.g. async IO, readahead, cache-only), use prefix_prober_with_opts.

Source

pub fn prefix_prober_with_opts( &self, readopts: ReadOptions, ) -> PrefixProber<'_, Self>

Creates a reusable prefix prober over the default column family using the provided read options (owned).

When to use: advanced tuning for heavy workloads. Callers can set set_async_io(true), set_readahead_size, set_read_tier, etc. Note: the prober owns ReadOptions to keep internal buffers alive.

Source

pub fn prefix_prober_cf( &self, cf_handle: &impl AsColumnFamilyRef, ) -> PrefixProber<'_, Self>

Creates a reusable prefix prober over the specified column family using read options optimized for prefix probes.

Source

pub fn prefix_prober_cf_with_opts( &self, cf_handle: &impl AsColumnFamilyRef, readopts: ReadOptions, ) -> PrefixProber<'_, Self>

Creates a reusable prefix prober over the specified column family using the provided read options (owned).

When to use: advanced tuning for heavy workloads on a specific CF.

Source

pub fn prefix_exists_cf<P: AsRef<[u8]>>( &self, cf_handle: &impl AsColumnFamilyRef, prefix: P, ) -> Result<bool, Error>

Returns true if there exists at least one key with the given prefix in the specified column family using default read options.

When to use: one-shot checks on a CF. Enables prefix_same_as_start(true) and bounds the iterator via PrefixRange.

Source

pub fn prefix_exists_cf_opt<P: AsRef<[u8]>>( &self, cf_handle: &impl AsColumnFamilyRef, prefix: P, readopts: &ReadOptions, ) -> Result<bool, Error>

Returns true if there exists at least one key with the given prefix in the specified column family using the provided read options.

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_iterators_cf<'a, 'b, W, I>( &'a self, column_families: I, ) -> Result<Vec<DBRawIteratorWithThreadMode<'a, Self>>, Error>
where W: AsColumnFamilyRef + 'b, I: IntoIterator<Item = &'b W>,

Opens raw iterators for multiple column families from one consistent RocksDB state.

The returned iterators match the input column family order and own their native handles. They share one ReadOptions, because one native rocksdb_create_iterators call applies a single options object to every iterator it creates.

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

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

Set the database entry for “key” to “value” with WriteOptions. If “key” already exists, it will coexist with previous entry. Get with a timestamp ts specified in ReadOptions will return the most recent key/value whose timestamp is smaller than or equal to ts. Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

Source

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

Put with timestamp in a specific column family with WriteOptions. If “key” already exists, it will coexist with previous entry. Get with a timestamp ts specified in ReadOptions will return the most recent key/value whose timestamp is smaller than or equal to ts. Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

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_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 delete_with_ts_opt<K, S>( &self, key: K, ts: S, writeopts: &WriteOptions, ) -> Result<(), Error>
where K: AsRef<[u8]>, S: AsRef<[u8]>,

Remove the database entry (if any) for “key” with WriteOptions. Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

Source

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

Delete with timestamp in a specific column family with WriteOptions. Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

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

Set the database entry for “key” to “value”. If “key” already exists, it will coexist with previous entry. Get with a timestamp ts specified in ReadOptions will return the most recent key/value whose timestamp is smaller than or equal to ts. Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

Source

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

Put with timestamp in a specific column family. If “key” already exists, it will coexist with previous entry. Get with a timestamp ts specified in ReadOptions will return the most recent key/value whose timestamp is smaller than or equal to ts. Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

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

Remove the database entry (if any) for “key”. Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

Source

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

Delete with timestamp in a specific column family. Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

Source

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

Remove the database entry for “key” with WriteOptions.

Requires that the key exists and was not overwritten. Returns OK on success, and a non-OK status on error. It is not an error if “key” did not exist in the database.

If a key is overwritten (by calling Put() multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key.

This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior.

Note: consider setting options.sync = true.

For more information, see https://github.com/facebook/rocksdb/wiki/Single-Delete

Source

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

Remove the database entry for “key” from a specific column family with WriteOptions.

See single_delete_opt() for detailed behavior and restrictions.

Source

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

Remove the database entry for “key” with WriteOptions.

Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

See single_delete_opt() for detailed behavior and restrictions.

Source

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

Remove the database entry for “key” from a specific column family with WriteOptions.

Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

See single_delete_opt() for detailed behavior and restrictions.

Source

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

Remove the database entry for “key”.

See single_delete_opt() for detailed behavior and restrictions.

Source

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

Remove the database entry for “key” from a specific column family.

See single_delete_opt() for detailed behavior and restrictions.

Source

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

Remove the database entry for “key”.

Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

See single_delete_opt() for detailed behavior and restrictions.

Source

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

Remove the database entry for “key” from a specific column family.

Takes an additional argument ts as the timestamp. Note: the DB must be opened with user defined timestamp enabled.

See single_delete_opt() for detailed behavior and restrictions.

Source

pub fn compact_range<S: AsRef<[u8]>, E: AsRef<[u8]>>( &self, start: Option<S>, end: Option<E>, )

Runs a manual compaction on the Range of keys given. This is not likely to be needed for typical usage.

Source

pub fn compact_range_opt<S: AsRef<[u8]>, E: AsRef<[u8]>>( &self, start: Option<S>, end: Option<E>, opts: &CompactOptions, )

Same as compact_range but with custom options.

Source

pub fn compact_range_cf<S: AsRef<[u8]>, E: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, start: Option<S>, end: Option<E>, )

Runs a manual compaction on the Range of keys given on the given column family. This is not likely to be needed for typical usage.

Source

pub fn compact_range_cf_opt<S: AsRef<[u8]>, E: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, start: Option<S>, end: Option<E>, opts: &CompactOptions, )

Same as compact_range_cf but with custom options.

Source

pub fn wait_for_compact( &self, opts: &WaitForCompactOptions, ) -> Result<(), Error>

Wait for all flush and compactions jobs to finish. Jobs to wait include the unscheduled (queued, but not scheduled yet).

NOTE: This may also never return if there’s sufficient ongoing writes that keeps flush and compaction going without stopping. The user would have to cease all the writes to DB to make this eventually return in a stable state. The user may also use timeout option in WaitForCompactOptions to make this stop waiting and return when timeout expires.

Source

pub fn set_options(&self, opts: &[(&str, &str)]) -> Result<(), Error>

Changes mutable column family options on the default column family at runtime.

set_db_options is the DB wide equivalent. Either the whole set is applied or none of it is.

§Aborts

Some unparseable values take the process down instead of returning an error, so validate values before passing them here.

RocksDB parses integers with std::stoi and friends (util/string_util.cc:378), which throw std::invalid_argument. It does try to catch that, but not everywhere, and an integer-valued option such as write_buffer_size given a non-numeric value aborts the process with “Rust cannot catch foreign exceptions”. A boolean-valued option such as disable_auto_compactions returns an error instead. Do not rely on which options fall on which side of that line.

Catching it here is not an option. ColumnFamilyData::SetOptions runs inside a callback that VersionSet::LogAndApply invokes while holding the DB mutex as the exclusive manifest writer (db/db_impl/db_impl.cc:1655), so unwinding through it leaves that state behind and the next option change on the DB blocks forever in InstrumentedCondVar::Wait. That was reproducible under ASAN and silent otherwise, which is worse than aborting.

§Errors

Returns the RocksDB error if a name is unknown or the option is not changeable at runtime. Also errors if any name or value contains an interior NUL byte.

Source

pub fn set_options_cf( &self, cf: &impl AsColumnFamilyRef, opts: &[(&str, &str)], ) -> Result<(), Error>

Like set_options, for a single column family.

§Aborts

See set_options.

§Errors

See set_options.

Source

pub fn property_value( &self, name: impl CStrLike, ) -> Result<Option<String>, Error>

Retrieves a RocksDB property by name.

Full list of properties could be find here.

Source

pub fn property_value_cf( &self, cf: &impl AsColumnFamilyRef, name: impl CStrLike, ) -> Result<Option<String>, Error>

Retrieves a RocksDB property by name, for a specific column family.

Full list of properties could be find here.

Source

pub fn property_int_value( &self, name: impl CStrLike, ) -> Result<Option<u64>, Error>

Retrieves a RocksDB property and casts it to an integer.

Full list of properties that return int values could be find here.

Source

pub fn property_int_value_cf( &self, cf: &impl AsColumnFamilyRef, name: impl CStrLike, ) -> Result<Option<u64>, Error>

Retrieves a RocksDB property for a specific column family and casts it to an integer.

Full list of properties that return int values could be find here.

Source

pub fn latest_sequence_number(&self) -> u64

The sequence number of the most recent transaction.

Source

pub fn get_approximate_sizes( &self, ranges: &[Range<'_>], ) -> Result<Vec<u64>, Error>

Return the approximate file system space used by keys in each ranges.

Note that the returned sizes measure file system space usage, so if the user data compresses by a factor of ten, the returned sizes will be one-tenth the size of the corresponding user data size.

Due to lack of abi, only data flushed to disk is taken into account.

§Errors

Returns the RocksDB error if the size estimate fails, for instance on an I/O error reading the manifest. No partial sizes are reported in that case.

Source

pub fn get_approximate_sizes_cf( &self, cf: &impl AsColumnFamilyRef, ranges: &[Range<'_>], ) -> Result<Vec<u64>, Error>

Like Self::get_approximate_sizes, for a single column family.

§Errors

See Self::get_approximate_sizes.

Source

pub fn get_approximate_sizes_with_options( &self, opts: &SizeApproximationOptions, ranges: &[Range<'_>], ) -> Result<Vec<u64>, Error>

Like Self::get_approximate_sizes, but lets the caller say what counts towards the total and how precise the answer has to be.

Self::get_approximate_sizes counts SST files only. Pass a SizeApproximationOptions with set_include_memtables on to include writes that have not been flushed yet.

§Errors

See Self::get_approximate_sizes.

Source

pub fn get_approximate_sizes_cf_with_options( &self, cf: &impl AsColumnFamilyRef, opts: &SizeApproximationOptions, ranges: &[Range<'_>], ) -> Result<Vec<u64>, Error>

Like Self::get_approximate_sizes_with_options, for a single column family.

§Errors

See Self::get_approximate_sizes.

Source

pub fn get_approximate_sizes_cf_with_flags( &self, cf: &impl AsColumnFamilyRef, flags: SizeApproximationFlags, ranges: &[Range<'_>], ) -> Result<Vec<u64>, Error>

Like Self::get_approximate_sizes_cf_with_options, but selects what counts with a flag set instead of an options object.

Prefer Self::get_approximate_sizes_cf_with_options, which can also set an error margin. This variant exists because it is the form RocksDB offers without allocating.

§Errors

See Self::get_approximate_sizes.

Source

pub fn get_updates_since(&self, seq_number: u64) -> Result<DBWALIterator, Error>

Iterate over batches of write operations since a given sequence.

Produce an iterator that will provide the batches of write operations that have occurred since the given sequence (see latest_sequence_number()). Use the provided iterator to retrieve each (u64, WriteBatch) tuple, and then gather the individual puts and deletes using the WriteBatch::iterate() function.

Calling get_updates_since() with a sequence number that is out of bounds will return an error.

Source

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

Tries to catch up with the primary by reading as much as possible from the log files.

Source

pub fn ingest_external_file<P: AsRef<Path>>( &self, paths: Vec<P>, ) -> Result<(), Error>

Loads a list of external SST files created with SstFileWriter into the DB with default opts

Source

pub fn ingest_external_file_opts<P: AsRef<Path>>( &self, opts: &IngestExternalFileOptions, paths: Vec<P>, ) -> Result<(), Error>

Loads a list of external SST files created with SstFileWriter into the DB

Source

pub fn ingest_external_file_cf<P: AsRef<Path>>( &self, cf: &impl AsColumnFamilyRef, paths: Vec<P>, ) -> Result<(), Error>

Loads a list of external SST files created with SstFileWriter into the DB for given Column Family with default opts

Source

pub fn ingest_external_file_cf_opts<P: AsRef<Path>>( &self, cf: &impl AsColumnFamilyRef, opts: &IngestExternalFileOptions, paths: Vec<P>, ) -> Result<(), Error>

Loads a list of external SST files created with SstFileWriter into the DB for given Column Family

Source

pub fn get_column_family_metadata(&self) -> ColumnFamilyMetaData

Obtains the LSM-tree meta data of the default column family of the DB

Source

pub fn get_column_family_metadata_cf( &self, cf: &impl AsColumnFamilyRef, ) -> ColumnFamilyMetaData

Obtains the LSM-tree meta data of the specified column family of the DB

Source

pub fn compact_files<I, N>( &self, opts: &CompactionOptions, input_file_names: I, output_level: i32, ) -> Result<CompactFilesResult, Error>
where I: IntoIterator<Item = N>, N: CStrLike,

Compacts the named SST files into output_level, giving the caller control over exactly which files are merged.

Self::compact_range picks the files itself from a key range. This picks them by name, which is what a tool driving compaction from Self::live_files or Self::get_column_family_metadata_with_options needs. The file names come from that metadata, not from the filesystem.

Runs on the calling thread, so it blocks until the compaction finishes.

§Errors

Returns the RocksDB error if any input file is unknown, if the files do not form a compactible set, or if the compaction itself fails. Nothing is compacted in that case.

Source

pub fn compact_files_cf<I, N>( &self, cf: &impl AsColumnFamilyRef, opts: &CompactionOptions, input_file_names: I, output_level: i32, ) -> Result<CompactFilesResult, Error>
where I: IntoIterator<Item = N>, N: CStrLike,

Like Self::compact_files, for a single column family.

§Errors

See Self::compact_files.

Source

pub fn get_column_family_metadata_with_options( &self, opts: &ColumnFamilyMetaDataOptions, ) -> Vec<LevelMetaData>

Obtains the LSM-tree meta data of the default column family, reporting only the levels and files opts selects.

Unlike Self::get_column_family_metadata, which returns only the totals, this reports every level and every SST file in it.

Source

pub fn get_column_family_metadata_cf_with_options( &self, cf: &impl AsColumnFamilyRef, opts: &ColumnFamilyMetaDataOptions, ) -> Vec<LevelMetaData>

Like Self::get_column_family_metadata_with_options, for a single column family.

Source

pub fn get_livefiles_storage_info( &self, opts: &LiveFilesStorageInfoOptions, ) -> Result<LiveFilesStorageInfo, Error>

Returns every file RocksDB needs in order to restore this DB, which is what a copy-based backup has to capture.

This covers more than Self::live_files does: alongside the SST files it reports the WAL, manifest, options and CURRENT files, each with the size and, when opts asks for it, the checksum needed to verify a copy.

§Errors

Returns the RocksDB error if the file list cannot be gathered, for instance when a flush it needs to run fails.

Source

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

Returns every WAL file the DB currently knows about, oldest first, including the one being written to.

§Errors

Returns the RocksDB error if the WAL directory cannot be listed.

Source

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

Returns the WAL file currently being written to.

Reported as alive, with its size read from the filesystem, and with a start_sequence of 0 rather than a real sequence number.

§Errors

Returns the RocksDB error if the current WAL file cannot be identified.

Source

pub fn start_trace<P: AsRef<Path>>( &self, opts: &TraceOptions, trace_path: P, ) -> Result<(), Error>

Starts recording every read and write to a trace file at trace_path, which Self::new_default_replayer can later replay against a DB.

The trace file is written through the DB’s own Env with default file options, so it is not rate limited.

Call Self::end_trace to stop.

Starting a second trace without ending the first does not fail. StartTrace installs the new tracer unconditionally, and the old one is dropped without its buffered records being written, so the first trace file is left truncated. Unlike Self::start_io_trace and Self::start_block_cache_trace, which report Busy, this one is the caller’s to get right.

§Errors

Returns the RocksDB error if the trace file cannot be created.

Source

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

Stops the trace started by Self::start_trace and closes the file.

§Errors

Returns the RocksDB error if no trace is running or the file cannot be closed cleanly.

Source

pub fn start_io_trace<P: AsRef<Path>>( &self, opts: &TraceOptions, trace_path: P, ) -> Result<(), Error>

Starts recording file system operations to a trace file at trace_path, for diagnosing IO behaviour rather than replaying queries.

Written the same way as Self::start_trace. Call Self::end_io_trace to stop.

§Errors

Returns the RocksDB error if the trace file cannot be created, or Busy if an IO trace is already running.

Source

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

Stops the IO trace started by Self::start_io_trace.

Does nothing if no IO trace is running.

§Errors

EndIOTrace always reports success, so this only fails if a future RocksDB gives it something to report. It returns a Result to keep that a non-breaking change.

Source

pub fn start_block_cache_trace<P: AsRef<Path>>( &self, opts: &BlockCacheTraceOptions, writer_opts: &BlockCacheTraceWriterOptions, trace_path: P, ) -> Result<(), Error>

Starts recording block cache accesses to a trace file at trace_path, which the block_cache_trace_analyzer tool can then simulate cache configurations against.

Written the same way as Self::start_trace. Call Self::end_block_cache_trace to stop.

§Errors

Returns the RocksDB error if the trace file cannot be created, or Busy if a block cache trace is already running.

Source

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

Stops the block cache trace started by Self::start_block_cache_trace.

Does nothing if no block cache trace is running.

§Errors

EndBlockCacheTrace always reports success, so this only fails if a future RocksDB gives it something to report. It returns a Result to keep that a non-breaking change.

Source

pub fn new_default_replayer<'cf, W, I, P>( &self, column_families: I, trace_path: P, ) -> Result<Replayer<'_>, Error>
where W: AsColumnFamilyRef + 'cf, I: IntoIterator<Item = &'cf W>, P: AsRef<Path>,

Builds a replayer that replays the trace at trace_path against this DB.

column_families must name every column family other than the default that the trace touched, or replay fails with Corruption: Invalid Column Family ID.. The default column family is always included, so an empty list replays it alone.

§Errors

Returns the RocksDB error if the trace file cannot be opened or read.

Source

pub fn live_files(&self) -> Result<Vec<LiveFile>, Error>

Returns a list of all table files with their level, start key and end key

Source

pub fn delete_file_in_range<K: AsRef<[u8]>>( &self, from: K, to: K, ) -> Result<(), Error>

Delete sst files whose keys are entirely in the given range.

Could leave some keys in the range which are in files which are not entirely in the range.

Note: L0 files are left regardless of whether they’re in the range.

SnapshotWithThreadModes before the delete might not see the data in the given range.

Source

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

Same as delete_file_in_range but only for specific column family

Source

pub fn cancel_all_background_work(&self, wait: bool)

Request stopping background work, if wait is true wait until it’s done.

Source

pub fn increase_full_history_ts_low<S: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, ts: S, ) -> Result<(), Error>

Increase the full_history_ts of column family. The new ts_low value should be newer than current full_history_ts value. If another thread updates full_history_ts_low concurrently to a higher timestamp than the requested ts_low, a try again error will be returned.

Source

pub fn get_full_history_ts_low( &self, cf: &impl AsColumnFamilyRef, ) -> Result<Vec<u8>, Error>

Get current full_history_ts value.

Source

pub fn get_db_identity(&self) -> Result<Vec<u8>, Error>

Returns the DB identity. This is typically ASCII bytes, but that is not guaranteed.

Source§

impl<I: DBInner> DBCommon<SingleThreaded, I>

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 create_cf_with_ttl<N: AsRef<str>>( &mut self, name: N, opts: &Options, ttl: ColumnFamilyTtl, ) -> Result<(), Error>

Creates a column family whose entries expire after ttl, on a DB that was opened with a TTL.

ColumnFamilyDescriptor::new_with_ttl sets this at open time. This is the way to add such a family to a DB that is already open.

§Errors

Errors if the DB was not opened with DB::open_with_ttl or one of the open_cf*_with_ttl functions, since RocksDB would otherwise treat the handle as a type it is not. Also returns the RocksDB error if the family already exists or cannot be created, and errors if the name contains an interior NUL byte.

Source

pub fn create_cfs<Iter, N>( &mut self, names: Iter, opts: &Options, ) -> Result<(), Error>
where Iter: IntoIterator<Item = N>, N: AsRef<str>,

Creates the named column families, all sharing opts.

This saves one options file write over calling create_cf in a loop. It is not a saving on manifest writes, and it is not atomic.

§Errors

Returns the RocksDB error if a family already exists or cannot be created, and errors if a name contains an interior NUL byte.

RocksDB creates the families in order and stops at the first failure, so on error the families named before the failing one already exist and stay that way. Those are recorded here as usual and can be used or dropped, so retrying with the same list will fail again on the ones that now exist.

Source

pub fn create_column_family_with_import<N: AsRef<str>>( &mut self, options: &Options, column_family_name: N, import_options: &ImportColumnFamilyOptions, metadata: &ExportImportFilesMetaData, ) -> Result<(), Error>

Creates a new column family by importing a collection of SST files

Column family SST files can be created in one of the following ways:

  1. Directly using SstFileWriter.
  2. Exported from an existing DB using Checkpoint::export_column_family. In that case, metadata should be the output of export_column_family.

The parameter import_options can specify whether to copy or move the external files (default is to copy). If set to copy, managing the source files is the caller’s responsibility. When set to move, the operation will attempt to delete the external files on successful import, logging any failure to delete rather than returning an error. Files are not modified on any error, and a best effort is made to remove any newly-created files. A new Column Family will be present on a successful return, and will not be present on error. A Column Family may be present if a crash occurs during a call.

§Examples
use rust_rocksdb::{ExportImportFilesMetaData, ImportColumnFamilyOptions, Options, DB};

fn import_column_family(
    db: &mut DB,
    column_family_name: &str,
    import_metadata: &ExportImportFilesMetaData,
) {
    let cf_opts = Options::default();

    let mut import_opts = ImportColumnFamilyOptions::default();
    import_opts.set_move_files(true);

    db.create_column_family_with_import(
        &cf_opts,
        column_family_name,
        &import_opts,
        &import_metadata,
    )
        .unwrap();
}
Source

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

Drops the column family with the given name

Source

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

Returns the underlying column family handle

Source

pub fn cf_names(&self) -> Vec<String>

Returns the list of column families currently open.

The order of names is unspecified and may vary between calls.

Source§

impl<I: DBInner> DBCommon<MultiThreaded, I>

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 create_cf_with_ttl<N: AsRef<str>>( &self, name: N, opts: &Options, ttl: ColumnFamilyTtl, ) -> Result<(), Error>

Creates a column family whose entries expire after ttl, on a DB that was opened with a TTL.

ColumnFamilyDescriptor::new_with_ttl sets this at open time. This is the way to add such a family to a DB that is already open.

§Errors

Errors if the DB was not opened with DB::open_with_ttl or one of the open_cf*_with_ttl functions, since RocksDB would otherwise treat the handle as a type it is not. Also returns the RocksDB error if the family already exists or cannot be created, and errors if the name contains an interior NUL byte.

Source

pub fn create_cfs<Iter, N>( &self, names: Iter, opts: &Options, ) -> Result<(), Error>
where Iter: IntoIterator<Item = N>, N: AsRef<str>,

Creates the named column families, all sharing opts.

See DBCommon::create_cfs(DBCommon::<SingleThreaded, I>::create_cfs), including the note that this is not atomic.

§Errors

Returns the RocksDB error if a family already exists or cannot be created, and errors if a name contains an interior NUL byte. On error the families named before the failing one already exist and are recorded here.

Source

pub fn create_column_family_with_import<N: AsRef<str>>( &self, options: &Options, column_family_name: N, import_options: &ImportColumnFamilyOptions, metadata: &ExportImportFilesMetaData, ) -> Result<(), Error>

Creates a new column family by importing a collection of SST files

Column family SST files can be created in one of the following ways:

  1. Directly using SstFileWriter.
  2. Exported from an existing DB using Checkpoint::export_column_family. In that case, metadata should be the output of export_column_family.

The parameter import_options can specify whether to copy or move the external files (default is to copy). If set to copy, managing the source files is the caller’s responsibility. When set to move, the operation will attempt to delete the external files on successful import, logging any failure to delete rather than returning an error. Files are not modified on any error, and a best effort is made to remove any newly-created files. A new Column Family will be present on a successful return, and will not be present on error. A Column Family may be present if a crash occurs during a call.

§Examples
use rust_rocksdb::{ExportImportFilesMetaData, ImportColumnFamilyOptions, Options, DB};

fn import_column_family(
    db: &mut DB,
    column_family_name: &str,
    import_metadata: &ExportImportFilesMetaData,
) {
    let cf_opts = Options::default();

    let mut import_opts = ImportColumnFamilyOptions::default();
    import_opts.set_move_files(true);

    db.create_column_family_with_import(
        &cf_opts,
        column_family_name,
        &import_opts,
        &import_metadata,
    )
        .unwrap();
}
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

Source

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

Returns the underlying column family handle

Source

pub fn cf_names(&self) -> Vec<String>

Returns the list of column families currently open.

The order of names is unspecified and may vary between calls.

Source§

impl<T: ThreadMode> DBCommon<T, OptimisticTransactionDBInner>

Methods of OptimisticTransactionDB.

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, path: P) -> Result<Self, Error>

Opens the database with the specified options.

Source

pub fn open_cf<P, I, N>(opts: &Options, 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. NOTE: default column family will be opened with the Options::default(). If you want to open default column family with custom options, use open_cf_descriptors and provide a ColumnFamilyDescriptor with the desired options.

Source

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

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

Source

pub fn open_with_otxn_db_options<P: AsRef<Path>>( opts: &Options, otxn_db_opts: &OptimisticTransactionDBOptions, path: P, ) -> Result<Self, Error>

Opens the database with the specified database and conflict validation options.

Same as open, plus control over how commits are validated. See OptimisticTransactionDBOptions.

Source

pub fn open_cf_with_otxn_db_options<P, I, N>( opts: &Options, otxn_db_opts: &OptimisticTransactionDBOptions, 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 and conflict validation options and column family names.

Same as open_cf, plus control over how commits are validated. Column families opened this way are created with default Options, including default.

Source

pub fn open_cf_descriptors_with_otxn_db_options<P, I>( opts: &Options, otxn_db_opts: &OptimisticTransactionDBOptions, path: P, cfs: I, ) -> Result<Self, Error>

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

Same as open_cf_descriptors, plus control over how commits are validated.

Source

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

Creates a transaction with default options.

Source

pub fn transaction_opt( &self, writeopts: &WriteOptions, otxn_opts: &OptimisticTransactionOptions, ) -> Transaction<'_, Self>

Creates a transaction with default options.

Source

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

Source

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

Source

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

Source

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

Removes the database entries in the range ["from", "to") using given write options.

Source

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

Removes the database entries in the range ["from", "to") using default write options.

Trait Implementations§

Source§

impl<T: ThreadMode, D: DBInner> DBAccess for DBCommon<T, D>

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, Iter>( &self, keys: Iter, readopts: &ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, Iter: IntoIterator<Item = K>,

Source§

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

Source§

impl<T: ThreadMode, I: DBInner> Debug for DBCommon<T, I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ThreadMode, I: DBInner> Drop for DBCommon<T, I>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: ThreadMode + Send, I: DBInner> Send for DBCommon<T, I>

Source§

impl<T: ThreadMode, I: DBInner> Sync for DBCommon<T, I>

Auto Trait Implementations§

§

impl<T, D> !RefUnwindSafe for DBCommon<T, D>

§

impl<T, D> !UnwindSafe for DBCommon<T, D>

§

impl<T, D> Freeze for DBCommon<T, D>
where D: Freeze, T: Freeze,

§

impl<T, D> Unpin for DBCommon<T, D>
where D: Unpin, T: Unpin,

§

impl<T, D> UnsafeUnpin for DBCommon<T, D>
where D: UnsafeUnpin, T: UnsafeUnpin,

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.