From 87f7e0b3998fcacebc96f57b08d5e9975af6fd11 Mon Sep 17 00:00:00 2001 From: alesapin Date: Thu, 19 Nov 2020 15:04:09 +0300 Subject: [PATCH] More compatible watches in TestKeeper --- src/Common/ZooKeeper/TestKeeper.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Common/ZooKeeper/TestKeeper.cpp b/src/Common/ZooKeeper/TestKeeper.cpp index 4ae26d874f..5f34a60c34 100644 --- a/src/Common/ZooKeeper/TestKeeper.cpp +++ b/src/Common/ZooKeeper/TestKeeper.cpp @@ -511,19 +511,30 @@ void TestKeeper::processingThread() if (expired) break; - if (info.watch) - { - auto & watches_type = dynamic_cast(info.request.get()) - ? list_watches - : watches; - - watches_type[info.request->getPath()].emplace_back(std::move(info.watch)); - } ++zxid; info.request->addRootPath(root_path); auto [response, _] = info.request->process(container, zxid); + + if (info.watch) + { + /// To be compatible with real ZooKeeper we add watch if request was successful (i.e. node exists) + /// or if it was exists request which allows to add watches for non existing nodes. + if (response->error == Error::ZOK) + { + auto & watches_type = dynamic_cast(info.request.get()) + ? list_watches + : watches; + + watches_type[info.request->getPath()].emplace_back(std::move(info.watch)); + } + else if (response->error == Error::ZNONODE && dynamic_cast(info.request.get())) + { + watches[info.request->getPath()].emplace_back(std::move(info.watch)); + } + } + if (response->error == Error::ZOK) info.request->processWatches(watches, list_watches); -- GitLab