From 8c5e5ec1cf02659445e93015cb1e90fe2e95398f Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 15 Aug 2020 15:30:17 +0300 Subject: [PATCH] Fix flaky test 01305_replica_create_drop_zookeeper --- src/Storages/StorageReplicatedMergeTree.cpp | 35 ++++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Storages/StorageReplicatedMergeTree.cpp b/src/Storages/StorageReplicatedMergeTree.cpp index 1c0c0b1f351..b6d967906eb 100644 --- a/src/Storages/StorageReplicatedMergeTree.cpp +++ b/src/Storages/StorageReplicatedMergeTree.cpp @@ -268,16 +268,28 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree( { bool is_first_replica = createTableIfNotExists(metadata_snapshot); - /// We have to check granularity on other replicas. If it's fixed we - /// must create our new replica with fixed granularity and store this - /// information in /replica/metadata. - other_replicas_fixed_granularity = checkFixedGranualrityInZookeeper(); + try + { + /// NOTE If it's the first replica, these requests to ZooKeeper look redundant, we already know everything. - checkTableStructure(zookeeper_path, metadata_snapshot); + /// We have to check granularity on other replicas. If it's fixed we + /// must create our new replica with fixed granularity and store this + /// information in /replica/metadata. + other_replicas_fixed_granularity = checkFixedGranualrityInZookeeper(); - Coordination::Stat metadata_stat; - current_zookeeper->get(zookeeper_path + "/metadata", &metadata_stat); - metadata_version = metadata_stat.version; + checkTableStructure(zookeeper_path, metadata_snapshot); + + Coordination::Stat metadata_stat; + current_zookeeper->get(zookeeper_path + "/metadata", &metadata_stat); + metadata_version = metadata_stat.version; + } + catch (Coordination::Exception & e) + { + if (!is_first_replica && e.code == Coordination::Error::ZNONODE) + throw Exception("Table " + zookeeper_path + " was suddenly removed.", ErrorCodes::ALL_REPLICAS_LOST); + else + throw; + } if (!is_first_replica) createReplica(metadata_snapshot); @@ -291,7 +303,6 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree( } else { - /// In old tables this node may missing or be empty String replica_metadata; bool replica_metadata_exists = current_zookeeper->tryGet(replica_path + "/metadata", replica_metadata); @@ -758,9 +769,9 @@ void StorageReplicatedMergeTree::dropReplica(zkutil::ZooKeeperPtr zookeeper, con } -/** Verify that list of columns and table storage_settings_ptr match those specified in ZK (/ metadata). - * If not, throw an exception. - */ +/** Verify that list of columns and table storage_settings_ptr match those specified in ZK (/metadata). + * If not, throw an exception. + */ void StorageReplicatedMergeTree::checkTableStructure(const String & zookeeper_prefix, const StorageMetadataPtr & metadata_snapshot) { auto zookeeper = getZooKeeper();