Skip to main content

CompactionServiceOptionsOverride

Struct CompactionServiceOptionsOverride 

Source
pub struct CompactionServiceOptionsOverride { /* private fields */ }
Expand description

How the worker should open the column family it is about to compact.

A serialized compaction job carries the work but not the column family’s configuration, and RocksDB cannot serialize a comparator, a merge operator, or a prefix extractor. Whatever the primary DB was opened with has to be rebuilt here, or the worker produces output the primary cannot use.

from_options is the shortcut when the worker can build the same Options the primary uses. create starts from RocksDB defaults instead.

Every setter here replaces the previous value and none of them can be unset. The C API ignores a null argument rather than clearing the field (c.cc:1412 and the setters below it).

Implementations§

Source§

impl CompactionServiceOptionsOverride

Source

pub fn create() -> Self

Starts from RocksDB’s defaults: the default Env, the bytewise comparator, a block-based table factory with default settings, no merge operator, and no prefix extractor.

The table factory is set here rather than left alone on purpose. The C struct leaves it null, and the worker copies every override field over the column family’s own options unconditionally (db/db_impl/db_impl_secondary.cc:1396), then dereferences the table factory without a null check (db/column_family.cc:415). Handing a freshly created override straight to open_and_compact would therefore crash the worker, so this fills in the same default a plain Options carries.

Source

pub fn from_options(options: &Options) -> Self

Copies the overridable settings out of options.

Thirteen fields are taken (c.cc:1381 to c.cc:1397): the env, file checksum generator factory, comparator, merge operator, compaction filter, compaction filter factory, prefix extractor, table factory, SST partitioner factory, event listeners, statistics, info log, and table properties collector factories. Anything else the worker needs has to go through set_option.

Three of those are bare pointers rather than shared_ptrs, so this keeps a handle on whatever options is holding them alive with, and the override stays valid after options is dropped.

Source

pub fn set_env(&mut self, env: &Env)

Sets the environment the worker reads and writes files through.

The C API stores a bare Env* (c.cc:1413), so this keeps a handle on env for as long as the override lives.

Source

pub fn set_comparator(&mut self, comparator: Arc<Comparator>)

Sets the key ordering, which must be the one the primary DB uses.

The C API stores a bare const Comparator* (c.cc:1421), so this takes an Arc and holds a clone rather than borrowing. Sharing a comparator is the normal case anyway, since the same one usually goes into the worker’s own Options.

Source

pub fn set_merge_operator<F: MergeFn, PF: MergeFn>( &mut self, name: impl CStrLike, full_merge_fn: F, partial_merge_fn: PF, ) -> Result<(), Error>

Sets the merge operator, which must be the one the primary DB uses.

Builds the operator here instead of taking a prepared one, because the C API adopts the pointer into a std::shared_ptr<MergeOperator> (c.cc:1429) and RocksDB frees it from then on. Handing the same pointer to two of these would build two control blocks and free it twice, which cannot happen when the only pointer is made on the spot.

The two callbacks mean what they do on Options::set_merge_operator.

§Errors

Returns an error if name contains an interior NUL byte.

Source

pub fn set_compaction_filter<F>( &mut self, name: impl CStrLike, filter_fn: F, ) -> Result<(), Error>
where F: CompactionFilterFn + Send + 'static,

Drops or rewrites entries as the worker compacts them, the way Options::set_compaction_filter does on the primary.

The C API stores a bare const CompactionFilter* (c.cc:1438) instead of adopting it, so the filter is built here and held for as long as the override lives. Setting a second one destroys the first, after the C struct has stopped pointing at it.

A filter set here wins over one from set_compaction_filter_factory. RocksDB only asks the factory when this field is null (compaction_job.cc:1452).

§Errors

Returns an error if name contains an interior NUL byte.

Source

pub fn set_compaction_filter_factory<F>(&mut self, factory: F)
where F: CompactionFilterFactory + 'static,

Builds a fresh compaction filter for each compaction the worker runs.

Takes the factory by value because the C API adopts the pointer into a std::shared_ptr<CompactionFilterFactory> (c.cc:1446), which makes RocksDB responsible for freeing it.

Ignored while a filter set by set_compaction_filter is in place.

Source

pub fn set_prefix_extractor(&mut self, prefix_extractor: SliceTransform)

Sets the prefix extractor, which must be the one the primary DB uses.

Takes the transform by value because the C API adopts the pointer into a std::shared_ptr<const SliceTransform> (c.cc:1455), which makes RocksDB responsible for freeing it.

Source

pub fn set_block_based_table_factory( &mut self, table_options: &BlockBasedOptions, )

Writes output with a block based table factory built from table_options.

The C API reads the options and builds a fresh factory from them (c.cc:1464), so table_options is free to drop as soon as this returns. A block cache set on it is carried into the factory by shared_ptr.

Source

pub fn set_cuckoo_table_factory(&mut self, table_options: &CuckooTableOptions)

Writes output with a cuckoo table factory built from table_options.

Replaces any factory set by set_block_based_table_factory, since both write the same field. The C API builds a fresh factory from the options (c.cc:1473), so table_options is free to drop as soon as this returns.

Source

pub fn set_sst_partitioner_factory(&mut self, factory: &SstPartitionerFactory)

Cuts output SST files on the boundaries this factory reports.

The C API copies the underlying shared_ptr (c.cc:1517), so the caller’s handle is free to drop at any time.

Source

pub fn set_file_checksum_gen_factory( &mut self, factory: &FileChecksumGenFactory, )

Records a whole file checksum for each SST the worker writes.

The C API copies the underlying shared_ptr (c.cc:1509), so the caller’s handle is free to drop at any time.

Source

pub fn set_statistics(&mut self, options: &Options)

Collects statistics for the compaction into the statistics object options carries.

The C API reaches into an Options for its statistics and copies the shared_ptr (c.cc:1485), so this takes an Options rather than a statistics handle. Call Options::enable_statistics on it first, otherwise there is nothing to copy and this does nothing.

Upstream notes on CompactionServiceOptionsOverride that these counters stay on the worker. Nothing is sent back to the primary DB.

Source

pub fn set_info_log(&mut self, logger: InfoLogger)

Sends the worker’s log lines to logger instead of the default log file.

Takes the logger by value, the same as Options::set_info_logger, because a callback logger owns the Rust closure it calls and the C API only copies the C++ side of it (c.cc:1493).

Source

pub fn set_option( &mut self, name: impl CStrLike, value: impl CStrLike, ) -> Result<(), Error>

Sets one option by its name in the options string format.

The escape hatch for everything without a setter of its own, such as compression or max_subcompactions. Names and values are the ones RocksDB’s options string parser takes, for example "compression" and "kZSTD". Both are copied into the override (c.cc:1501).

Upstream ignores a name it does not recognise rather than reporting it, so a typo here is silent.

§Errors

Returns an error if name or value contains an interior NUL byte.

Trait Implementations§

Source§

impl Default for CompactionServiceOptionsOverride

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for CompactionServiceOptionsOverride

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 Send for CompactionServiceOptionsOverride

Source§

impl Sync for CompactionServiceOptionsOverride

Auto Trait Implementations§

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.