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 <raphaelsc@scylladb.com>
This commit is contained in:
Raphael S. Carvalho
2017-06-22 05:05:50 -03:00
parent 719dbf547d
commit 0d21129cc7
2 changed files with 16 additions and 0 deletions

View File

@@ -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<void()> 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<>();
});

View File

@@ -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<column_family*, rwlock> _compaction_locks;
std::function<void()> 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<lowres_clock> _compaction_submission_timer = timer<lowres_clock>(compaction_submission_callback());
static constexpr std::chrono::seconds periodic_compaction_submission_interval = std::chrono::seconds(3600);
private:
future<> task_stop(lw_shared_ptr<task> task);