Log-Structured Merge Trees and Compaction

Follow updates from an in-memory structure to sorted files and account for why merging versions can amplify writes.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Change fast state first and flush sorted runs later
  2. Compaction trades maintenance work for simpler reads

Change fast state first and flush sorted runs later

An LSM-style engine records a new value in a mutable memory structure, typically protected by a log. A flush creates an immutable sorted run. A read may have to check several runs, preferring the appropriate visible version. A deletion marker can suppress an older value even though that older value still occupies storage. Compaction merges runs and can remove versions no active snapshot or lower layer needs.

Compaction trades maintenance work for simpler reads

Merging overlapping sets of ranges can rewrite data more than once as runs move through levels. Policies differ in space, read and write amplification. Skipping compaction indefinitely can leave more candidates to check per request. Bloom filters avoid some negative probes. Sorted-table block lookup locates an entry within a run, and version cleanup governs when an obsolete record is safe to discard.[1][2]

References

  1. Patrick O’Neil et al., The Log-Structured Merge-Tree ↩
  2. CMU 15-445/645, Introduction to Database Systems: Lectures ↩