From 228dbf475e5a21091bfaa6b631c4df3d39d8c486 Mon Sep 17 00:00:00 2001 From: alesapin Date: Mon, 27 Apr 2020 19:19:04 +0300 Subject: [PATCH] Finalize mutations in background (#10526) --- src/Storages/StorageReplicatedMergeTree.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Storages/StorageReplicatedMergeTree.cpp b/src/Storages/StorageReplicatedMergeTree.cpp index 267b8a1c7fa..8f822e15fcd 100644 --- a/src/Storages/StorageReplicatedMergeTree.cpp +++ b/src/Storages/StorageReplicatedMergeTree.cpp @@ -126,9 +126,10 @@ namespace ActionLocks } -static const auto QUEUE_UPDATE_ERROR_SLEEP_MS = 1 * 1000; -static const auto MERGE_SELECTING_SLEEP_MS = 5 * 1000; -static const auto MUTATIONS_FINALIZING_SLEEP_MS = 1 * 1000; +static const auto QUEUE_UPDATE_ERROR_SLEEP_MS = 1 * 1000; +static const auto MERGE_SELECTING_SLEEP_MS = 5 * 1000; +static const auto MUTATIONS_FINALIZING_SLEEP_MS = 1 * 1000; +static const auto MUTATIONS_FINALIZING_IDLE_SLEEP_MS = 5 * 1000; void StorageReplicatedMergeTree::setZooKeeper(zkutil::ZooKeeperPtr zookeeper) @@ -2284,7 +2285,18 @@ void StorageReplicatedMergeTree::mutationsFinalizingTask() } if (needs_reschedule) + { mutations_finalizing_task->scheduleAfter(MUTATIONS_FINALIZING_SLEEP_MS); + } + else + { + /// Even if no mutations seems to be done or appeared we are trying to + /// finalize them in background because manual control the launch of + /// this function is error prone. This can lead to mutations that + /// processed all the parts but have is_done=0 state for a long time. Or + /// killed mutations, which are also considered as undone. + mutations_finalizing_task->scheduleAfter(MUTATIONS_FINALIZING_IDLE_SLEEP_MS); + } }