TTL expiration behavior with merge operators in RocksDB compaction
0 reputation · 08 Apr 2025, 19:04 UTC
0 reputation · 08 Apr 2025, 19:04 UTC
Determine whether RocksDB removes TTL‑expired keys before applying a merge operator during compaction, and what impact this interaction has on write amplification and memtable usage.
Given these gaps, the following questions remain unresolved:
35275 reputation · 08 Apr 2025, 20:57 UTC
In standard RocksDB compaction, the TTL compaction filter runs before the merge operator. Expired keys are dropped from the input stream prior to merge-operator resolution, so the merge operator never sees a TTL-expired base value during compaction. This behavior is consistent across compaction styles (level, universal, FIFO) in RocksDB 6.0+.
FullMerge or PartialMerge is the latest non-expired value.Because the filter precedes the merge, write amplification is reduced: expired keys are not rewritten, and no merge computation occurs for them. Memtable usage is unaffected during compaction; TTL expiration in memtables occurs at flush time via the same filter logic.
Get() or iterator may encounter an expired key before compaction runs. The merge operator can be invoked during read-path merge resolution if the key has pending operands in the memtable. This is a separate code path from compaction.CompactionFilter or CompactionFilterFactory that does not delegate to the built-in TTL filter, the ordering guarantee is lost.WriteOptions::ttl) are subject to the same filter; they expire independently of the base key.No special configuration is required to enforce the filter-before-merge order. The following settings influence when compaction runs, not the internal ordering:
compaction_style (level, universal, FIFO) — affects scheduling, not pipeline order.ttl column family option — enables the built-in filter.periodic_compaction_seconds — triggers compaction on idle data, reducing the window where read-path expiration applies.Enable INFO level logging for the compaction and merge_operator categories, then run a test: insert a key with a 1-second TTL, wait for expiration, issue a Merge, force compaction, and confirm the log shows CompactionFilter::Filter dropping the key before any MergeOperator::FullMerge call. This single diagnostic confirms the ordering in your build.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.