From db516e8c9142aedeb2a9d5ba8ed9b5ee0063bf31 Mon Sep 17 00:00:00 2001 From: Vladimir Chebotarev Date: Fri, 17 Sep 2021 16:19:36 +0300 Subject: [PATCH] Removed sub-optimal mutation notifications in `StorageMergeTree` when merges are still going (#27552) * Removed redundand mutation notifications in `StorageMergeTree` when merges are still going. --- src/Storages/StorageMergeTree.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Storages/StorageMergeTree.cpp b/src/Storages/StorageMergeTree.cpp index 1310b6199cd..e2a0c36b463 100644 --- a/src/Storages/StorageMergeTree.cpp +++ b/src/Storages/StorageMergeTree.cpp @@ -1019,7 +1019,7 @@ bool StorageMergeTree::scheduleDataProcessingJob(BackgroundJobsAssignee & assign auto share_lock = lockForShare(RWLockImpl::NO_QUERY, getSettings()->lock_acquire_timeout_for_background_operations); - bool has_mutations; + bool has_mutations = false; { std::unique_lock lock(currently_processing_in_background_mutex); if (merger_mutator.merges_blocker.isCancelled()) @@ -1027,16 +1027,10 @@ bool StorageMergeTree::scheduleDataProcessingJob(BackgroundJobsAssignee & assign merge_entry = selectPartsToMerge(metadata_snapshot, false, {}, false, nullptr, share_lock, lock); if (!merge_entry) + { mutate_entry = selectPartsToMutate(metadata_snapshot, nullptr, share_lock); - - has_mutations = !current_mutations_by_version.empty(); - } - - if (!mutate_entry && has_mutations) - { - /// Notify in case of errors - std::lock_guard lock(mutation_wait_mutex); - mutation_wait_event.notify_all(); + has_mutations = !current_mutations_by_version.empty(); + } } if (merge_entry) @@ -1051,6 +1045,14 @@ bool StorageMergeTree::scheduleDataProcessingJob(BackgroundJobsAssignee & assign assignee.scheduleMergeMutateTask(task); return true; } + if (has_mutations) + { + /// Notify in case of errors if no mutation was successfully selected. + /// Otherwise, notification will occur after any of mutations complete. + std::lock_guard lock(mutation_wait_mutex); + mutation_wait_event.notify_all(); + } + bool scheduled = false; if (time_after_previous_cleanup_temporary_directories.compareAndRestartDeferred(getContext()->getSettingsRef().merge_tree_clear_old_temporary_directories_interval_seconds)) {