zk的KeeperErrorCode = ConnectionLoss错误

额,这东西都快把人搞崩溃了,各种排查各种正常。

最后竟然是因为我在客户端未连接上zkserver的时候就进行了create操作造成的错误。

噗, 

Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /servers/server
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:99)
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
    at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:778)
    at com.example.test.zk.DistributeServer.registerServer(DistributeServer.java:44)
    at com.example.test.zk.DistributeServer.main(DistributeServer.java:66)

上面这样的错误,在我随便加了一个sleep操作,之后就正常了。

如下:

//        Thread.sleep(10000);
        String create = zk.create(parentNode + "/server", hostname.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
        System.out.println(hostname + "is online.." + create);

 

哎, 贼耽误工夫。

 

posted @ 2018-08-13 14:11  goblinn  阅读(4863)  评论(0编辑  收藏  举报