[][src]Trait rocks::compaction_filter::CompactionFilter

pub trait CompactionFilter {
    fn filter(
        &mut self,
        level: i32,
        key: &[u8],
        value_type: ValueType,
        existing_value: &[u8]
    ) -> Decision { ... }
fn ignore_snapshots(&self) -> bool { ... }
fn name(&self) -> &str { ... } }

CompactionFilter allows an application to modify/delete a key-value at the time of compaction.

Provided methods

fn filter(
    &mut self,
    level: i32,
    key: &[u8],
    value_type: ValueType,
    existing_value: &[u8]
) -> Decision

An extended API. Called for both values and merge operands. Allows changing value and skipping ranges of keys. The default implementation uses Filter() and FilterMergeOperand(). If you're overriding this method, no need to override the other two. value_type indicates whether this key-value corresponds to a normal value (e.g. written with Put()) or a merge operand (written with Merge()).

Possible return values:

  • kKeep - keep the key-value pair.

  • kRemove - remove the key-value pair or merge operand.

  • kChangeValue - keep the key and change the value/operand to *new_value.

  • kRemoveAndSkipUntil - remove this key-value pair, and also remove all key-value pairs with key in [key, *skip_until). This range of keys will be skipped without reading, potentially saving some IO operations compared to removing the keys one by one.

    *skip_until <= key is treated the same as Decision::kKeep (since the range [key, *skip_until) is empty).

    The keys are skipped even if there are snapshots containing them, as if IgnoreSnapshots() was true; i.e. values removed by kRemoveAndSkipUntil can disappear from a snapshot - beware if you're using TransactionDB or DB::GetSnapshot().

    Another warning: if value for a key was overwritten or merged into (multiple Put()s or Merge()s), and compaction filter skips this key with kRemoveAndSkipUntil, it's possible that it will remove only the new value, exposing the old value that was supposed to be overwritten.

    If you use kRemoveAndSkipUntil, consider also reducing compaction_readahead_size option.

Note: If you are using a TransactionDB, it is not recommended to filter out or modify merge operands (ValueType::kMergeOperand). If a merge operation is filtered out, TransactionDB may not realize there is a write conflict and may allow a Transaction to Commit that should have failed. Instead, it is better to implement any Merge filtering inside the MergeOperator.

Rust: Decision for detailed return type.

fn ignore_snapshots(&self) -> bool

This function is deprecated. Snapshots will always be ignored for compaction filters, because we realized that not ignoring snapshots doesn't provide the gurantee we initially thought it would provide. Repeatable reads will not be guaranteed anyway. If you override the function and returns false, we will fail the compaction.

fn name(&self) -> &str

Returns a name that identifies this compaction filter. The name will be printed to LOG file on start up for diagnosis.

Loading content...

Implementors

Loading content...