问题一

1,现象

    zookeeper版本是3.4.5

Unexpected Exception:
java.nio.channels.CancelledKeyException
at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55)
at sun.nio.ch.SelectionKeyImpl.interestOps(SelectionKeyImpl.java:59)
at org.apache.zookeeper.server.NIOServerCnxn.sendBuffer(NIOServerCnxn.java:418)
at org.apache.zookeeper.server.NIOServerCnxn.sendResponse(NIOServerCnxn.java:1509)
at org.apache.zookeeper.server.FinalRequestProcessor.processRequest(FinalRequestProcessor.java:367)
at org.apache.zookeeper.server.quorum.CommitProcessor.run(CommitProcessor.java:73)

2,解决,3.4.5及以前版本存在这个问题

    从官网找到对应补丁,见附件,由于不支持附件,直接贴内容

   

diff -uwp zookeeper-3.4.5/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java.ZK1237 zookeeper-3.4.5/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
--- zookeeper-3.4.5/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java.ZK1237	2012-09-30 10:53:32.000000000 -0700
+++ zookeeper-3.4.5/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java	2013-08-07 13:20:19.227152865 -0700
@@ -150,7 +150,8 @@ public class NIOServerCnxn extends Serve
                 // We check if write interest here because if it is NOT set,
                 // nothing is queued, so we can try to send the buffer right
                 // away without waking up the selector
-                if ((sk.interestOps() & SelectionKey.OP_WRITE) == 0) {
+                if (sk.isValid() &&
+                    (sk.interestOps() & SelectionKey.OP_WRITE) == 0) {
                     try {
                         sock.write(bb);
                     } catch (IOException e) {
@@ -214,14 +215,18 @@ public class NIOServerCnxn extends Serve
 
                 return;
             }
-            if (k.isReadable()) {
+            if (k.isValid() && k.isReadable()) {
                 int rc = sock.read(incomingBuffer);
                 if (rc < 0) {
-                    throw new EndOfStreamException(
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug(
                             "Unable to read additional data from client sessionid 0x"
                             + Long.toHexString(sessionId)
                             + ", likely client has closed socket");
                 }
+                    close();
+                    return;
+                }
                 if (incomingBuffer.remaining() == 0) {
                     boolean isPayload;
                     if (incomingBuffer == lenBuffer) { // start of next request
@@ -242,7 +247,7 @@ public class NIOServerCnxn extends Serve
                     }
                 }
             }
-            if (k.isWritable()) {
+            if (k.isValid() && k.isWritable()) {
                 // ZooLog.logTraceMessage(LOG,
                 // ZooLog.CLIENT_DATA_PACKET_TRACE_MASK
                 // "outgoingBuffers.size() = " +

3,安装补丁

      复制上面的被丁内容到一个文件,假定为zookeeper-3.4.5-ZK1237.patch,在 NIOServerCnxn.java所在的路径zookeeper-3.4.5/src/java/main/org/apache/zookeeper/server执行下面命令,将补丁打进源码

     #patch NIOServerCnxn.java zookeeper-3.4.5-ZK1237.patch

     #返回到zookeeper-3.4.5执行ant,重新源码

    重启zookeeper,即可


问题二

   1,现象

    libkafka打印I0105 14:02:04.527153  7142 KafkaConsumingManager.cpp:94] ********ConumingProcessor is running********
btp-0x00001:140533781387008
2017-01-05 14:02:04,536:7138(0x7fd093fe8700):ZOO_DEBUG@zookeeper_process@2260: Got ping response in 0 ms
2017-01-05 14:02:06,536:7138(0x7fd093fe8700):ZOO_DEBUG@do_io@446: IO thread terminated
2017-01-05 14:02:06,537:7138(0x7fd0935e7700):ZOO_DEBUG@do_completion@469: completion thread terminated
2017-01-05 14:02:06,537:7138(0x7fd091fe4700):ZOO_INFO@zookeeper_close@2507: Closing zookeeper sessionId=0x1596d3612730001 to [192.168.1.71:2181]

   2,解决办法,watcher注册了两次,注册一次搞定

  问题三

1,现象

    zookeeper重启以后出现下面问题

2017-04-21 14:21:41,009 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2017-04-21 14:21:41,009 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2017-04-21 14:21:41,019 [myid:1] - INFO  [main:QuorumPeerMain@127] - Starting quorum peer
2017-04-21 14:21:41,028 [myid:1] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:2181
2017-04-21 14:21:41,042 [myid:1] - INFO  [main:QuorumPeer@913] - tickTime set to 2000
2017-04-21 14:21:41,042 [myid:1] - INFO  [main:QuorumPeer@933] - minSessionTimeout set to 10000
2017-04-21 14:21:41,043 [myid:1] - INFO  [main:QuorumPeer@944] - maxSessionTimeout set to 120000
2017-04-21 14:21:41,043 [myid:1] - INFO  [main:QuorumPeer@959] - initLimit set to 10
2017-04-21 14:21:41,092 [myid:1] - INFO  [main:FileSnap@83] - Reading snapshot /export/distributed/zookeeper/data/version-2/snapshot.1800000f7c
2017-04-21 14:21:41,235 [myid:1] - ERROR [main:FileTxnSnapLog@210] - Parent /hbase/replication/rs/M-192-168-1-71,60020,1476845967944 missing for /hbase/repli
cation/rs/M-192-168-1-71,60020,1476845967944/lock
2017-04-21 14:21:41,236 [myid:1] - ERROR [main:QuorumPeer@453] - Unable to load database on disk
java.io.IOException: Failed to process transaction type: 1 error: KeeperErrorCode = NoNode for /hbase/replication/rs/M-192-168-1-71,60020,1476845967944
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.restore(FileTxnSnapLog.java:153)
        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:151)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:111)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
Caused by: org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /hbase/replication/rs/M-192-168-1-71,60020,1476845967944
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.processTransaction(FileTxnSnapLog.java:211)
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.restore(FileTxnSnapLog.java:151)
        ... 6 more
2017-04-21 14:21:41,237 [myid:1] - ERROR [main:QuorumPeerMain@89] - Unexpected exception, exiting abnormally
java.lang.RuntimeException: Unable to run quorum server
        at org.apache.zookeeper.server.quorum.QuorumPeer.loadDataBase(QuorumPeer.java:454)
        at org.apache.zookeeper.server.quorum.QuorumPeer.start(QuorumPeer.java:409)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:151)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:111)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
Caused by: java.io.IOException: Failed to process transaction type: 1 error: KeeperErrorCode = NoNode for /hbase/replication/rs/M-192-168-1-71,60020,14768459
67944
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.restore(FileTxnSnapLog.java:153)
        at org.apache.zookeeper.server.ZKDatabase.loadDataBase(ZKDatabase.java:223)
        at org.apache.zookeeper.server.quorum.QuorumPeer.loadDataBase(QuorumPeer.java:417)
        ... 4 more
Caused by: org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /hbase/replication/rs/M-192-168-1-71,60020,1476845967944
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.processTransaction(FileTxnSnapLog.java:211)
        at org.apache.zookeeper.server.persistence.FileTxnSnapLog.restore(FileTxnSnapLog.java:151)

 2,解决

      从zookeeper的data目录中找到version-2目录,清空后重启即可
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐