mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
███████████: write recount requests robustly [#METR-11718]
This commit is contained in:
parent
0eedb5ee84
commit
9feab97b19
@ -9,6 +9,7 @@ namespace zkutil
|
||||
{
|
||||
|
||||
const UInt32 DEFAULT_SESSION_TIMEOUT = 30000;
|
||||
const UInt32 DEFAULT_RETRY_NUM = 3;
|
||||
|
||||
struct WatchWithPromise;
|
||||
|
||||
@ -86,6 +87,12 @@ public:
|
||||
int32_t tryCreate(const std::string & path, const std::string & data, int32_t mode, std::string & pathCreated);
|
||||
int32_t tryCreate(const std::string & path, const std::string & data, int32_t mode);
|
||||
|
||||
/** создает Persistent ноду.
|
||||
* Игнорирует, если нода уже создана.
|
||||
* Пытается сделать retry при ConnectionLoss или OperationTimeout
|
||||
*/
|
||||
void createIfNotExists(const std::string & path, const std::string & data);
|
||||
|
||||
/** Удалить ноду, если ее версия равна version (если -1, подойдет любая версия).
|
||||
*/
|
||||
void remove(const std::string & path, int32_t version = -1);
|
||||
|
@ -222,6 +222,27 @@ int32_t ZooKeeper::tryCreate(const std::string & path, const std::string & data,
|
||||
return tryCreate(path, data, mode, pathCreated);
|
||||
}
|
||||
|
||||
void ZooKeeper::createIfNotExists(const std::string & path, const std::string & data)
|
||||
{
|
||||
int32_t code = tryCreate(path, "", zkutil::CreateMode::Persistent);
|
||||
|
||||
if (code == ZOK || code == ZNODEEXISTS)
|
||||
return;
|
||||
|
||||
if (!(code == ZOPERATIONTIMEOUT || code == ZCONNECTIONLOSS))
|
||||
throw KeeperException(code, path);
|
||||
|
||||
for (size_t attempt = 0; attempt < retry_num && (code == ZOPERATIONTIMEOUT || code == ZCONNECTIONLOSS); ++attempt)
|
||||
{
|
||||
code = tryCreate(path, "", zkutil::CreateMode::Persistent);
|
||||
};
|
||||
|
||||
if (code == ZOK || code == ZNODEEXISTS)
|
||||
return;
|
||||
else
|
||||
throw KeeperException(code, path);
|
||||
}
|
||||
|
||||
int32_t ZooKeeper::removeImpl(const std::string & path, int32_t version)
|
||||
{
|
||||
int32_t code = zoo_delete(impl, path.c_str(), version);
|
||||
|
Loading…
Reference in New Issue
Block a user