From 0a46d231eddb16f5261aba5bbb8d85c1a26f9b41 Mon Sep 17 00:00:00 2001 From: Alexey Zatelepin Date: Wed, 4 Jul 2018 18:44:12 +0300 Subject: [PATCH] speedup merge selection: async exists check for selected parts [#CLICKHOUSE-3802] --- dbms/src/Storages/StorageReplicatedMergeTree.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.cpp b/dbms/src/Storages/StorageReplicatedMergeTree.cpp index 92a82d128f4..87cda09f566 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.cpp +++ b/dbms/src/Storages/StorageReplicatedMergeTree.cpp @@ -2282,14 +2282,20 @@ bool StorageReplicatedMergeTree::createLogEntryToMergeParts( bool deduplicate, ReplicatedMergeTreeLogEntryData * out_log_entry) { - bool all_in_zk = true; + std::vector> exists_futures; + exists_futures.reserve(parts.size()); for (const auto & part : parts) + exists_futures.emplace_back(zookeeper->asyncExists(replica_path + "/parts/" + part->name)); + + bool all_in_zk = true; + for (size_t i = 0; i < parts.size(); ++i) { /// If there is no information about part in ZK, we will not merge it. - if (!zookeeper->exists(replica_path + "/parts/" + part->name)) + if (exists_futures[i].get().error == ZooKeeperImpl::ZooKeeper::ZNONODE) { all_in_zk = false; + const auto & part = parts[i]; if (part->modification_time + MAX_AGE_OF_LOCAL_PART_THAT_WASNT_ADDED_TO_ZOOKEEPER < time(nullptr)) { LOG_WARNING(log, "Part " << part->name << " (that was selected for merge)" @@ -2300,6 +2306,7 @@ bool StorageReplicatedMergeTree::createLogEntryToMergeParts( } } } + if (!all_in_zk) return false;