2016-09-29 3 views
0

私はZookeeperに接続するためにキュレーターを使用しています。飼育係が利用できない状況で、私は常にこのようなイベントを取得しています:キュレーターとZookeeperとの接続遅延を設定する方法は、1秒ごとにpingを実行しないのですか?

2016-09-29 12:54:22.831 INFO 43937 --- [localhost:2181)] 
org.apache.zookeeper.ClientCnxn   : Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) 
2016-09-29 12:54:22.832 WARN 43937 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn   : Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect 

java.net.ConnectException: Connection refused 
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) 
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) 
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361) 
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081) 

2016-09-29 12:54:23.940 INFO 43937 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn   : Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) 
2016-09-29 12:54:23.940 WARN 43937 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn   : Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect 

java.net.ConnectException: Connection refused 
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) 
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) 
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361) 
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081) 

私はそう頻繁に起こらないために、この動作を設定することができる場所を見つけることができません。 CuratorFrameworkで設定できるRetryPolicyは、初めてZookeeperに接続しようとしているときは考慮されていません。どんなアドバイスですか?私はスレッドが毎秒接続をチェックしないようにしたいと思いますが、それほど頻繁にはしませんし、理想的には指数ポリシーに適合させることもできます。

答えて

0

私はそれを設定する方法がないと理解しています。クラスClientCnxnSocketからのコードがあります:「>>>>>>>>>>>>>>>>>>>」でマークされた行で

@Override 
    public void run() { 
     clientCnxnSocket.introduce(this,sessionId); 
     clientCnxnSocket.updateNow(); 
     clientCnxnSocket.updateLastSendAndHeard(); 
     int to; 
     long lastPingRwServer = System.currentTimeMillis(); 
     final int MAX_SEND_PING_INTERVAL = 10000; //10 seconds 
     while (state.isAlive()) { 
      try { 
       if (!clientCnxnSocket.isConnected()) { 
        if(!isFirstConnect){ 
         try { 
     >>>>>>>>>>>>>>>>>>>Thread.sleep(r.nextInt(1000)); 
         } catch (InterruptedException e) { 
          LOG.warn("Unexpected exception", e); 
         } 
        } 
        // don't re-establish connection if we are closing 
        if (closing || !state.isAlive()) { 
         break; 
        } 
        startConnect(); 
        clientCnxnSocket.updateLastSendAndHeard(); 
       } 

見て、私はこの場所で考えるの次に待って起こります試してみる。

+0

はい、私はそのクラスをデバッグしていましたが、実際にはパスではなく、コードが実行されました(ブール値のフラグisFirstConnectは「true」でした)。 〜1秒ごとに起こっている唯一の理由は、後で行われるネイティブpingコールです。 – dmydlarz

関連する問題