pub trait CompactionFilter {
    // Required methods
    fn filter(&mut self, level: u32, key: &[u8], value: &[u8]) -> Decision;
    fn name(&self) -> &CStr;
}
Expand description

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

Required Methods§

source

fn filter(&mut self, level: u32, key: &[u8], value: &[u8]) -> Decision

The compaction process invokes this method for kv that is being compacted. The application can inspect the existing value of the key and make decision based on it.

Key-Values that are results of merge operation during compaction are not passed into this function. Currently, when you have a mix of Put()s and Merge()s on a same key, we only guarantee to process the merge operands through the compaction filters. Put()s might be processed, or might not.

When the value is to be preserved, the application has the option to modify the existing_value and pass it back through new_value. value_changed needs to be set to true in this case.

Note that RocksDB snapshots (i.e. call GetSnapshot() API on a DB* object) will not guarantee to preserve the state of the DB with CompactionFilter. Data seen from a snapshot might disappear after a compaction finishes. If you use snapshots, think twice about whether you want to use compaction filter and whether you are using it in a safe way.

If the CompactionFilter was created by a factory, then it will only ever be used by a single thread that is doing the compaction run, and this call does not need to be thread-safe. However, multiple filters may be in existence and operating concurrently.

source

fn name(&self) -> &CStr

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

Implementors§