hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From li...@apache.org
Subject svn commit: r1411940 - in /hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase: client/HConnectionManager.java regionserver/ShutdownHook.java
Date Wed, 21 Nov 2012 00:02:33 GMT
Author: liyin
Date: Wed Nov 21 00:02:32 2012
New Revision: 1411940

URL: http://svn.apache.org/viewvc?rev=1411940&view=rev
Log:
[HBASE-7195] [0.89-fb] Ensure proper ordering for shutdown hooks

Author: aaiyer

Summary:
It looks like HConnectionManager wants a shutdown hook to ensure that
connections are closed properly.

ShutdownHook installled by RegionServer needs to clean up regions.

Currently, both are installed, and java guarantees no ordering -- leading
to RS not being able to talk to the Master.

This is to enforce a determinstic ordering (clean up HCM after SDH)

Test Plan:
unit tests. deploy and ensure that
"hadoopctl stop regionserver" using kill
works correctly

Reviewers: liyintang, kannan

Reviewed By: kannan

CC: hbase-eng@

Differential Revision: https://phabricator.fb.com/D634197

Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ShutdownHook.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1411940&r1=1411939&r2=1411940&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
Wed Nov 21 00:02:32 2012
@@ -101,13 +101,15 @@ import org.apache.zookeeper.Watcher.Even
 @SuppressWarnings("serial")
 public class HConnectionManager {
   // Register a shutdown hook, one that cleans up RPC and closes zk sessions.
+  public static final Thread shutdownHook = new Thread("HCM.shutdownHook") {
+    @Override
+    public void run() {
+      HConnectionManager.deleteAllConnections();
+    }
+  };
+
   static {
-    Runtime.getRuntime().addShutdownHook(new Thread("HCM.shutdownHook") {
-      @Override
-      public void run() {
-        HConnectionManager.deleteAllConnections();
-      }
-    });
+    Runtime.getRuntime().addShutdownHook(shutdownHook);
   }
 
   /*

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ShutdownHook.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ShutdownHook.java?rev=1411940&r1=1411939&r2=1411940&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ShutdownHook.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ShutdownHook.java
Wed Nov 21 00:02:32 2012
@@ -28,6 +28,7 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.client.HConnectionManager;
 import org.apache.hadoop.hbase.util.Threads;
 
 /**
@@ -72,6 +73,9 @@ class ShutdownHook {
       final Stoppable stop, final Thread threadToJoin) {
     Thread fsShutdownHook = suppressHdfsShutdownHook(fs);
     Thread t = new ShutdownHookThread(conf, stop, threadToJoin, fsShutdownHook);
+    // Let us not do the client side shutdown hook. Deleting all connections
+    // will be done at the end or the run.
+    Runtime.getRuntime().removeShutdownHook(HConnectionManager.shutdownHook);
     Runtime.getRuntime().addShutdownHook(t);
     LOG.info("Installed shutdown hook thread: " + t.getName());
   }
@@ -108,6 +112,13 @@ class ShutdownHook {
           Threads.shutdown(this.fsShutdownHook,
             this.conf.getLong(FS_SHUTDOWN_HOOK_WAIT, 30000));
         }
+        if (HConnectionManager.shutdownHook != null) {
+          LOG.info("Starting HConnectionManager shutdown hook thread.");
+          HConnectionManager.shutdownHook.start();
+          long timeout = 10000; // 10 sec
+          Threads.shutdown(HConnectionManager.shutdownHook,
+            timeout);
+        }
       }
       LOG.info("Shutdown hook finished.");
     }



Mime
View raw message