【问题标题】:Curator:InterProcessMutex Lock.release() didn't delete lock path策展人:InterProcessMutex Lock.release() 没有删除锁路径
【发布时间】: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


【解决方案1】:

是的!父节点不会自动删除。因为实际创建的节点是这样的

/test_lock/"+"_c_"+UUID.randomUUID().toString()+"-"

CreateBuilderImpl#adjustPath

之后

lock.release()

子节点将被删除。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    • 2013-09-18
    • 2015-02-03
    • 2019-12-01
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多