You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2015/05/08 21:04:45 UTC

cassandra git commit: Fix for harmless exceptions being logged as ERROR

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 d8b79d5af -> 9e9846e73


Fix for harmless exceptions being logged as ERROR

Patch by tjake; reviewed by thobbs for CASSANDRA-8564


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/9e9846e7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/9e9846e7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/9e9846e7

Branch: refs/heads/cassandra-2.1
Commit: 9e9846e73d2e9c702c8652d9e8744de31923ef6d
Parents: d8b79d5
Author: T Jake Luciani <ja...@apache.org>
Authored: Thu May 7 16:22:56 2015 -0400
Committer: T Jake Luciani <ja...@apache.org>
Committed: Fri May 8 15:03:22 2015 -0400

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../DebuggableScheduledThreadPoolExecutor.java  | 27 ++++++++++++++++++++
 .../cassandra/service/StorageService.java       |  7 +++++
 3 files changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/9e9846e7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 162b34f..4a9b34a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.6
+ * Fix for harmless exceptions logged as ERROR (CASSANDRA-8564)
  * Delete processed sstables in sstablesplit/sstableupgrade (CASSANDRA-8606)
  * Improve sstable exclusion from partition tombstones (CASSANDRA-9298)
  * Validate the indexed column rather than the cell's contents for 2i (CASSANDRA-9057)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9e9846e7/src/java/org/apache/cassandra/concurrent/DebuggableScheduledThreadPoolExecutor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/concurrent/DebuggableScheduledThreadPoolExecutor.java b/src/java/org/apache/cassandra/concurrent/DebuggableScheduledThreadPoolExecutor.java
index a301923..7226db8 100644
--- a/src/java/org/apache/cassandra/concurrent/DebuggableScheduledThreadPoolExecutor.java
+++ b/src/java/org/apache/cassandra/concurrent/DebuggableScheduledThreadPoolExecutor.java
@@ -19,6 +19,10 @@ package org.apache.cassandra.concurrent;
 
 import java.util.concurrent.*;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.JVMStabilityInspector;
 
 /**
@@ -30,19 +34,42 @@ import org.apache.cassandra.utils.JVMStabilityInspector;
  */
 public class DebuggableScheduledThreadPoolExecutor extends ScheduledThreadPoolExecutor
 {
+    private static final Logger logger = LoggerFactory.getLogger(DebuggableScheduledThreadPoolExecutor.class);
+
+    public static final RejectedExecutionHandler rejectedExecutionHandler = new RejectedExecutionHandler()
+    {
+        public void rejectedExecution(Runnable task, ThreadPoolExecutor executor)
+        {
+            if (executor.isShutdown())
+            {
+                if (!StorageService.instance.isInShutdownHook())
+                    throw new RejectedExecutionException("ScheduledThreadPoolExecutor has shut down.");
+
+                logger.debug("ScheduledThreadPoolExecutor has shut down as part of C* shutdown");
+            }
+            else
+            {
+                throw new AssertionError("Unknown rejection of ScheduledThreadPoolExecutor task");
+            }
+        }
+    };
+
     public DebuggableScheduledThreadPoolExecutor(int corePoolSize, String threadPoolName, int priority)
     {
         super(corePoolSize, new NamedThreadFactory(threadPoolName, priority));
+        setRejectedExecutionHandler(rejectedExecutionHandler);
     }
 
     public DebuggableScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory)
     {
         super(corePoolSize, threadFactory);
+        setRejectedExecutionHandler(rejectedExecutionHandler);
     }
 
     public DebuggableScheduledThreadPoolExecutor(String threadPoolName)
     {
         this(1, threadPoolName, Thread.NORM_PRIORITY);
+        setRejectedExecutionHandler(rejectedExecutionHandler);
     }
 
     // We need this as well as the wrapper for the benefit of non-repeating tasks

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9e9846e7/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index 8521256..7f9259c 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -200,9 +200,15 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
     public volatile VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(getPartitioner());
 
     private Thread drainOnShutdown = null;
+    private boolean inShutdownHook = false;
 
     public static final StorageService instance = new StorageService();
 
+    public boolean isInShutdownHook()
+    {
+        return inShutdownHook;
+    }
+
     public static IPartitioner getPartitioner()
     {
         return DatabaseDescriptor.getPartitioner();
@@ -652,6 +658,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
             @Override
             public void runMayThrow() throws InterruptedException
             {
+                inShutdownHook = true;
                 ExecutorService counterMutationStage = StageManager.getStage(Stage.COUNTER_MUTATION);
                 ExecutorService mutationStage = StageManager.getStage(Stage.MUTATION);
                 if (mutationStage.isShutdown() && counterMutationStage.isShutdown())