我正在尝试一个简单的 zookeeper 示例进行Leader
选举,但总是出现错误并且服务器无法启动。这是我的代码:
public LeaderElection() throws IOException, InterruptedException, KeeperException {
setZk(new ZooKeeper("localhost", TIMEOUT, this));
/* This call gives the problem */
Stat s = getZk().exists(MASTER, this);
if (s == null) {
getZk().create(MASTER, "This node is used for election.".getBytes(),
ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
//wait till SyncConnected Signal is received in process method.
latch.await();
setNodePath(getZk().create(MASTER + NODE, null /*no data yet*/,
ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL));
}
在exists()
通话中我收到错误:
线程“主”org.apache.zookeeper.KeeperException$ConnectionLossException 中的异常:KeeperErrorCode = ConnectionLoss for
请让我知道我错过了什么。我正在使用 zk 3.4.5 版本,并且超时 15K。