avoid race between compaction and table stop

Also add a debug-only compaction-manager-side assertion that tests
that no new compaction tasks were submitted for a table that is being
removed (debug-only because not constant-time).

Fixes #9448.

Signed-off-by: Michael Livshin <michael.livshin@scylladb.com>
Message-Id: <20211007110416.159110-1-michael.livshin@scylladb.com>
(cherry picked from commit e88891a8af)
This commit is contained in:
Michael Livshin
2021-10-07 14:04:16 +03:00
committed by Avi Kivity
parent 14620444a2
commit 152f710dec
2 changed files with 5 additions and 2 deletions

View File

@@ -860,6 +860,9 @@ future<> compaction_manager::remove(column_family* cf) {
return do_for_each(*tasks_to_stop, [this, cf] (auto& task) {
return this->task_stop(task);
}).then([this, cf, tasks_to_stop] {
#ifdef DEBUG
assert(std::find_if(_tasks.begin(), _tasks.end(), [cf] (auto& task) { return task->compacting_cf == cf; }) == _tasks.end());
#endif
_compaction_locks.erase(cf);
});
}

View File

@@ -953,8 +953,8 @@ void table::try_trigger_compaction() noexcept {
}
void table::do_trigger_compaction() {
// But only submit if we're not locked out
if (!_compaction_disabled) {
// But not if we're locked out or stopping
if (!_compaction_disabled && !_async_gate.is_closed()) {
_compaction_manager.submit(this);
}
}