Connection loss is not related with the session timeout. If it frequently ocurrs, then it indicates
that the ensemble of zookeeper are not in a good state.
bit1129@163.com
From: Chris Barlock
Date: 2015-01-16 10:04
To: user
Subject: ConnectionLossException
We are currently using ZK 3.3.4, which is included in the version of Kafka
we are using. I'm seeing a number of exceptions like:
org.apache.zookeeper.KeeperException$ConnectionLossException:
KeeperErrorCode = ConnectionLoss for /com
at
org.apache.zookeeper.KeeperException.create(KeeperException.java:90)
at
org.apache.zookeeper.KeeperException.create(KeeperException.java:42)
at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:815)
at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:843)
at
com.ibm.tivoli.ccm.config.rest.ConfigClient.setValueAtNode(ConfigClient.java:630)
My method setValueAtNode includes a call to this method before I make any
zk (ZooKeeper) calls:
private void connectZooKeeper() {
final String methodName = "connectZooKeeper";
trace.entry(CLASS_NAME, methodName);
if (zk == null || zk.getState() != States.CONNECTED) {
if (zk != null) {
close();
}
try {
zk = new ZooKeeper(connectString, sessionTimeout, this);
int connectAttempts = 0;
while (zk.getState() != States.CONNECTED &&
connectAttempts < MAX_ZK_CONNECT_ATTEMPTS) {
try {
Thread.sleep(ZK_CONNECT_WAIT);
} catch (InterruptedException e) {
// Ignore
}
connectAttempts++;
}
} catch (IOException e) {
trace.exception(CLASS_NAME, methodName, e);
}
}
trace.exit(CLASS_NAME, methodName);
}
I'm totally guessing that the connection is timing out between the time
this method is called and when I make the following zk method calls. Is
there a best practise for ensuring one is connected to ZooKeeper? My
session timeout is 3000 ms.
Chris
|