liveBook · Manning

Compaction

As explained in ScyllaDB in Action

Compaction is a storage-maintenance process that merges multiple immutable database files into fewer, more compact files while reconciling their contents.

Compaction is ScyllaDB’s storage-maintenance process for immutable SSTables. Updates and deletes leave older values or tombstones on disk; compaction merges SSTables into newer files, retaining the newest values and removing obsolete rows when safe. Fewer redundant files reduce the data reads must examine, helping read performance and controlling disk growth. section 6.2.3 section 8.4

Figure 6.6 Compaction combines multiple SSTables into a newer SSTable, skipping obsolete rows and eligible-for-deletion tombstones.
figure

The merge creates a replacement SSTable while skipping superseded rows and tombstones that are eligible for deletion. section 6.2.3

Deletes need extra care. A tombstone remains until gc_grace_seconds has elapsed so that nodes have time to learn about the deletion. Removing it too early can allow deleted data to reappear on a node that missed the tombstone; retaining it longer consumes space. Run repair within this period to synchronize tombstones. section 6.2.3 section 6.6

Compaction can run in two ways:

  • Minor compaction runs automatically against selected SSTables according to the table’s configured compaction strategy. section 6.2.3 section 8.4.1
  • Major compaction is requested with nodetool compact and compacts all SSTables for a table; use it cautiously because it consumes resources and can make later minor compactions less effective. section 9.3.3

A strategy determines which SSTables are grouped. Size-tiered compaction strategy (STCS), the default, groups similarly sized files and produces fewer, larger SSTables, but may require substantial temporary disk space. Leveled compaction strategy (LCS) organizes fixed-size SSTables into levels. Time-window compaction strategy (TWCS) groups time-series data by windows. section 8.4.1

Repeated profile updates

If an author’s bio is written, flushed, and updated several times, versions can be scattered across many SSTables. Reads must inspect those files to select the newest bio. Compaction merges the relevant files and removes the obsolete versions when the newer version participates in the merge. section 8.4.1

Monitor active work with nodetool compactionstats. It reports ongoing operations, affected keyspaces and tables, and the amount of data being compacted. A sustained backlog or heavy continuous compaction can contribute to slow cluster performance because resources spent compacting are unavailable for reads. section 9.3.3

How ScyllaDB in Action covers it

How deep it goes
Explains SSTable merging, tombstone timing, strategies, and operational monitoring, while deferring detailed strategy configuration.
Examples
Illustrates repeated author-bio updates scattered across SSTables and shows their consolidation into current data.
What you can do after
Diagnose/debug with nodetool compactionstats and evaluate major-compaction performance trade-offs.
How it connects
Connects compaction to SSTables, tombstones, gc_grace_seconds, repair, read performance, and compaction strategies.

Also explained in

Compare how 5 books explain compaction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.