Skip to content

feat(storage): AdaptiveCompactionScheduler — EMA-driven I/O monitoring, impact prediction, and dynamic trigger adjustment (v1.7.0, #209) - #4234

Merged
makr-code merged 6 commits into
developfrom
copilot/adaptive-compaction-storage
Mar 15, 2026
Merged

makr-code merged 6 commits into
developfrom
copilot/adaptive-compaction-storage

Conversation

Copilot AI commented Mar 14, 2026 •

Copy link
Copy Markdown
Contributor

Implements roadmap item #209: machine-learning-inspired (EMA-based) adaptive compaction scheduling for the storage engine, targeting 20–30% reduction in compaction CPU overhead.

New: AdaptiveCompactionScheduler

include/storage/adaptive_compaction.h · src/storage/adaptive_compaction.cpp

Acceptance Criteria Mechanism
Monitor read/write patterns Atomic recordRead()/recordWrite() + background sampling thread → per-second rates → EMA smoothing (α configurable)
Predict compaction impact predictCompactionImpact(write_amp) → CompactionImpactPrediction (CPU overhead ∈ [0,1], duration estimate, is_urgent, is_low_impact)
Schedule during low-load isLowLoadPeriod() (EMA rates vs thresholds) + shouldTriggerCompaction(write_amp) combining WA urgency with low-load gate
Adjust triggers dynamically getAdaptedConfig() / applyAdaptedConfig(mgr) linearly interpolate tombstone threshold and GC interval from measured load pressure
AdaptiveCompactionScheduler sched;
sched.startSampling();

// hot path:
sched.recordWrite(batch_size);

// maintenance loop:
if (sched.shouldTriggerCompaction(cm.stats().writeAmplification())) {
    cm.compactAll();
}
sched.applyAdaptedConfig(cm);  // keeps thresholds in sync with load

Extended: CompactionManager

Added setConfig(const Config&) and getConfig() for live config updates. setConfig holds bg_mutex_ during the assignment to prevent a race with concurrent getConfig() reads, and restarts the background GC thread so the new interval takes effect immediately.

Tests · CI · Build

  • tests/test_adaptive_compaction.cpp — 30 focused tests in AdaptiveCompactionFocusedTests covering all 4 ACs including an integration test
  • tests/CMakeLists.txt — fixed post-merge corruption where the adaptive compaction and test_device_manager_focused blocks were interleaved (missing target_include_directories body, wrong if/else/endif nesting); both blocks restored to correct standalone structure
  • .github/workflows/adaptive-compaction-ci.yml — replaced inline cmake steps with configure-themis composite action; added librocksdb-dev to setup-cpp-build packages per CI conventions
  • cmake/CMakeLists.txt + cmake/ModularBuild.cmake — adaptive_compaction.cpp added to storage source lists

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Other:

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?
    • Falls JA: Research-Dateien in /docs/research/ angelegt?
    • Falls JA: Im Modul-README unter "Wissenschaftliche Grundlagen" verlinkt?
    • Falls JA: In /docs/research/implementation_influence/ eingetragen?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No new warnings introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>Adaptive Compaction</issue_title>
<issue_description>### Context

This issue implements the roadmap item 'Adaptive Compaction' for the storage domain. It is sourced from the consolidated roadmap under 🟡 Medium Priority — Near-term (v1.5.0 – v1.8.0) and targets milestone v1.7.0.

Primary detail section: Adaptive Compaction

Goal

Deliver the scoped changes for Adaptive Compaction in src/storage/ and complete the linked detail section in a release-ready state for v1.7.0.

Detailed Scope

Adaptive Compaction

Priority: Medium
Target Version: v1.7.0

Machine learning-based compaction scheduling.

Approach:

  • Monitor read/write patterns
  • Predict compaction impact
  • Schedule compactions during low-load periods
  • Adjust compaction triggers dynamically

Expected Improvement: 20-30% less compaction CPU overhead


Acceptance Criteria

  • Monitor read/write patterns
  • Predict compaction impact
  • Schedule compactions during low-load periods
  • Adjust compaction triggers dynamically

Relationships

References

  • src/ROADMAP.md
  • src/storage/FUTURE_ENHANCEMENTS.md#adaptive-compaction
  • Source key: roadmap:209:storage:v1.7.0:adaptive-compaction

Generated from the consolidated source roadmap. Keep the roadmap and issue in sync when scope changes.

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 14, 2026 15:57
)

- Add include/storage/adaptive_compaction.h: AdaptiveCompactionScheduler
  class with EMA-based I/O pattern monitoring, compaction impact prediction,
  low-load period detection, and dynamic trigger adjustment
- Add src/storage/adaptive_compaction.cpp: full production implementation
- Add CompactionManager::setConfig()/getConfig() to allow live config updates
- Add tests/test_adaptive_compaction.cpp: 30 focused tests covering all 4 ACs
- Add .github/workflows/adaptive-compaction-ci.yml: CI workflow
- Update cmake/CMakeLists.txt and cmake/ModularBuild.cmake to include new sources
- Update tests/CMakeLists.txt to register AdaptiveCompactionFocusedTests

Co-authored-by: makr-code <[email protected]>
- Remove spurious trigger_adjustments_ increment from collectSample()
  (should only count actual threshold adjustments in applyAdaptedConfig)
- Use chrono::seconds::rep instead of long for portable duration cast
- Hold bg_mutex_ during config_ assignment in setConfig() to prevent
  race condition with concurrent getConfig() reads
- Rename unused loop variables i -> n in integration test

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title [WIP] Implement adaptive compaction for storage domain feat(storage): AdaptiveCompactionScheduler — EMA-driven scheduling with dynamic trigger adjustment (v1.7.0) Mar 14, 2026
Copilot AI requested a review from makr-code March 14, 2026 16:01
@makr-code
makr-code requested a review from Copilot March 14, 2026 17:57
@makr-code
makr-code marked this pull request as ready for review March 14, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements the new AdaptiveCompactionScheduler to monitor I/O patterns, predict compaction impact, schedule compactions during low-load periods, and dynamically adapt compaction/GC triggers; extends CompactionManager to support live config updates.

Changes:

  • Added AdaptiveCompactionScheduler (EMA-based sampling, impact prediction, trigger adaptation + application to CompactionManager)
  • Extended CompactionManager with setConfig() / getConfig() for dynamic updates (incl. BG GC restart on interval change)
  • Added focused unit tests + CMake/CI wiring for the new scheduler and manager config updates

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
include/storage/adaptive_compaction.h Declares scheduler API, config, stats, and adapted config contract
src/storage/adaptive_compaction.cpp Implements sampling thread, EMA logic, prediction, triggering, and config adaptation
include/storage/compaction_manager.h Adds dynamic config update/snapshot API
src/storage/compaction_manager.cpp Implements setConfig() / getConfig() with BG GC restart behavior
tests/test_adaptive_compaction.cpp Adds focused unit + integration-style tests for scheduler and manager config updates
tests/CMakeLists.txt Adds new focused test target and ctest entry (but currently breaks CMake scoping)
cmake/CMakeLists.txt Adds adaptive compaction source to core build
cmake/ModularBuild.cmake Adds adaptive compaction source to modular storage sources
.github/workflows/adaptive-compaction-ci.yml Adds dedicated workflow to build/run the focused test target on relevant changes

You can also share your feedback on Copilot code review. Take the survey.

Comment thread tests/CMakeLists.txt
test_adaptive_compaction.cpp
)

target_include_directories(test_adaptive_compaction_focused PRIVATE
Comment on lines +147 to +150
double wa_factor = (current_write_amp > 1.0)
? std::log(current_write_amp) / std::log(config_.urgent_write_amp_threshold)
: 0.0;

Comment on lines +121 to +124
/** Minimum tombstone GC threshold (used during high-write periods). */
uint64_t min_tombstone_threshold = 1'000;

/** Maximum tombstone GC threshold (used during low-write periods). */
pred.is_urgent =
(current_write_amp >= config_.urgent_write_amp_threshold);

// Low impact = low estimated CPU overhead AND low current load.
Comment on lines +44 to +46
void AdaptiveCompactionScheduler::updateEMA(double new_value, double& ema) noexcept {
ema = config_.ema_alpha * new_value + (1.0 - config_.ema_alpha) * ema;
}
collectSample();
}
}

… conventions

- tests/CMakeLists.txt: fix post-merge corruption where
  test_adaptive_compaction_focused block was interleaved with
  test_device_manager_focused block; restore both blocks with correct
  target_include_directories, target_link_libraries and if/else/endif
  nesting
- .github/workflows/adaptive-compaction-ci.yml: replace inline cmake
  configure+build steps with configure-themis composite action; add
  librocksdb-dev to setup-cpp-build packages

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title feat(storage): AdaptiveCompactionScheduler — EMA-driven scheduling with dynamic trigger adjustment (v1.7.0) feat(storage): AdaptiveCompactionScheduler — EMA-driven I/O monitoring, impact prediction, and dynamic trigger adjustment (v1.7.0, #209) Mar 15, 2026
@makr-code
makr-code merged commit a58bf39 into develop Mar 15, 2026
63 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:storage Storage subsystem type:test Test-only change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adaptive Compaction

3 participants