Author: [email protected]
Date: Mon Feb 28 12:21:38 2011
New Revision: 851

Log:
[AMDATU-319] Fixed shutdown errors by manually invoking the mutation stage 
shutdown in the stop() method of the daemon service, which normally would be 
invoked by a JVM shutdown hook.

Modified:
   
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/service/CassandraDaemonActivatorImpl.java

Modified: 
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/service/CassandraDaemonActivatorImpl.java
==============================================================================
--- 
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/service/CassandraDaemonActivatorImpl.java
        (original)
+++ 
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/service/CassandraDaemonActivatorImpl.java
        Mon Feb 28 12:21:38 2011
@@ -16,7 +16,13 @@
  */
 package org.amdatu.cassandra.application.service;
 
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
 import org.amdatu.cassandra.application.CassandraConfigurationService;
+import org.apache.cassandra.concurrent.Stage;
+import org.apache.cassandra.concurrent.StageManager;
+import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.Cassandra;
 import org.apache.cassandra.thrift.CassandraDaemon;
@@ -91,7 +97,28 @@
 
     public void stop() {
         m_logService.log(LogService.LOG_INFO, "Shutting down Cassandra 
Daemon");
-        m_daemon.deactivate();
+        
+        try {
+            // NB: Cassandra does not really support shutting down Cassandra 
manually, its termination is implemented
+            // by JVM shutdown hooks. The problem is that a Felix shutdown 
will first stop all bundles and then
+            // send the JVM shutdown. So this means that at the time Cassandra 
is terminated, this bundle is stopped
+            // and so the classloader of this bundle that managed the 
Cassandra classes is already destroyed at that
+            // time. This will result in errors as described in AMDATU-319.
+            // For that reason we perform the part of termination that causes 
these errors right now. This shouldn't
+            // cause any problems, as there is no guaranteed order in which JV 
shutdown hooks are invoked and the
+            // StorageService that contains the shutdown hook with the code 
snippet below verifies if the mutation
+            // stage has already been terminated before terinating it.
+            ThreadPoolExecutor mutationStage = 
StageManager.getStage(Stage.MUTATION);
+            if (!mutationStage.isShutdown()) {
+                mutationStage.shutdown();
+                mutationStage.awaitTermination(1, TimeUnit.SECONDS);
+                CommitLog.instance.shutdownBlocking();
+            }
+        }
+        catch (InterruptedException e) {
+            m_logService.log(LogService.LOG_ERROR, "Could not properly 
terminate Cassandra mutation stage", e);
+        }
+        
         m_daemonHasShutdown = true;
         m_logService.log(LogService.LOG_INFO, "Cassandra Daemon stopped");
     }
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to