首页 > 解决方案 > Zookeeper 3.5 和 Curator 4.0:InterProcessMutex release() 没有删除锁路径

问题描述

我正在使用 CuratorFramework 4.0.0 和 Zookeper 3.5.4。我有这个代码片段:

RetryPolicy retryPolicy = new RetryOneTime(1000);
client = CuratorFrameworkFactory.newClient(zkConnectionString, retryPolicy);
client.start();
String path = "/node/test_lock";
client.createContainers(path);
InterProcessSemaphoreMutex lock = new InterProcessSemaphoreMutex(client, path);
if (lock.acquire(3, TimeUnit.MILLISECONDS)) {                 
    LOGGER.debug(client.exists(lockPath) == null);
}
if (lock != null){
    lock.release();  // After I call this method,
                     // the "/node/test_lock" node still exists.
}

使用zookeeper 3.5版本,锁路径不应该自动删除?我错过了什么?

谢谢!

标签: apache-zookeeperapache-curator

解决方案


锁配方的“父”ZNode 被创建为容器节点。当容器节点没有剩余子节点时,它会被 ZooKeeper 清理。默认时间检查是 1 分钟,因此您不会看到父节点被删除,直到大约。1 分钟后(此值可以更改 - 有关znode.container.checkIntervalMs的详细信息,请参见此处)


推荐阅读