ZooKeeper: Fixed potential issue [#CLICKHOUSE-2]

This commit is contained in:
Alexey Milovidov 2018-04-05 19:42:54 +03:00
parent 805325015f
commit a2ce515a84
2 changed files with 24 additions and 14 deletions

View File

@ -1272,21 +1272,29 @@ void ZooKeeper::pushRequest(RequestInfo && info)
if (expired && info.request->xid != close_xid)
throw Exception("Session expired", ZSESSIONEXPIRED);
info.request->addRootPath(root_path);
info.time = clock::now();
if (!info.request->xid)
try
{
info.request->xid = xid.fetch_add(1);
if (info.request->xid < 0)
throw Exception("XID overflow", ZSESSIONEXPIRED);
info.request->addRootPath(root_path);
info.time = clock::now();
if (!info.request->xid)
{
info.request->xid = xid.fetch_add(1);
if (info.request->xid < 0)
throw Exception("XID overflow", ZSESSIONEXPIRED);
}
ProfileEvents::increment(ProfileEvents::ZooKeeperTransactions);
if (!requests_queue.tryPush(std::move(info), operation_timeout.totalMilliseconds()))
throw Exception("Cannot push request to queue within operation timeout", ZOPERATIONTIMEOUT);
}
catch (...)
{
finalize(false, false);
throw;
}
ProfileEvents::increment(ProfileEvents::ZooKeeperTransactions);
if (!requests_queue.tryPush(std::move(info), operation_timeout.totalMilliseconds()))
throw Exception("Cannot push request to queue within operation timeout", ZOPERATIONTIMEOUT);
}

View File

@ -440,7 +440,9 @@ public:
using MultiCallback = std::function<void(const MultiResponse &)>;
/// If the method will throw exception, callbacks won't be called.
/// After the method is executed successfully, you must wait for callbacks.
/// After the method is executed successfully, you must wait for callbacks
/// (don't destroy callback data before it will be called).
/// All callbacks are executed sequentially.
void create(
const String & path,