Compaction¶
Level-based compaction with subprocess merging.
CompactionManager¶
CompactionManager(sst, config, data_root)
¶
Flush-triggered compaction with level-reservation scheduling.
Initialize the compaction manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sst
|
SSTableManager
|
SSTable manager providing level state and commit API. |
required |
config
|
LSMConfig
|
Live engine configuration for thresholds and modes. |
required |
data_root
|
Path
|
Root data directory, used for compaction log and output SSTable paths. |
required |
Source code in app/engine/compaction_manager.py
active_jobs
property
¶
Currently running compaction jobs.
check_and_compact()
async
¶
Entry point. Called after every flush commit and after each completed compaction job.
Source code in app/engine/compaction_manager.py
CompactionTask¶
CompactionTask(task_id, input_file_ids, input_dirs, output_file_id, output_dir, output_level, seq_cutoff, bloom_fpr=0.01)
dataclass
¶
Immutable description of one compaction job.
All fields are primitive types so the task can be safely passed
across the ProcessPoolExecutor subprocess boundary.
Attributes:
| Name | Type | Description |
|---|---|---|
task_id |
str
|
Unique identifier for this compaction run. |
input_file_ids |
list[FileID]
|
SSTable file IDs to merge (includes source and destination level files). |
input_dirs |
dict[FileID, str]
|
Mapping from file ID to its on-disk directory path. |
output_file_id |
FileID
|
File ID for the newly created merged SSTable. |
output_dir |
str
|
Directory where the output SSTable will be written. |
output_level |
Level
|
Target compaction level for the output. |
seq_cutoff |
SeqNum
|
Tombstones with |
bloom_fpr |
float
|
Target false positive rate for the output bloom filter. |
run_compaction¶
run_compaction(task)
¶
Merge all input SSTables into one output SSTable.
Called in a subprocess — no event loop, no registry, no cache.
Opens its own file handles via _open_reader_sync().
Uses finish_sync() because blocking is fine in a subprocess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
CompactionTask
|
Immutable description of the compaction job, including input file IDs, directories, output path, and GC cutoff. |
required |
Returns:
| Type | Description |
|---|---|
SSTableMeta
|
Metadata of the newly created merged SSTable. |