From 0d21129cc70b659b4e5aa3bd675e95ec35f201f9 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Thu, 22 Jun 2017 05:05:50 -0300 Subject: [PATCH] compaction_manager: periodically submit cfs for compaction This is useful for a column family which isn't generating new content and will have lots of expired data later on that can be purged. Compaction submission is NO-OP if there's nothing to do, so I think it's reasonable to do it at an interval of 1 hour. Signed-off-by: Raphael S. Carvalho --- sstables/compaction_manager.cc | 10 ++++++++++ sstables/compaction_manager.hh | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/sstables/compaction_manager.cc b/sstables/compaction_manager.cc index 5d2ab939c7..10cf4339f6 100644 --- a/sstables/compaction_manager.cc +++ b/sstables/compaction_manager.cc @@ -344,6 +344,15 @@ void compaction_manager::register_metrics() { void compaction_manager::start() { _stopped = false; register_metrics(); + _compaction_submission_timer.arm(periodic_compaction_submission_interval); +} + +std::function compaction_manager::compaction_submission_callback() { + return [this] () mutable { + for (auto& e: _compaction_locks) { + submit(e.first); + } + }; } future<> compaction_manager::stop() { @@ -367,6 +376,7 @@ future<> compaction_manager::stop() { }); }).then([this] { _weight_tracker.clear(); + _compaction_submission_timer.cancel(); cmlog.info("Stopped"); return make_ready_future<>(); }); diff --git a/sstables/compaction_manager.hh b/sstables/compaction_manager.hh index d3b0889c81..248813dfc8 100644 --- a/sstables/compaction_manager.hh +++ b/sstables/compaction_manager.hh @@ -82,6 +82,12 @@ private: semaphore _major_compaction_sem{1}; // Prevents column family from running major and minor compaction at same time. std::unordered_map _compaction_locks; + + std::function compaction_submission_callback(); + // all registered column families are submitted for compaction at a constant interval. + // Submission is a NO-OP when there's nothing to do, so it's fine to call it regularly. + timer _compaction_submission_timer = timer(compaction_submission_callback()); + static constexpr std::chrono::seconds periodic_compaction_submission_interval = std::chrono::seconds(3600); private: future<> task_stop(lw_shared_ptr task);