From bb909798bc7edb41b83f2c15828ee9bbfd153e06 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Thu, 21 Jan 2016 15:39:24 -0200 Subject: [PATCH] compaction_manager: introduce can_submit Purpose is to reuse code and also make it easier to read. Signed-off-by: Raphael S. Carvalho --- sstables/compaction_manager.cc | 8 ++++++-- sstables/compaction_manager.hh | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sstables/compaction_manager.cc b/sstables/compaction_manager.cc index 044efc4f94..ae3b22931a 100644 --- a/sstables/compaction_manager.cc +++ b/sstables/compaction_manager.cc @@ -254,8 +254,12 @@ void compaction_manager::signal_less_busy_task() { (*result)->compaction_sem.signal(); } +bool compaction_manager::can_submit() { + return !_stopped && !_tasks.empty(); +} + void compaction_manager::submit(column_family* cf) { - if (_stopped || _tasks.empty()) { + if (!can_submit()) { return; } // To avoid having two or more entries of the same cf stored in the queue. @@ -268,7 +272,7 @@ void compaction_manager::submit(column_family* cf) { } void compaction_manager::submit_cleanup_job(column_family* cf) { - if (_stopped || _tasks.empty()) { + if (!can_submit()) { return; } // To avoid having two or more entries of the same cf stored in the queue. diff --git a/sstables/compaction_manager.hh b/sstables/compaction_manager.hh index 142a9b9086..ae895f304e 100644 --- a/sstables/compaction_manager.hh +++ b/sstables/compaction_manager.hh @@ -82,6 +82,10 @@ private: // This function is called when a cf is submitted for compaction and we need // to wake up a handler. void signal_less_busy_task(); + // Returns if this compaction manager is accepting new requests. + // It will not accept new requests in case the manager was stopped and/or there + // is no task to handle them. + bool can_submit(); public: compaction_manager(); ~compaction_manager();