update api

This commit is contained in:
Mikhail Artemenko 2024-09-06 12:23:57 +00:00
parent cf0e0b766d
commit 068ada57ba
2 changed files with 29 additions and 17 deletions

View File

@ -979,8 +979,26 @@ bool ZooKeeper::tryRemoveChildrenRecursive(const std::string & path, bool probab
return removed_as_expected; return removed_as_expected;
} }
void ZooKeeper::removeRecursive(const std::string & path) // TODO(michicosun) rewrite void ZooKeeper::removeRecursive(const std::string & path, uint32_t remove_nodes_limit)
{ {
if (!isFeatureEnabled(DB::KeeperFeatureFlag::REMOVE_RECURSIVE))
{
removeChildrenRecursive(path);
remove(path);
return;
}
check(tryRemoveRecursive(path, remove_nodes_limit), path);
}
Coordination::Error ZooKeeper::tryRemoveRecursive(const std::string & path, uint32_t remove_nodes_limit)
{
if (!isFeatureEnabled(DB::KeeperFeatureFlag::REMOVE_RECURSIVE))
{
tryRemoveChildrenRecursive(path);
return tryRemove(path);
}
auto promise = std::make_shared<std::promise<Coordination::RemoveRecursiveResponse>>(); auto promise = std::make_shared<std::promise<Coordination::RemoveRecursiveResponse>>();
auto future = promise->get_future(); auto future = promise->get_future();
@ -989,27 +1007,20 @@ void ZooKeeper::removeRecursive(const std::string & path) // TODO(michicosun) re
promise->set_value(response); promise->set_value(response);
}; };
impl->removeRecursive(path, 100, std::move(callback)); impl->removeRecursive(path, remove_nodes_limit, std::move(callback));
if (future.wait_for(std::chrono::milliseconds(args.operation_timeout_ms)) != std::future_status::ready) if (future.wait_for(std::chrono::milliseconds(args.operation_timeout_ms)) != std::future_status::ready)
{ {
impl->finalize(fmt::format("Operation timeout on {} {}", Coordination::OpNum::RemoveRecursive, path)); impl->finalize(fmt::format("Operation timeout on {} {}", Coordination::OpNum::RemoveRecursive, path));
check(Coordination::Error::ZOPERATIONTIMEOUT, path); return Coordination::Error::ZOPERATIONTIMEOUT;
} }
else else
{ {
auto response = future.get(); auto response = future.get();
check(response.error, path); return response.error;
} }
} }
Coordination::Error ZooKeeper::tryRemoveRecursive(const std::string & path)
{
tryRemoveChildrenRecursive(path);
return tryRemove(path);
}
namespace namespace
{ {
struct WaitForDisappearState struct WaitForDisappearState

View File

@ -479,15 +479,16 @@ public:
Int64 getClientID(); Int64 getClientID();
/// Remove the node with the subtree. If someone concurrently adds or removes a node /// Remove the node with the subtree.
/// in the subtree, the result is undefined. /// If Keeper supports RemoveRecursive operation then it will be performed atomically.
void removeRecursive(const std::string & path); /// Otherwise if someone concurrently adds or removes a node in the subtree, the result is undefined.
void removeRecursive(const std::string & path, uint32_t remove_nodes_limit = 100);
/// Remove the node with the subtree. If someone concurrently removes a node in the subtree, /// Same as removeRecursive but in case if Keeper does not supports RemoveRecursive and
/// this will not cause errors. /// if someone concurrently removes a node in the subtree, this will not cause errors.
/// For instance, you can call this method twice concurrently for the same node and the end /// For instance, you can call this method twice concurrently for the same node and the end
/// result would be the same as for the single call. /// result would be the same as for the single call.
Coordination::Error tryRemoveRecursive(const std::string & path); Coordination::Error tryRemoveRecursive(const std::string & path, uint32_t remove_nodes_limit = 100);
/// Similar to removeRecursive(...) and tryRemoveRecursive(...), but does not remove path itself. /// Similar to removeRecursive(...) and tryRemoveRecursive(...), but does not remove path itself.
/// Node defined as RemoveException will not be deleted. /// Node defined as RemoveException will not be deleted.