【发布时间】:2017-06-14 15:01:45
【问题描述】:
Lock.release()不删除锁路径?这是一个错误吗?
需要我自己删除路径吗?
RetryPolicy retryPolicy = new RetryOneTime(1000);
CuratorFramework client =
CuratorFrameworkFactory
.builder()
.connectString(zkAddress)
.sessionTimeoutMs(ZKConstant.ZK_SESSION_TIMEOUT)
.connectionTimeoutMs(ZKConstant.ZK_CONNECTION_TIMEOUT)
.retryPolicy(retryPolicy)
.build();
client.start();
InterProcessMutex lock = new InterProcessMutex(client, "/test_lock");
if (lock.acquire(3, TimeUnit.SECONDS)) {
LOGGER.debug(curatorUtil.exists(lockPath) == null);
}
if (lock != null){
lock.release(); // After I call this method,
// the "/test_lock" node still exists. Why?
}
LOGGER.debug(curatorUtil.exists(lockPath) == null);
client.close();
} catch (Exception e) {
e.printStackTrace();
}
}
【问题讨论】:
-
这是 ZooKeeper 中的普遍问题。这就是我在 ZooKeeper 3.5 中添加容器节点的原因。如果您使用 Curator 3.0 和 ZooKeeper 3.5.x,父节点将自动删除。在旧版本中,您需要使用 Curator's Reaper 和 ChidReaper。
标签: apache-zookeeper apache-curator