Zookeeper 异常代码:KeeperErrorCode = /lock/test3_node的连接丢失

fsi0uk1n  于 2022-12-09  发布在  Apache
关注(0)|答案(1)|浏览(237)

我使用Curator客户端来操作zookeeper服务器,但是如果我同时启动十个线程来操作zookeeper服务器,总是失败。
如果线程数小于6,它工作正常,当连接丢失时,我必须重新启动zookeeper服务器。有人知道如何解决这个问题吗?

curatorClient = CuratorFrameworkFactory.builder().connectString(zkAddress).sessionTimeoutMs(Constant.ZK_SESSION_TIMEOUT).connectionTimeoutMs(Constant.ZK_CONNECTION_TIMEOUT).retryPolicy(retryPolicy).build();
curatorClient.start();

我做了以下操作:创建一个新的回调函数。(). callback(). callback(). callback(). callback(). callback(). callback(). callback(). callback().锁获取();..
错误:

org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode    
= ConnectionLoss for /lock/test3_node
at org.apache.zookeeper.KeeperException.create(KeeperException.java:99)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1472)
at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1500)
at  

org.apache.curator.framework.imps.CreateBuilderImpl$12.call(CreateBuilderImpl.java:766)
at org.apache.curator.framework.imps.CreateBuilderImpl$12.call(CreateBuilderImpl.java:758)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107)
at org.apache.curator.framework.imps.CreateBuilderImpl.findProtectedNodeInForeground(CreateBuilderImpl.java:754)
at org.apache.curator.framework.imps.CreateBuilderImpl.access$1300(CreateBuilderImpl.java:44)
at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:713)
at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:703)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107)
at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:699)
at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:477)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:467)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:447)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:44)
at org.apache.curator.framework.recipes.locks.StandardLockInternalsDriver.createsTheLock(StandardLockInternalsDriver.java:54)
at org.apache.curator.framework.recipes.locks.LockInternals.attemptLock(LockInternals.java:216)
at org.apache.curator.framework.recipes.locks.InterProcessMutex.internalLock(InterProcessMutex.java:232)
at org.apache.curator.framework.recipes.locks.InterProcessMutex.acquire(InterProcessMutex.java:108)
at 
$InsertQueueCallBack.processResult(CuratorUtil.java:614)
at org.apache.curator.framework.imps.CuratorFrameworkImpl.sendToBackgroundCallback(CuratorFrameworkImpl.java:743)
at org.apache.curator.framework.imps.CuratorFrameworkImpl.processBackgroundOperation(CuratorFrameworkImpl.java:520)
at org.apache.curator.framework.imps.CreateBuilderImpl.sendBackgroundResponse(CreateBuilderImpl.java:565)
at org.apache.curator.framework.imps.CreateBuilderImpl.access$900(CreateBuilderImpl.java:44)
at org.apache.curator.framework.imps.CreateBuilderImpl$6.processResult(CreateBuilderImpl.java:524)
at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:599)
at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:498)
.....
Connection timed out for connection string (slc03nwh.us.oracle.com:2181) and timeout (15000) / elapsed (5380)
org.apache.curator.CuratorConnectionLossException: KeeperErrorCode = ConnectionLoss
at org.apache.curator.ConnectionState.checkTimeouts(ConnectionState.java:195)
at org.apache.curator.ConnectionState.getZooKeeper(ConnectionState.java:87)
at org.apache.curator.CuratorZookeeperClient.getZooKeeper(CuratorZookeeperClient.java:115)
at org.apache.curator.framework.imps.CuratorFrameworkImpl.performBackgroundOperation(CuratorFrameworkImpl.java:821)
at org.apache.curator.framework.imps.CuratorFrameworkImpl.backgroundOperationsLoop(CuratorFrameworkImpl.java:807)
at org.apache.curator.framework.imps.CuratorFrameworkImpl.access$300(CuratorFrameworkImpl.java:63)
at org.apache.curator.framework.imps.CuratorFrameworkImpl$4.call(CuratorFrameworkImpl.java:267)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

然后我添加ConnectionStateListener和UnhandledErrorListener,我得到了以下信息:

newState.isConnected()false
 SUSPENDED
 newState.isConnected()true
 RECONNECTED
 newState.isConnected()lost
 RECONNECTED

  unhandledErrorListener:Background operation retry gave up
  Background retry gave up
whitzsjs

whitzsjs1#

我试着使用单一示例来创建客户端,并将连接超时设置得更长。这个问题已经解决了。
但我并没有找到造成连接丢失错误的根本原因。

相关问题