Skip to content

Commit

Permalink
Fix ZooDelete in zookeeper client
Browse files Browse the repository at this point in the history
Fix ZooDelete in zookeeper client to retry recoverable errors

Closes-Bug #1692453

Change-Id: If9a9d10d8675acd181aeb2f8436c1aa944cbb13f
(cherry picked from commit 97b9d19)
  • Loading branch information
Megh Bhatt authored and Sundaresan Rajangam committed Jun 28, 2017
1 parent 513bf79 commit 1d26974
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/zookeeper/test/zookeeper_client_test.cc
Expand Up @@ -212,6 +212,35 @@ TEST_F(ZookeeperClientTest, ZooCreateUnrecoverableError) {
EXPECT_FALSE(cImpl->IsConnected());
}

TEST_F(ZookeeperClientTest, ZooDeleteRecoverableError) {
ZookeeperMockInterface *zmi(new ZookeeperMockInterface);
EXPECT_CALL(*zmi, ZooSetDebugLevel(_));
impl::ZookeeperClientImpl *cImpl(
new impl::ZookeeperClientImpl("Test", "127.0.0.1:2181", zmi));
std::auto_ptr<ZookeeperClient> client(CreateClient(cImpl));
std::string zk_lock_name("/test-lock");
ZookeeperLock zk_lock(client.get(), zk_lock_name.c_str());
std::string zk_lock_id(GetLockId(zk_lock));
int zkh(0xdeadbeef);
zhandle_t *zk_handle = (zhandle_t *)(&zkh);
EXPECT_CALL(*zmi, ZookeeperInit(StrEq("127.0.0.1:2181"), _, _, _, _, _))
.WillOnce(Return(zk_handle));
EXPECT_CALL(*zmi, ZooState(zk_handle))
.WillOnce(Return(ZOO_CONNECTED_STATE));
EXPECT_CALL(*zmi, ZooCreate(zk_handle, StrEq(zk_lock_name),
StrEq(zk_lock_id), zk_lock_id.length(), _, _, _, _))
.WillOnce(Return(ZOK));
EXPECT_TRUE(zk_lock.Lock());
EXPECT_TRUE(cImpl->IsConnected());
EXPECT_CALL(*zmi, ZooDelete(zk_handle, StrEq(zk_lock_name), _))
.WillOnce(Return(ZCONNECTIONLOSS))
.WillOnce(Return(ZOPERATIONTIMEOUT))
.WillOnce(Return(ZOK));
EXPECT_CALL(*zmi, ZookeeperClose(zk_handle));
EXPECT_TRUE(zk_lock.Release());
EXPECT_FALSE(cImpl->IsConnected());
}

int main(int argc, char **argv) {
LoggingInit();
::testing::InitGoogleTest(&argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion src/zookeeper/zookeeper_client.cc
Expand Up @@ -190,7 +190,7 @@ int ZookeeperClientImpl::DeleteNodeSync(const char *path, int *err) {
retry:
do {
rc = zki_->ZooDelete(zk_handle_, path, -1);
} while (IsZooErrorUnrecoverable(rc));
} while (IsZooErrorRecoverable(rc));
if (IsZooErrorUnrecoverable(rc)) {
// Reconnect
Reconnect();
Expand Down

0 comments on commit 1d26974

Please sign in to comment.