Skip to content

Commit

Permalink
compaction_manager: perform_cleanup: wait until all candidates are cl…
Browse files Browse the repository at this point in the history
…eaned up

cleanup_compaction should resolve only after all
sstables that require cleanup are cleaned up.

Since it is possible that some of them are in staging
and therefore cannot be cleaned up, retry once a second
until they become eligible.

Timeout if there is no progress within 5 minutes
to prevent hanging due to view building bug.

\Fixes scylladb#9559

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
(cherry picked from commit a5a8020)
  • Loading branch information
bhalevy committed Nov 13, 2023
1 parent 2357b29 commit 1b114b3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 38 additions & 1 deletion compaction/compaction_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,44 @@ bool compaction_manager::requires_cleanup(table_state& t, const sstables::shared
return cs.sstables_requiring_cleanup.contains(sst);
}

future<> compaction_manager::perform_cleanup(owned_ranges_ptr sorted_owned_ranges, compaction::table_state& t) {
future<> compaction_manager::perform_cleanup(owned_ranges_ptr sorted_owned_ranges, table_state& t) {
constexpr auto sleep_duration = std::chrono::seconds(10);
constexpr auto max_idle_duration = std::chrono::seconds(300);
auto& cs = get_compaction_state(&t);

co_await try_perform_cleanup(sorted_owned_ranges, t);
auto last_idle = seastar::lowres_clock::now();

while (!cs.sstables_requiring_cleanup.empty()) {
auto idle = seastar::lowres_clock::now() - last_idle;
if (idle >= max_idle_duration) {
auto msg = ::format("Cleanup timed out after {} seconds of no progress", std::chrono::duration_cast<std::chrono::seconds>(idle).count());
cmlog.warn("{}", msg);
co_await coroutine::return_exception(std::runtime_error(msg));
}

auto has_sstables_eligible_for_compaction = [&] {
for (auto& sst : cs.sstables_requiring_cleanup) {
if (sstables::is_eligible_for_compaction(sst)) {
return true;
}
}
return false;
};

cmlog.debug("perform_cleanup: waiting for sstables to become eligible for cleanup");
// FIXME: wait for a signal from view update builder
co_await sleep(sleep_duration);

if (!has_sstables_eligible_for_compaction()) {
continue;
}
co_await try_perform_cleanup(sorted_owned_ranges, t);
last_idle = seastar::lowres_clock::now();
}
}

future<> compaction_manager::try_perform_cleanup(owned_ranges_ptr sorted_owned_ranges, table_state& t) {
auto check_for_cleanup = [this, &t] {
return boost::algorithm::any_of(_tasks, [&t] (auto& task) {
return task->compacting_table() == &t && task->type() == sstables::compaction_type::Cleanup;
Expand Down
3 changes: 3 additions & 0 deletions compaction/compaction_manager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ public:
// given sstable, e.g. after node loses part of its token range because
// of a newly added node.
future<> perform_cleanup(owned_ranges_ptr sorted_owned_ranges, compaction::table_state& t);
private:
future<> try_perform_cleanup(owned_ranges_ptr sorted_owned_ranges, compaction::table_state& t);

public:
// Submit a table to be upgraded and wait for its termination.
future<> perform_sstable_upgrade(owned_ranges_ptr sorted_owned_ranges, compaction::table_state& t, bool exclude_current_version);

Expand Down

0 comments on commit 1b114b3

Please sign in to comment.