pub trait CompactionStrategy: Send + Sync {
// Required methods
fn get_name(&self) -> &'static str;
fn choose(
&self,
version: &Version,
config: &Config,
state: &CompactionState,
) -> Choice;
// Provided methods
fn pending_compaction_bytes(&self, _version: &Version) -> u64 { ... }
fn next_merge_level(
&self,
version: &Version,
dest_level: u8,
) -> Option<usize> { ... }
}Expand description
Trait for a compaction strategy
The strategy receives the levels of the LSM-tree as argument and emits a choice on what to do.
Required Methods§
Sourcefn choose(
&self,
version: &Version,
config: &Config,
state: &CompactionState,
) -> Choice
fn choose( &self, version: &Version, config: &Config, state: &CompactionState, ) -> Choice
Decides on what to do based on the current state of the LSM-tree’s levels
This is the purely structural decision (level shape, run counts, size targets); it deliberately does not see the live runtime config. The orchestrator layers the runtime-config-driven housekeeping fallback on top (the density-based columnar rewrite).
Provided Methods§
Sourcefn pending_compaction_bytes(&self, _version: &Version) -> u64
fn pending_compaction_bytes(&self, _version: &Version) -> u64
Estimated bytes pending compaction: on-disk data currently sitting above
its level’s target size that must eventually be rewritten downward (a
RocksDB estimate-pending-compaction-bytes analog). A scheduler /
tiering consumer reads it as a compaction-debt signal; 0 means the tree
is at or below its target shape.
The default is 0 for strategies without a size-target notion of debt
(FIFO, major one-shot); the leveled strategy overrides it with
the per-level overflow sum.
Sourcefn next_merge_level(&self, version: &Version, dest_level: u8) -> Option<usize>
fn next_merge_level(&self, version: &Version, dest_level: u8) -> Option<usize>
The level a merge into dest_level writes outputs that are next merged
into, whose table boundaries they are cut on (see
Config::compaction_output_alignment); None cuts them at the target
size alone.
The default is the first level below the destination that holds tables: outputs move down through empty levels untouched and are next merged where tables are, as a leveled intra-L0 merge’s outputs are merged into the base level. A strategy whose outputs are next merged elsewhere, such as back into the level they were written to, overrides it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".