dbms: fixed race condition in SingleBarrier [#METR-18510]

This commit is contained in:
Alexey Arno 2016-09-01 11:58:49 +03:00
parent 18930e5bb5
commit b62b499a9c

View File

@ -41,6 +41,22 @@ SingleBarrier::SingleBarrier(GetZooKeeper get_zookeeper_, const std::string & pa
if ((code != ZOK) && (code != ZNODEEXISTS)) if ((code != ZOK) && (code != ZNODEEXISTS))
throw KeeperException{code}; throw KeeperException{code};
if (code == ZNODEEXISTS)
{
/// This barrier is already being created by another node.
/// Wait until it has been fully created so that it is usable.
if (!zookeeper->exists(path + "/lock", nullptr, event))
{
do
{
abortIfRequested();
}
while (!event->tryWait(wait_duration));
return;
}
}
/// List of tokens. /// List of tokens.
code = zookeeper->tryCreate(path + "/tokens", "", CreateMode::Persistent); code = zookeeper->tryCreate(path + "/tokens", "", CreateMode::Persistent);
if ((code != ZOK) && (code != ZNODEEXISTS)) if ((code != ZOK) && (code != ZNODEEXISTS))