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§
Provided Methods§
Sourcefn filter_range_delete(
&self,
level: usize,
start: &[u8],
end: &[u8],
) -> CompactionDecision
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".