add zookeeper tryRemoveChildren method

This commit is contained in:
Val 2020-05-24 20:12:59 +03:00
parent 34f74ff785
commit 1f03839830
2 changed files with 22 additions and 0 deletions

View File

@ -579,6 +579,23 @@ void ZooKeeper::removeChildren(const std::string & path)
}
void ZooKeeper::tryRemoveChildren(const std::string & path)
{
Strings children;
if (tryGetChildren(path, children) != Coordination::ZOK)
return;
while (!children.empty())
{
Coordination::Requests ops;
for (size_t i = 0; i < MULTI_BATCH_SIZE && !children.empty(); ++i)
{
ops.emplace_back(makeRemoveRequest(path + "/" + children.back(), -1));
children.pop_back();
}
multi(ops);
}
}
void ZooKeeper::removeChildrenRecursive(const std::string & path)
{
Strings children = getChildren(path);

View File

@ -187,7 +187,12 @@ public:
/// Remove all children nodes (non recursive).
void removeChildren(const std::string & path);
/// Remove all children nodes (non recursive).
/// If there're no children, this method doesn't throw an exception
void tryRemoveChildren(const std::string & path);
using WaitCondition = std::function<bool()>;
/// Wait for the node to disappear or return immediately if it doesn't exist.
/// If condition is speficied, it is used to return early (when condition returns false)
/// The function returns true if waited and false if waiting was interrupted by condition.