From 1da86169d69aabec875da5fd98c52d82016d46ff Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 3 Oct 2014 03:31:18 +0400 Subject: [PATCH] dbms: more handy error message [#METR-2944]. --- dbms/include/DB/Core/ErrorCodes.h | 1 + .../ReplicatedMergeTreeBlockOutputStream.h | 2 +- .../src/Storages/StorageReplicatedMergeTree.cpp | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dbms/include/DB/Core/ErrorCodes.h b/dbms/include/DB/Core/ErrorCodes.h index 61a6449cbbe..cdaaee298ce 100644 --- a/dbms/include/DB/Core/ErrorCodes.h +++ b/dbms/include/DB/Core/ErrorCodes.h @@ -260,6 +260,7 @@ namespace ErrorCodes NOT_ENOUGH_BLOCK_NUMBERS, NO_SUCH_REPLICA, TOO_MUCH_PARTS, + REPLICA_IS_ALREADY_EXIST, POCO_EXCEPTION = 1000, STD_EXCEPTION, diff --git a/dbms/include/DB/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h b/dbms/include/DB/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h index 409603e6d08..3803f6d259e 100644 --- a/dbms/include/DB/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h +++ b/dbms/include/DB/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h @@ -125,7 +125,7 @@ public: + zkutil::ZooKeeper::error2string(code), ErrorCodes::UNEXPECTED_ZOOKEEPER_ERROR); } } - catch (zkutil::KeeperException & e) + catch (const zkutil::KeeperException & e) { /** Если потерялось соединение, и мы не знаем, применились ли изменения, нельзя удалять локальный кусок: * если изменения применились, в /blocks/ появился вставленный блок, и его нельзя будет вставить снова. diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.cpp b/dbms/src/Storages/StorageReplicatedMergeTree.cpp index 25388310c0c..2c0c9a8874b 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.cpp +++ b/dbms/src/Storages/StorageReplicatedMergeTree.cpp @@ -271,7 +271,18 @@ void StorageReplicatedMergeTree::createReplica() ops.push_back(new zkutil::Op::Create(replica_path + "/queue", "", zookeeper->getDefaultACL(), zkutil::CreateMode::Persistent)); ops.push_back(new zkutil::Op::Create(replica_path + "/parts", "", zookeeper->getDefaultACL(), zkutil::CreateMode::Persistent)); ops.push_back(new zkutil::Op::Create(replica_path + "/flags", "", zookeeper->getDefaultACL(), zkutil::CreateMode::Persistent)); - zookeeper->multi(ops); + + try + { + zookeeper->multi(ops); + } + catch (const zkutil::KeeperException & e) + { + if (e.code == ZNODEEXISTS) + throw Exception("Replica " + replica_path + " is already exist.", ErrorCodes::REPLICA_IS_ALREADY_EXIST); + + throw; + } /** Нужно изменить данные ноды /replicas на что угодно, чтобы поток, удаляющий старые записи в логе, * споткнулся об это изменение и не удалил записи, которые мы еще не прочитали. @@ -404,7 +415,7 @@ void StorageReplicatedMergeTree::activateReplica() { zookeeper->multi(ops); } - catch (zkutil::KeeperException & e) + catch (const zkutil::KeeperException & e) { if (e.code == ZNODEEXISTS) throw Exception("Replica " + replica_path + " appears to be already active. If you're sure it's not, " @@ -1201,7 +1212,7 @@ void StorageReplicatedMergeTree::queueUpdatingThread() queue_updating_event->wait(); } - catch (zkutil::KeeperException & e) + catch (const zkutil::KeeperException & e) { if (e.code == ZINVALIDSTATE) restarting_event.set();