logbroker-import: develop partition release

This commit is contained in:
Pavel Kartavyy 2016-07-13 17:14:05 +03:00
parent 34b27dbbe4
commit aaf4207c38
2 changed files with 20 additions and 0 deletions

View File

@ -59,6 +59,7 @@ namespace zkutil
Status tryCheck() const;
void unlock();
void unlockAndMoveIfFailed(std::vector<zkutil::Lock> & failed_to_unlock_locks);
bool tryLock();

View File

@ -58,6 +58,7 @@ void Lock::unlock()
{
size_t attempt;
int32_t code = zookeeper->tryRemoveEphemeralNodeWithRetries(lock_path, -1, &attempt);
if (attempt)
{
if (code != ZOK)
@ -119,3 +120,21 @@ std::string Lock::status2String(Status status)
return names[status];
}
void Lock::unlockAndMoveIfFailed(std::vector<zkutil::Lock> & failed_to_unlock_locks)
{
try
{
unlock();
}
catch (const zkutil::KeeperException & e)
{
if (e.isTemporaryError())
{
LOG_WARNING(log, "Fail to unlock lock. Move lock to vector to remove later. Path: " << getPath());
failed_to_unlock_locks.emplace_back(std::move(*this));
}
else
throw;
}
}