ZooKeeper运行报错KeeperErrorCode = NoNode for .....

时间:2021-08-28 22:14:01

    最近遇到一个很尴尬的报错,org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode KeeperErrorCode = NoNode for (节点路径)。

java.io.IOException: Failed to process transaction type: 1 error: KeeperErrorCode = NoNode for /cloudera_manager_zookeeper_canary
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.restore(FileTxnSnapLog.java:188)
        at org.apache.zookeeper.server.ZKDatabase.loadDataBase(ZKDatabase.java:223)
        at org.apache.zookeeper.server.quorum.QuorumPeer.loadDataBase(QuorumPeer.java:417)
        at org.apache.zookeeper.server.quorum.QuorumPeer.start(QuorumPeer.java:409)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:156)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:116)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:79)
Caused by: org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /cloudera_manager_zookeeper_canary
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.processTransaction(FileTxnSnapLog.java:250)
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.restore(FileTxnSnapLog.java:186)

    百度后发现关闭ZooKeeper,删除你自己设定的dataDir路径下的version-2文件夹,然后重启即可。


   随着进一步的了解,我突然顿悟!!!

    在每次新建一个节点时,一定要判断该节点(路径)是否存在,因为在ZooKeeper中路径使唯一的,所以当在该路径下已有节点时,继续往当前路径上新建节点就会报这个错。所以删除缓存的version-2文件夹其实就是删除了已经create的节点。

 if (null==zk.exists("/root", false)) {
zk.create("/root", "测试".getBytes(),acls , CreateMode.PERSISTENT);
}