Skip to main content

CompactionFilter

Trait CompactionFilter 

Source
pub trait CompactionFilter:
    Send
    + Sync
    + 'static {
    // Required methods
    fn filter(
        &self,
        level: usize,
        key: &[u8],
        value: &[u8],
    ) -> CompactionDecision;
    fn name(&self) -> &'static str;

    // Provided method
    fn filter_range_delete(
        &self,
        level: usize,
        start: &[u8],
        end: &[u8],
    ) -> CompactionDecision { ... }
}
Expand description

A user-supplied hook that runs during compaction and can drop or rewrite entries in place. Typical uses: TTL expiration, application- level GC, schema migrations.

§Determinism

Implementations must be deterministic functions of (level, key, value) - the same input should always yield the same decision. They must not read from the database (would deadlock) and should avoid blocking.

§Snapshot isolation

Compaction filters currently run only when no live crate::Snapshot is pinned. This guarantees that every Snapshot taken before compaction still observes the pre-filter value until the snapshot is dropped. When a snapshot is alive, compaction still runs but skips the filter entirely. Finer-grained per-snapshot filtering is a planned follow-up.

Required Methods§

Source

fn filter(&self, level: usize, key: &[u8], value: &[u8]) -> CompactionDecision

Inspect a point entry. Called once per surviving (user_key, value) pair during compaction.

Source

fn name(&self) -> &'static str

A stable, human-readable identifier for this filter. Used by tracing and diagnostics.

Provided Methods§

Source

fn filter_range_delete( &self, level: usize, start: &[u8], end: &[u8], ) -> CompactionDecision

Inspect a range tombstone. Default implementation keeps every range tombstone. CompactionDecision::Change is treated as Keep for range tombstones (there’s no “value” to rewrite).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§