You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 21:13:03 UTC

svn commit: r1182033 - in /hbase/branches/0.89/src/main: java/org/apache/hadoop/hbase/ java/org/apache/hadoop/hbase/client/ java/org/apache/hadoop/hbase/master/ ruby/ ruby/hbase/ ruby/shell/commands/

Author: nspiegelberg
Date: Tue Oct 11 19:13:03 2011
New Revision: 1182033

URL: http://svn.apache.org/viewvc?rev=1182033&view=rev
Log:
Added ability to move a region to a specific region server

Summary:
Added the moveRegion(regionName, regionServer) to HBaseAdmin and the
MOVE_REGION table modification type to HMaster. The HMaster handles
region moves by assigning the specified region server as the preferred
host for the specified region, then closing that region. The preferred
region server will then pick up that region at its next heartbeat. This
functionality is also exposed through the HBase shell's move_region
command.

Test Plan: Tested using HBase shell on a dev cluster.

Reviewers: kranganathan

Reviewed By: kranganathan

CC: hbase-eng@lists, kranganathan, cgist

Differential Revision: 334698

Task ID: 735411

Added:
    hbase/branches/0.89/src/main/ruby/shell/commands/move_region.rb
Modified:
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/branches/0.89/src/main/ruby/hbase/admin.rb
    hbase/branches/0.89/src/main/ruby/shell.rb

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java?rev=1182033&r1=1182032&r2=1182033&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/HConstants.java Tue Oct 11 19:13:03 2011
@@ -306,6 +306,7 @@ public final class HConstants {
   /** modifyTable op for replacing the table descriptor */
   public static enum Modify {
     CLOSE_REGION,
+    MOVE_REGION,
     TABLE_COMPACT,
     TABLE_FLUSH,
     TABLE_MAJOR_COMPACT,

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1182033&r1=1182032&r2=1182033&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Tue Oct 11 19:13:03 2011
@@ -787,6 +787,37 @@ public class HBaseAdmin {
   }
 
   /**
+   * Move a region. For expert-admins.
+   * Asynchronous operation. Region will be be assigned to the specified
+   * preferred host, then closed.
+   *
+   * @param regionName region name to move
+   * @param regionServer the "hostname:port" of the region server to which to
+   * move the region
+   * @throws IOException if a remote or network exception occurs
+   */
+  public void moveRegion(final String regionName, final String regionServer)
+  throws IOException {
+    moveRegion(Bytes.toBytes(regionName), regionServer);
+  }
+
+  /**
+   * Move a region. For expert-admins.
+   * Asynchronous operation. Region will be be assigned to the specified
+   * preferred host, then closed.
+   *
+   * @param regionName region name to move
+   * @param regionServer the "hostname:port" of the region server to which to
+   * move the region
+   * @throws IOException if a remote or network exception occurs
+   */
+  public void moveRegion(final byte[] regionName, final String regionServer)
+  throws IOException {
+    modifyTable(HConstants.META_TABLE_NAME, HConstants.Modify.MOVE_REGION,
+      new Object[]{regionName, regionServer});
+  }
+
+  /**
    * Flush a table or an individual region.
    * Asynchronous operation.
    *
@@ -1114,6 +1145,10 @@ public class HBaseAdmin {
         this.master.modifyTable(tableName, op, arr);
         break;
 
+      case MOVE_REGION:
+        if (args == null || args.length < 2) {
+          throw new IllegalArgumentException("Requires at least a region name and hostname");
+        }
       case CLOSE_REGION:
         if (args == null || args.length < 1) {
           throw new IllegalArgumentException("Requires at least a region name");

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1182033&r1=1182032&r2=1182033&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Tue Oct 11 19:13:03 2011
@@ -1366,6 +1366,27 @@ public class HMaster extends Thread impl
       }
       break;
 
+    case MOVE_REGION: {
+      if (args == null || args.length != 2) {
+        throw new IOException("Requires a region name and a hostname");
+      }
+      // Arguments are region name and an region server hostname.
+      byte [] regionname = ((ImmutableBytesWritable)args[0]).get();
+
+      // Need hri
+      Result rr = getFromMETA(regionname, HConstants.CATALOG_FAMILY);
+      HRegionInfo hri = getHRegionInfo(rr.getRow(), rr);
+      String hostnameAndPort = Bytes.toString(((ImmutableBytesWritable)args[1]).get());
+      HServerAddress serverAddress = new HServerAddress(hostnameAndPort);
+
+      // Assign the specified host to be the preferred host for the specified region.
+      this.regionManager.addRegionToPreferredAssignment(serverAddress, hri);
+
+      // Close the region so that it will be re-opened by the preferred host.
+      modifyTable(tableName, HConstants.Modify.CLOSE_REGION, new Writable[]{args[0]});
+      break;
+    }
+
     case CLOSE_REGION:
       if (args == null || args.length < 1 || args.length > 2) {
         throw new IOException("Requires at least a region name; " +

Modified: hbase/branches/0.89/src/main/ruby/hbase/admin.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/ruby/hbase/admin.rb?rev=1182033&r1=1182032&r2=1182033&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/ruby/hbase/admin.rb (original)
+++ hbase/branches/0.89/src/main/ruby/hbase/admin.rb Tue Oct 11 19:13:03 2011
@@ -168,6 +168,12 @@ module Hbase
     end
 
     #----------------------------------------------------------------------------------------------
+    # Moves a region
+    def move_region(region_name, server)
+      @admin.moveRegion(region_name, server)
+    end
+
+    #----------------------------------------------------------------------------------------------
     # Enables a region
     def enable_region(region_name)
       online(region_name, false)

Modified: hbase/branches/0.89/src/main/ruby/shell.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/ruby/shell.rb?rev=1182033&r1=1182032&r2=1182033&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/ruby/shell.rb (original)
+++ hbase/branches/0.89/src/main/ruby/shell.rb Tue Oct 11 19:13:03 2011
@@ -251,6 +251,7 @@ Shell.load_command_group(
     enable_region
     flush
     major_compact
+    move_region
     shutdown
     split
     zk

Added: hbase/branches/0.89/src/main/ruby/shell/commands/move_region.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/ruby/shell/commands/move_region.rb?rev=1182033&view=auto
==============================================================================
--- hbase/branches/0.89/src/main/ruby/shell/commands/move_region.rb (added)
+++ hbase/branches/0.89/src/main/ruby/shell/commands/move_region.rb Tue Oct 11 19:13:03 2011
@@ -0,0 +1,39 @@
+#
+# Copyright 2010 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.
+#
+
+module Shell
+  module Commands
+    class MoveRegion < Command
+      def help
+        return <<-EOF
+          Move a single region to a specific regionserver.
+          Examples:
+            hbase> move_region 'REGIONNAME', 'REGIONSERVER_NAME:PORT'
+        EOF
+      end
+
+      def command(region_name, server)
+        format_simple_command do
+          admin.move_region(region_name, server)
+        end
+      end
+    end
+  end
+end