问题描述
我使用Curator 1.2.4,并且想要监视一个znode的子项更改时,我会一直得到ConnectionLossException
.
I use Curator 1.2.4 and I keep getting ConnectionLossException
when I want to monitor one znode for its children's changes.
然后我实现了这样的观察者
I then implemented a watcher like this
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.
}
}
每隔11秒,如果将connectionTimeout
设置为10秒,则代码将抛出ConnectionLossException
.看来例外是connectionTimeout
加1秒.为什么?
Every 11 seconds the code throws ConnectionLossException
if connectionTimeout
is set to 10 seconds. It seems the exception is connectionTimeout
plus 1 second. Why?
我检查了源代码,发现GetChildrenBuilderImpl将调用CuratorZookeeperClient的blockUntilConnectedOrTimeout方法,该方法每1秒检查一次连接状态.
I checked the source code found that GetChildrenBuilderImpl will call the CuratorZookeeperClient's blockUntilConnectedOrTimeout method which will check the connection state every 1 second.
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)
推荐答案
这是在 CURATOR-24当前管理悬挂ZK手柄的方法需要改进.它已在2.0.1孵化版本中修复.
This was a known bug in the Curator/ZooKeeper interaction that's tracked under CURATOR-24 The current method of managing hung ZK handles needs improvement. It was fixed in 2.0.1-incubating version.
这篇关于何时以及为何Curator引发ConnectionLossException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!