Remote compaction thread count - #15172
Conversation
Differential Revision: D118323642
|
@rban1 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D118323642. |
✅ clang-tidy: No findings on changed linesCompleted in 380.3s. |
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 10d6a12 SummarySolid approach to allowing remote-compaction-waiting threads to not consume compaction slots. The core mechanism (callback + counter + scheduling adjustment) is sound and the test is well-designed. A few consistency and style issues to address. High-severity findings (1):
Full review (click to expand)Findings🔴 HIGHH1.
|
| Context | Does code execute? | Assumptions hold? | Action needed? |
|---|---|---|---|
| CompactionServiceCompactionJob (remote worker) | NO -- callback defaults to empty | YES | Safe |
| CompactFilesImpl | YES -- callback passed | YES | Correct |
| BackgroundCompaction | YES -- callback passed (per diff) | YES, but diff shows old code in repo | Verify diff applied |
| Bottom-priority compactions | YES -- same CompactionJob constructor | Callback passed in bottom-pri path | Correct |
| DB shutdown | YES -- callback fires before bg_compaction_scheduled_-- | YES -- Defer fires before BackgroundCallCompaction cleanup | Safe |
| Compaction abort | Callback fires during Wait() | Defer handles cleanup | Safe |
| AcquireSubcompactionResources | YES | NO -- formula inconsistent | H1 |
| CaptureBackgroundJobPressure | YES | Partial -- reports raw counts | M1 |
Bottom-priority compaction analysis: The diff updates the BackgroundCompaction call site at line 5063, which handles both LOW and BOTTOM priority compactions (bottom-pri goes through the BGWorkBottomCompaction -> BackgroundCallCompaction -> BackgroundCompaction path, which uses the same CompactionJob constructor at line 5049). Per the diff, the callback is passed. The bg_remote_compaction_waiting_ subtraction covers both LOW and BOTTOM scheduled counts, so bottom-pri remote compactions will correctly free a slot. However, the counter tracks "waiting" globally without distinguishing priority -- this is correct since the scheduling check also uses the combined count.
Subcompaction analysis: Only the primary subcompaction fires the callback. This is correct: a CompactionJob occupies one bg_compaction_scheduled_ slot (with optional extra slots from AcquireSubcompactionResources). Each subcompaction calls ProcessKeyValueCompactionWithCompactionService independently, but they share the same CompactionJob and its single slot. Freeing one slot when the primary enters Wait() is the right granularity.
Lifecycle analysis: The callback [this](bool waiting) { OnRemoteCompactionWaitStateChanged(waiting); } captures this (DBImpl*). The CompactionJob is stack-allocated inside BackgroundCompaction/CompactFilesImpl, and the Defer fires before the function returns. BackgroundCallCompaction decrements bg_compaction_scheduled_ after the compaction job completes, so DBImpl is still alive when the callback fires.
Positive Observations
- The "primary subcompaction" check (
sub_compact == compact_->sub_compact_states.data()) is a clean, zero-overhead way to identify the first subcompaction without adding bookkeeping. - Using
Deferfor the cleanup ensures the counter is balanced even ifWait()throws or returns early. - The test design (2 CFs,
max_background_compactions=1, blocking service) cleanly validates the core feature. - The assert
bg_remote_compaction_waiting_ <= bg_compaction_scheduled_ + bg_bottom_compaction_scheduled_is a good safety net for debug builds.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
Differential Revision: D118323642