You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2012/11/22 01:01:45 UTC

svn commit: r1412369 - in /hbase/branches/0.89-fb: bin/ src/main/java/org/apache/hadoop/hbase/client/ src/main/java/org/apache/hadoop/hbase/ipc/ src/main/java/org/apache/hadoop/hbase/regionserver/

Author: liyin
Date: Thu Nov 22 00:01:43 2012
New Revision: 1412369

URL: http://svn.apache.org/viewvc?rev=1412369&view=rev
Log:
[master] Stop RegionServer from the HBaseAdmin

Author: liyintang

Summary: Previously, we only expose the restart functionality through the rpc call. And it would be more flexible to expose the stop function through the HRegionInterface as well, so that we can stop the RegionServer from the HBaseAdmin.

Test Plan: will test it on dev cluster

Reviewers: kannan, aaiyer

Reviewed By: aaiyer

CC: hbase-eng@

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

Added:
    hbase/branches/0.89-fb/bin/stop_regionserver.rb
Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Added: hbase/branches/0.89-fb/bin/stop_regionserver.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/bin/stop_regionserver.rb?rev=1412369&view=auto
==============================================================================
--- hbase/branches/0.89-fb/bin/stop_regionserver.rb (added)
+++ hbase/branches/0.89-fb/bin/stop_regionserver.rb Thu Nov 22 00:01:43 2012
@@ -0,0 +1,79 @@
+#
+# Copyright The Apache Software Foundation
+#
+# 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.
+#
+# Script will be used to stop a regionserver
+#
+# To see usage for this script, run:
+#
+#  ${HBASE_HOME}/bin/hbase org.jruby.Main stop_regionserver.rb
+#
+include Java
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.hbase.ClusterStatus
+import org.apache.hadoop.hbase.HBaseConfiguration
+import org.apache.hadoop.hbase.HServerInfo
+import org.apache.hadoop.hbase.HServerAddress
+import org.apache.hadoop.hbase.client.HBaseAdmin
+import org.apache.hadoop.hbase.util.Bytes
+import org.apache.hadoop.hbase.HConstants
+import org.apache.commons.logging.LogFactory
+import java.net.InetAddress
+
+# Name of this script
+NAME = "stop_regionserver"
+
+# Print usage for this script
+def usage
+  puts 'Usage: %s.rb' % NAME
+  exit!
+end
+
+# Check arguments
+if ARGV.size > 0
+  usage
+end
+
+
+c = HBaseConfiguration.create()
+c.set("fs.default.name", c.get(HConstants::HBASE_DIR))
+LOG = LogFactory.getLog(NAME)
+admin = HBaseAdmin.new(c)
+hostname = InetAddress.getLocalHost().getHostName()
+port = c.getInt("hbase.regionserver.port", 0)
+if port > 0
+  address = HServerAddress.new(hostname, port)
+else
+  address = nil
+  # get the cluster servers
+  servers = admin.getClusterStatus().getServerInfo()
+
+  servers.each do |server|
+    if server.getServerAddress().getHostname() == InetAddress.getLocalHost().getHostName()
+    address = server.getServerAddress()
+    break
+    end
+  end
+end
+
+if address == nil
+  puts "invalid server"
+  exit
+end
+admin.stopRegionServer(address, "stop from ruby script")
+

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1412369&r1=1412368&r2=1412369&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Thu Nov 22 00:01:43 2012
@@ -1250,6 +1250,23 @@ public class HBaseAdmin {
       LOG.info("Restarting RegionServer" + hsa.toString());
       rs.stopForRestart();
   }
+  
+  /**
+   * Stop the designated RegionServer for a stop.
+   * 
+   * @param hsa
+   *          the address of the RegionServer to stop
+   * @para message
+   *          the reason to stop the RegionServer
+   * @throws IOException
+   *           if a remote or network exception occurs
+   */
+  public synchronized void stopRegionServer(final HServerAddress hsa, String reason)
+      throws IOException {
+    HRegionInterface rs = this.connection.getHRegionConnection(hsa);
+    LOG.info("Stopping RegionServer" + hsa.toString() + " because " + reason);
+    rs.stop(reason);
+  }
 
   /**
    * @return cluster status
@@ -1306,4 +1323,4 @@ public class HBaseAdmin {
     server.updateConfiguration();
   }
 
-}
\ No newline at end of file
+}

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java?rev=1412369&r1=1412368&r2=1412369&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java Thu Nov 22 00:01:43 2012
@@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.HRegionIn
 import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.hbase.NotServingRegionException;
 import org.apache.hadoop.hbase.Restartable;
+import org.apache.hadoop.hbase.Stoppable;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.MultiAction;
@@ -46,7 +47,7 @@ import org.apache.hadoop.io.MapWritable;
  * <p>NOTE: if you change the interface, you must change the RPC version
  * number in HBaseRPCProtocolVersion
  */
-public interface HRegionInterface extends HBaseRPCProtocolVersion, Restartable {
+public interface HRegionInterface extends HBaseRPCProtocolVersion, Restartable, Stoppable {
   /**
    * Get metainfo about an HRegion
    *
@@ -399,5 +400,14 @@ public interface HRegionInterface extend
    * Update the configuration.
    */
   public void updateConfiguration() throws IOException;
+  
+  /**
+   * Stop this service.
+   * @param why Why we're stopping.
+   */
+  public void stop(String why);
+
+  /** @return why we are stopping */
+  String getStopReason();
 
 }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1412369&r1=1412368&r2=1412369&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Thu Nov 22 00:01:43 2012
@@ -160,7 +160,7 @@ import com.google.common.base.Preconditi
  * the HMaster. There are many HRegionServers in a single HBase deployment.
  */
 public class HRegionServer implements HRegionInterface,
-    HBaseRPCErrorHandler, Runnable, Watcher, Stoppable {
+    HBaseRPCErrorHandler, Runnable, Watcher {
   public static final Log LOG = LogFactory.getLog(HRegionServer.class);
   private static final HMsg REPORT_EXITING = new HMsg(Type.MSG_REPORT_EXITING);
   private static final HMsg REPORT_RESTARTING = new HMsg(
@@ -3462,6 +3462,7 @@ public class HRegionServer implements HR
     return stopRequested.get();
   }
 
+  @Override
   public String getStopReason() {
     return stopReason;
   }