From 73ed05492bf21f12f68bfc910abd7d8db0aaa0ee Mon Sep 17 00:00:00 2001 From: alesapin Date: Fri, 20 Nov 2020 11:37:16 +0300 Subject: [PATCH] More correct initialization --- src/Common/ZooKeeper/TestKeeperStorage.cpp | 9 +++++++-- src/Server/TestKeeperTCPHandler.cpp | 2 -- src/Server/TestKeeperTCPHandler.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Common/ZooKeeper/TestKeeperStorage.cpp b/src/Common/ZooKeeper/TestKeeperStorage.cpp index 9f88774455f..02649dccbff 100644 --- a/src/Common/ZooKeeper/TestKeeperStorage.cpp +++ b/src/Common/ZooKeeper/TestKeeperStorage.cpp @@ -40,6 +40,7 @@ static void processWatchesImpl(const String & path, TestKeeperStorage::Watches & Coordination::ZooKeeperWatchResponse watch_response; watch_response.path = path; watch_response.xid = -1; + watch_response.zxid = -1; auto it = watches.find(watch_response.path); if (it != watches.end()) @@ -54,6 +55,7 @@ static void processWatchesImpl(const String & path, TestKeeperStorage::Watches & Coordination::ZooKeeperWatchResponse watch_list_response; watch_list_response.path = parentPath(path); watch_list_response.xid = -1; + watch_list_response.zxid = -1; it = list_watches.find(watch_list_response.path); if (it != list_watches.end()) @@ -238,7 +240,7 @@ struct TestKeeperStorageRemoveRequest final : public TestKeeperStorageRequest else { auto prev_node = it->second; - if (it->second.is_ephemeral) + if (prev_node.is_ephemeral) ephemerals[session_id].erase(request.path); container.erase(it); @@ -247,8 +249,11 @@ struct TestKeeperStorageRemoveRequest final : public TestKeeperStorageRequest ++parent.stat.cversion; response.error = Coordination::Error::ZOK; - undo = [prev_node, &container, path = request.path] + undo = [prev_node, &container, &ephemerals, session_id, path = request.path] { + if (prev_node.is_ephemeral) + ephemerals[session_id].emplace(path); + container.emplace(path, prev_node); auto & undo_parent = container.at(parentPath(path)); ++undo_parent.stat.numChildren; diff --git a/src/Server/TestKeeperTCPHandler.cpp b/src/Server/TestKeeperTCPHandler.cpp index 261e9576ec5..935e392325d 100644 --- a/src/Server/TestKeeperTCPHandler.cpp +++ b/src/Server/TestKeeperTCPHandler.cpp @@ -17,12 +17,10 @@ namespace DB namespace ErrorCodes { extern const int LOGICAL_ERROR; - } void TestKeeperTCPHandler::sendHandshake() { - session_id = test_keeper_storage->getSessionID(); Coordination::write(Coordination::SERVER_HANDSHAKE_LENGTH, *out); Coordination::write(Coordination::ZOOKEEPER_PROTOCOL_VERSION, *out); Coordination::write(Coordination::DEFAULT_SESSION_TIMEOUT_MS, *out); diff --git a/src/Server/TestKeeperTCPHandler.h b/src/Server/TestKeeperTCPHandler.h index 76da1bad89b..ca72b9711bb 100644 --- a/src/Server/TestKeeperTCPHandler.h +++ b/src/Server/TestKeeperTCPHandler.h @@ -25,6 +25,7 @@ public: , test_keeper_storage(global_context.getTestKeeperStorage()) , operation_timeout(0, Coordination::DEFAULT_OPERATION_TIMEOUT_MS * 1000) , session_timeout(0, Coordination::DEFAULT_SESSION_TIMEOUT_MS * 1000) + , session_id(test_keeper_storage->getSessionID()) { }