zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1686289 - in /zookeeper/branches/branch-3.4: ./ src/java/main/org/apache/zookeeper/ src/java/main/org/apache/zookeeper/server/ src/java/main/org/apache/zookeeper/server/quorum/ src/java/test/config/ src/java/test/org/apache/zookeeper/server/
Date Thu, 18 Jun 2015 18:58:49 GMT
Author: rgs
Date: Thu Jun 18 18:58:48 2015
New Revision: 1686289

URL: http://svn.apache.org/r1686289
Log:
ZOOKEEPER-602: log all exceptions not caught by ZK threads
(Rakesh R via rgs)

Added:
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperCriticalThread.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperThread.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperThreadTest.java
Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ClientCnxn.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java
    zookeeper/branches/branch-3.4/src/java/test/config/findbugsExcludeFile.xml

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Thu Jun 18 18:58:48 2015
@@ -96,6 +96,9 @@ BUGFIXES:
   ZOOKEEPER-706: Large numbers of watches can cause session re-establishment to fail
   (Chris Thunes via rgs)
 
+  ZOOKEEPER-602: log all exceptions not caught by ZK threads
+  (Rakesh R via rgs)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1575. adding .gitattributes to prevent CRLF and LF mismatches for

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ClientCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ClientCnxn.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ClientCnxn.java (original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ClientCnxn.java Thu Jun
18 18:58:48 2015
@@ -74,6 +74,7 @@ import org.apache.zookeeper.proto.SetDat
 import org.apache.zookeeper.proto.SetWatches;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.server.ByteBufferInputStream;
+import org.apache.zookeeper.server.ZooKeeperThread;
 import org.apache.zookeeper.server.ZooTrace;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -420,13 +421,6 @@ public class ClientCnxn {
 
     private Object eventOfDeath = new Object();
 
-    private final static UncaughtExceptionHandler uncaughtExceptionHandler = new UncaughtExceptionHandler()
{
-        @Override
-        public void uncaughtException(Thread t, Throwable e) {
-            LOG.error("from " + t.getName(), e);
-        }
-    };
-
     private static class WatcherSetEventPair {
         private final Set<Watcher> watchers;
         private final WatchedEvent event;
@@ -448,7 +442,7 @@ public class ClientCnxn {
         return name + suffix;
     }
 
-    class EventThread extends Thread {
+    class EventThread extends ZooKeeperThread {
         private final LinkedBlockingQueue<Object> waitingEvents =
             new LinkedBlockingQueue<Object>();
 
@@ -463,7 +457,6 @@ public class ClientCnxn {
 
         EventThread() {
             super(makeThreadName("-EventThread"));
-            setUncaughtExceptionHandler(uncaughtExceptionHandler);
             setDaemon(true);
         }
 
@@ -711,7 +704,7 @@ public class ClientCnxn {
      * This class services the outgoing request queue and generates the heart
      * beats. It also spawns the ReadThread.
      */
-    class SendThread extends Thread {
+    class SendThread extends ZooKeeperThread {
         private long lastPingSentNs;
         private final ClientCnxnSocket clientCnxnSocket;
         private Random r = new Random(System.nanoTime());        
@@ -840,7 +833,6 @@ public class ClientCnxn {
             super(makeThreadName("-SendThread()"));
             state = States.CONNECTING;
             this.clientCnxnSocket = clientCnxnSocket;
-            setUncaughtExceptionHandler(uncaughtExceptionHandler);
             setDaemon(true);
         }
 

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
Thu Jun 18 18:58:48 2015
@@ -39,11 +39,6 @@ public class NIOServerCnxnFactory extend
     private static final Logger LOG = LoggerFactory.getLogger(NIOServerCnxnFactory.class);
 
     static {
-        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
-                public void uncaughtException(Thread t, Throwable e) {
-                    LOG.error("Thread " + t + " died", e);
-                }
-            });
         /**
          * this is to avoid the jvm bug:
          * NullPointerException in Selector.open()
@@ -86,7 +81,7 @@ public class NIOServerCnxnFactory extend
     public void configure(InetSocketAddress addr, int maxcc) throws IOException {
         configureSaslLogin();
 
-        thread = new Thread(this, "NIOServerCxn.Factory:" + addr);
+        thread = new ZooKeeperThread(this, "NIOServerCxn.Factory:" + addr);
         thread.setDaemon(true);
         maxClientCnxns = maxcc;
         this.ss = ServerSocketChannel.open();

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
Thu Jun 18 18:58:48 2015
@@ -76,7 +76,8 @@ import org.apache.zookeeper.txn.TxnHeade
  * outstandingRequests, so that it can take into account transactions that are
  * in the queue to be applied when generating a transaction.
  */
-public class PrepRequestProcessor extends Thread implements RequestProcessor {
+public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
+        RequestProcessor {
     private static final Logger LOG = LoggerFactory.getLogger(PrepRequestProcessor.class);
 
     static boolean skipACL;

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java
Thu Jun 18 18:58:48 2015
@@ -39,7 +39,7 @@ import org.apache.zookeeper.KeeperExcept
  * period. Sessions are thus expired in batches made up of sessions that expire
  * in a given interval.
  */
-public class SessionTrackerImpl extends Thread implements SessionTracker {
+public class SessionTrackerImpl extends ZooKeeperCriticalThread implements SessionTracker
{
     private static final Logger LOG = LoggerFactory.getLogger(SessionTrackerImpl.class);
 
     HashMap<Long, SessionImpl> sessionsById = new HashMap<Long, SessionImpl>();

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
Thu Jun 18 18:58:48 2015
@@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory;
  *             be null. This change the semantic of txnlog on the observer
  *             since it only contains committed txns.
  */
-public class SyncRequestProcessor extends Thread implements RequestProcessor {
+public class SyncRequestProcessor extends ZooKeeperCriticalThread implements RequestProcessor
{
     private static final Logger LOG = LoggerFactory.getLogger(SyncRequestProcessor.class);
     private final ZooKeeperServer zks;
     private final LinkedBlockingQueue<Request> queuedRequests =
@@ -147,7 +147,7 @@ public class SyncRequestProcessor extend
                             if (snapInProcess != null && snapInProcess.isAlive())
{
                                 LOG.warn("Too busy to snap, skipping");
                             } else {
-                                snapInProcess = new Thread("Snapshot Thread") {
+                                snapInProcess = new ZooKeeperThread("Snapshot Thread") {
                                         public void run() {
                                             try {
                                                 zks.takeSnapshot();
@@ -180,7 +180,7 @@ public class SyncRequestProcessor extend
                 }
             }
         } catch (Throwable t) {
-            LOG.error("Severe unrecoverable error, exiting", t);
+            super.handleException(this.getName(), t);
             running = false;
             System.exit(11);
         }

Added: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperCriticalThread.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperCriticalThread.java?rev=1686289&view=auto
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperCriticalThread.java
(added)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperCriticalThread.java
Thu Jun 18 18:58:48 2015
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.server;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents critical thread. When there is an uncaught exception thrown by the
+ * thread this will exit the system.
+ */
+public class ZooKeeperCriticalThread extends ZooKeeperThread {
+    private static final Logger LOG = LoggerFactory
+            .getLogger(ZooKeeperCriticalThread.class);
+    private static final int DEFAULT_EXIT_CODE = 1;
+
+    public ZooKeeperCriticalThread(String threadName) {
+        super(threadName);
+    }
+
+    /**
+     * This will be used by the uncaught exception handler and make the system
+     * exit.
+     * 
+     * @param thName
+     *            - thread name
+     * @param e
+     *            - exception object
+     */
+    @Override
+    protected void handleException(String thName, Throwable e) {
+        LOG.error("Severe unrecoverable error, from thread : {}", thName, e);
+        System.exit(DEFAULT_EXIT_CODE);
+    }
+}

Added: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperThread.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperThread.java?rev=1686289&view=auto
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperThread.java
(added)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperThread.java
Thu Jun 18 18:58:48 2015
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.server;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This is the main class for catching all the uncaught exceptions thrown by the
+ * threads.
+ */
+public class ZooKeeperThread extends Thread {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(ZooKeeperThread.class);
+
+    private UncaughtExceptionHandler uncaughtExceptionalHandler = new UncaughtExceptionHandler()
{
+
+        @Override
+        public void uncaughtException(Thread t, Throwable e) {
+            handleException(t.getName(), e);
+        }
+    };
+
+    public ZooKeeperThread(Runnable thread, String threadName) {
+        super(thread, threadName);
+        setUncaughtExceptionHandler(uncaughtExceptionalHandler);
+    }
+
+    public ZooKeeperThread(String threadName) {
+        super(threadName);
+        setUncaughtExceptionHandler(uncaughtExceptionalHandler);
+    }
+
+    /**
+     * This will be used by the uncaught exception handler and just log a
+     * warning message and return.
+     * 
+     * @param thName
+     *            - thread name
+     * @param e
+     *            - exception object
+     */
+    protected void handleException(String thName, Throwable e) {
+        LOG.warn("Exception occured from thread {}", thName, e);
+    }
+}

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java
Thu Jun 18 18:58:48 2015
@@ -40,6 +40,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.zookeeper.jmx.MBeanRegistry;
+import org.apache.zookeeper.server.ZooKeeperThread;
 import org.apache.zookeeper.server.quorum.Election;
 import org.apache.zookeeper.server.quorum.Vote;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
@@ -716,7 +717,7 @@ public class AuthFastLeaderElection impl
             lastEpoch = 0;
 
             for (int i = 0; i < threads; ++i) {
-                Thread t = new Thread(new WorkerSender(3),
+                Thread t = new ZooKeeperThread(new WorkerSender(3),
                         "WorkerSender Thread: " + (i + 1));
                 t.setDaemon(true);
                 t.start();
@@ -728,8 +729,8 @@ public class AuthFastLeaderElection impl
                 addrChallengeMap.put(saddr, new ConcurrentHashMap<Long, Long>());
             }
 
-            Thread t = new Thread(new WorkerReceiver(s, this),
-                    "WorkerReceiver Thread");
+            Thread t = new ZooKeeperThread(new WorkerReceiver(s, this),
+                    "WorkerReceiver-" + s.getRemoteSocketAddress());
             t.start();
         }
 

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java
Thu Jun 18 18:58:48 2015
@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.RequestProcessor;
+import org.apache.zookeeper.server.ZooKeeperCriticalThread;
 
 /**
  * This RequestProcessor matches the incoming committed requests with the
@@ -33,7 +34,7 @@ import org.apache.zookeeper.server.Reque
  * change the state of the system will come back as incoming committed requests,
  * so we need to match them up.
  */
-public class CommitProcessor extends Thread implements RequestProcessor {
+public class CommitProcessor extends ZooKeeperCriticalThread implements RequestProcessor
{
     private static final Logger LOG = LoggerFactory.getLogger(CommitProcessor.class);
 
     /**

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
Thu Jun 18 18:58:48 2015
@@ -28,6 +28,7 @@ import java.util.concurrent.LinkedBlocki
 import java.util.concurrent.TimeUnit;
 
 import org.apache.zookeeper.jmx.MBeanRegistry;
+import org.apache.zookeeper.server.ZooKeeperThread;
 import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message;
 import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
@@ -227,11 +228,12 @@ public class FastLeaderElection implemen
          * method run(), and processes such messages.
          */
 
-        class WorkerReceiver implements Runnable {
+        class WorkerReceiver extends ZooKeeperThread {
             volatile boolean stop;
             QuorumCnxManager manager;
 
             WorkerReceiver(QuorumCnxManager manager) {
+                super("WorkerReceiver");
                 this.stop = false;
                 this.manager = manager;
             }
@@ -412,11 +414,12 @@ public class FastLeaderElection implemen
          * and queues it on the manager's queue.
          */
 
-        class WorkerSender implements Runnable {
+        class WorkerSender extends ZooKeeperThread {
             volatile boolean stop;
             QuorumCnxManager manager;
 
             WorkerSender(QuorumCnxManager manager){
+                super("WorkerSender");
                 this.stop = false;
                 this.manager = manager;
             }

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java
Thu Jun 18 18:58:48 2015
@@ -26,13 +26,14 @@ import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.server.RequestProcessor;
 import org.apache.zookeeper.server.Request;
+import org.apache.zookeeper.server.ZooKeeperCriticalThread;
 import org.apache.zookeeper.server.ZooTrace;
 
 /**
  * This RequestProcessor forwards any requests that modify the state of the
  * system to the Leader.
  */
-public class FollowerRequestProcessor extends Thread implements
+public class FollowerRequestProcessor extends ZooKeeperCriticalThread implements
         RequestProcessor {
     private static final Logger LOG = LoggerFactory.getLogger(FollowerRequestProcessor.class);
 

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
Thu Jun 18 18:58:48 2015
@@ -21,7 +21,6 @@ package org.apache.zookeeper.server.quor
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.BindException;
-import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.SocketAddress;
@@ -39,10 +38,10 @@ import java.util.concurrent.ConcurrentLi
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.jute.BinaryOutputArchive;
-import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.FinalRequestProcessor;
 import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.RequestProcessor;
+import org.apache.zookeeper.server.ZooKeeperThread;
 import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
 import org.apache.zookeeper.server.util.ZxidUtils;
@@ -302,9 +301,13 @@ public class Leader {
 
     Proposal newLeaderProposal = new Proposal();
     
-    class LearnerCnxAcceptor extends Thread{
+    class LearnerCnxAcceptor extends ZooKeeperThread{
         private volatile boolean stop = false;
-        
+
+        public LearnerCnxAcceptor() {
+            super("LearnerCnxAcceptor-" + ss.getLocalSocketAddress());
+        }
+
         @Override
         public void run() {
             try {

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java
Thu Jun 18 18:58:48 2015
@@ -39,6 +39,7 @@ import org.apache.zookeeper.KeeperExcept
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.server.ByteBufferInputStream;
 import org.apache.zookeeper.server.Request;
+import org.apache.zookeeper.server.ZooKeeperThread;
 import org.apache.zookeeper.server.ZooTrace;
 import org.apache.zookeeper.server.quorum.Leader.Proposal;
 import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
@@ -53,7 +54,7 @@ import org.slf4j.LoggerFactory;
  * learner. All communication with a learner is handled by this
  * class.
  */
-public class LearnerHandler extends Thread {
+public class LearnerHandler extends ZooKeeperThread {
     private static final Logger LOG = LoggerFactory.getLogger(LearnerHandler.class);
 
     protected final Socket sock;    

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java
Thu Jun 18 18:58:48 2015
@@ -26,13 +26,14 @@ import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.server.RequestProcessor;
 import org.apache.zookeeper.server.Request;
+import org.apache.zookeeper.server.ZooKeeperCriticalThread;
 import org.apache.zookeeper.server.ZooTrace;
 
 /**
  * This RequestProcessor forwards any requests that modify the state of the
  * system to the Leader.
  */
-public class ObserverRequestProcessor extends Thread implements
+public class ObserverRequestProcessor extends ZooKeeperCriticalThread implements
         RequestProcessor {
     private static final Logger LOG = LoggerFactory.getLogger(ObserverRequestProcessor.class);
 

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
Thu Jun 18 18:58:48 2015
@@ -40,6 +40,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.ZooKeeperThread;
 
 /**
  * This class implements a connection manager for leader election using TCP. It
@@ -492,10 +493,16 @@ public class QuorumCnxManager {
     /**
      * Thread to listen on some port
      */
-    public class Listener extends Thread {
+    public class Listener extends ZooKeeperThread {
 
         volatile ServerSocket ss = null;
 
+        public Listener() {
+            // During startup of thread, thread name will be overridden to
+            // specific election address
+            super("ListenerThread");
+        }
+
         /**
          * Sleeps on accept().
          */
@@ -569,7 +576,7 @@ public class QuorumCnxManager {
      * soon as there is one available. If connection breaks, then opens a new
      * one.
      */
-    class SendWorker extends Thread {
+    class SendWorker extends ZooKeeperThread {
         Long sid;
         Socket sock;
         RecvWorker recvWorker;
@@ -723,7 +730,7 @@ public class QuorumCnxManager {
      * Thread to receive messages. Instance waits on a socket read. If the
      * channel breaks, then removes itself from the pool of receivers.
      */
-    class RecvWorker extends Thread {
+    class RecvWorker extends ZooKeeperThread {
         Long sid;
         Socket sock;
         volatile boolean running = true;

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
Thu Jun 18 18:58:48 2015
@@ -41,6 +41,7 @@ import org.apache.zookeeper.jmx.ZKMBeanI
 import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.ZooKeeperThread;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
@@ -75,7 +76,7 @@ import org.slf4j.LoggerFactory;
  *
  * The request for the current leader will consist solely of an xid: int xid;
  */
-public class QuorumPeer extends Thread implements QuorumStats.Provider {
+public class QuorumPeer extends ZooKeeperThread implements QuorumStats.Provider {
     private static final Logger LOG = LoggerFactory.getLogger(QuorumPeer.class);
 
     QuorumBean jmxQuorumBean;
@@ -293,7 +294,7 @@ public class QuorumPeer extends Thread i
      *
      */
     @Deprecated
-    class ResponderThread extends Thread {
+    class ResponderThread extends ZooKeeperThread {
         ResponderThread() {
             super("ResponderThread");
         }

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java
Thu Jun 18 18:58:48 2015
@@ -26,6 +26,7 @@ import org.apache.zookeeper.ZooDefs.OpCo
 import org.apache.zookeeper.proto.ReplyHeader;
 import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.RequestProcessor;
+import org.apache.zookeeper.server.ZooKeeperCriticalThread;
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.ZooTrace;
 import org.apache.zookeeper.server.quorum.Leader.XidRolloverException;
@@ -38,7 +39,7 @@ import org.slf4j.LoggerFactory;
  * OpCode.getData, OpCode.exists) through to the next processor, but drops
  * state-changing operations (e.g. OpCode.create, OpCode.setData).
  */
-public class ReadOnlyRequestProcessor extends Thread implements RequestProcessor {
+public class ReadOnlyRequestProcessor extends ZooKeeperCriticalThread implements RequestProcessor
{
 
     private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyRequestProcessor.class);
 

Modified: zookeeper/branches/branch-3.4/src/java/test/config/findbugsExcludeFile.xml
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/config/findbugsExcludeFile.xml?rev=1686289&r1=1686288&r2=1686289&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/config/findbugsExcludeFile.xml (original)
+++ zookeeper/branches/branch-3.4/src/java/test/config/findbugsExcludeFile.xml Thu Jun 18
18:58:48 2015
@@ -10,8 +10,8 @@
        In particular we want to make sure we exit if this occurs
        Also notice logged as fatal error -->
   <Match>
-    <Class name="org.apache.zookeeper.server.SyncRequestProcessor" />
-    <Method name="run" />
+    <Class name="org.apache.zookeeper.server.ZooKeeperCriticalThread" />
+    <Method name="handleException" />
     <Bug pattern="DM_EXIT" />
   </Match>
 

Added: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperThreadTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperThreadTest.java?rev=1686289&view=auto
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperThreadTest.java
(added)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperThreadTest.java
Thu Jun 18 18:58:48 2015
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.server;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class ZooKeeperThreadTest {
+    private CountDownLatch runningLatch = new CountDownLatch(1);
+
+    public class MyThread extends ZooKeeperThread {
+
+        public MyThread(String threadName) {
+            super(threadName);
+        }
+
+        public void run() {
+            throw new Error();
+        }
+
+        @Override
+        protected void handleException(String thName, Throwable e) {
+            runningLatch.countDown();
+        }
+    }
+
+    public class MyCriticalThread extends ZooKeeperCriticalThread {
+
+        public MyCriticalThread(String threadName) {
+            super(threadName);
+        }
+
+        public void run() {
+            throw new Error();
+        }
+
+        @Override
+        protected void handleException(String thName, Throwable e) {
+            runningLatch.countDown();
+        }
+    }
+
+    /**
+     * Test verifies uncaught exception handling of ZooKeeperThread
+     */
+    @Test(timeout = 30000)
+    public void testUncaughtException() throws Exception {
+        MyThread t1 = new MyThread("Test-Thread");
+        t1.start();
+        Assert.assertTrue("Uncaught exception is not properly handled.",
+                runningLatch.await(10000, TimeUnit.MILLISECONDS));
+
+        runningLatch = new CountDownLatch(1);
+        MyCriticalThread t2 = new MyCriticalThread("Test-Critical-Thread");
+        t2.start();
+        Assert.assertTrue("Uncaught exception is not properly handled.",
+                runningLatch.await(10000, TimeUnit.MILLISECONDS));
+    }
+}



Mime
View raw message