【问题标题】:When and why does Curator throw ConnectionLossException?Curator 何时以及为何抛出 ConnectionLossException?
【发布时间】:2013-04-10 00:30:38
【问题描述】:

我使用 Curator 1.2.4,当我想监控一个 znode 的子节点更改时,我不断收到 ConnectionLossException

然后我实现了一个这样的观察者

public class CuratorChildWatcherImpl implements CuratorWatcher {

    private CuratorFramework client;

    public CuratorChildWatcherImpl(CuratorFramework client) {
        this.client = client;
    }

    @Override
    public void process(WatchedEvent event) throws Exception {
       List<String> children=client.getChildren().usingWatcher(this).forPath(event.getPath());
       // Do other stuff with the children znode.
    }
}

如果 connectionTimeout 设置为 10 秒,则代码每 11 秒抛出一次 ConnectionLossException。似乎例外是connectionTimeout 加 1 秒。为什么?

查看源码发现GetChildrenBuilderImpl会调用CuratorZookeeperClient的blockUntilConnectedOrTimeout方法,每隔1秒检查一次连接状态。

2013-04-17 17:22:08 [ERROR]-[com.netflix.curator.ConnectionState.getZooKeeper(ConnectionState.java:97)] Connection timed out for connection string (...) and timeout (10000) / elapsed (10317913)
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss
    at com.netflix.curator.ConnectionState.getZooKeeper(ConnectionState.java:94)
    at com.netflix.curator.CuratorZookeeperClient.getZooKeeper(CuratorZookeeperClient.java:107)
    at com.netflix.curator.framework.imps.CuratorFrameworkImpl.getZooKeeper(CuratorFrameworkImpl.java:413)
    at com.netflix.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:213)
    at com.netflix.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:202)
    at com.netflix.curator.RetryLoop.callWithRetry(RetryLoop.java:106)
    at com.netflix.curator.framework.imps.GetChildrenBuilderImpl.pathInForeground(GetChildrenBuilderImpl.java:198)
    at com.netflix.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:190)
    at com.netflix.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:37)
    at com.netflix.curator.framework.imps.NamespaceWatcher.process(NamespaceWatcher.java:56)
    at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:521)

【问题讨论】:

    标签: apache-zookeeper apache-curator


    【解决方案1】:

    这是在 CURATOR-24 The current method of managing hung ZK handles needs improvement 下跟踪的 ​​Curator/ZooKeeper 交互中的一个已知错误。它已在 2.0.1 孵化版本中修复。

    【讨论】:

    • 谢谢@Randgalt,我给你发了一些电子邮件,你已经告诉我了。很抱歉没有更新这个问题。
    猜你喜欢
    • 1970-01-01
    • 2010-12-25
    • 2020-08-06
    • 1970-01-01
    • 2010-10-10
    • 2017-07-01
    相关资源
    最近更新 更多