hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkris...@apache.org
Subject svn commit: r1195998 - in /hbase/branches/0.90: ./ src/main/java/org/apache/hadoop/hbase/client/ src/main/java/org/apache/hadoop/hbase/ipc/ src/main/java/org/apache/hadoop/hbase/regionserver/ src/main/ruby/hbase/ src/main/ruby/shell/commands/ src/test/...
Date Tue, 01 Nov 2011 13:54:38 GMT
Author: ramkrishna
Date: Tue Nov  1 13:54:38 2011
New Revision: 1195998

URL: http://svn.apache.org/viewvc?rev=1195998&view=rev
Log:
HBASE-4277 HRS.closeRegion should be able to close regions with only the encoded name (Ram)

Modified:
    hbase/branches/0.90/CHANGES.txt
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/branches/0.90/src/main/ruby/hbase/admin.rb
    hbase/branches/0.90/src/main/ruby/shell/commands/close_region.rb
    hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java

Modified: hbase/branches/0.90/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/CHANGES.txt?rev=1195998&r1=1195997&r2=1195998&view=diff
==============================================================================
--- hbase/branches/0.90/CHANGES.txt (original)
+++ hbase/branches/0.90/CHANGES.txt Tue Nov  1 13:54:38 2011
@@ -86,6 +86,7 @@ Release 0.90.5 - Unreleased
    HBASE-4378  [hbck] Does not complain about regions with startkey==endkey.
                (Jonathan Hsieh)
    HBASE-4508  Backport HBASE-3777 to 0.90 branch (Bright Fulton)
+   HBASE-4277  HRS.closeRegion should be able to close regions with only the encoded name
(Ram)
 
   IMPROVEMENT
    HBASE-4205  Enhance HTable javadoc (Eric Charles)

Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1195998&r1=1195997&r2=1195998&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Tue Nov
 1 13:54:38 2011
@@ -823,6 +823,44 @@ public class HBaseAdmin implements Abort
       cleanupCatalogTracker(ct);
     }
   }
+  /**
+   * For expert-admins. Runs close on the regionserver. Closes a region based on
+   * the encoded region name. The region server name is mandatory. If the
+   * servername is provided then based on the online regions in the specified
+   * regionserver the specified region will be closed. The master will not be
+   * informed of the close. Note that the regionname is the encoded regionname.
+   * 
+   * @param encodedRegionName
+   *          The encoded region name; i.e. the hash that makes up the region
+   *          name suffix: e.g. if regionname is
+   *          <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>
+   *          , then the encoded region name is:
+   *          <code>527db22f95c8a9e0116f0cc13c680396</code>.
+   * @param serverName
+   *          The servername of the regionserver. A server name is made of host
+   *          and port. This is mandatory. Here is an example:
+   *          <code> host187.example.com:60020</code>
+   * @return true if the region was closed, false if not.
+   * @throws IOException
+   *           if a remote or network exception occurs
+   */
+  public boolean closeRegionWithEncodedRegionName(
+      final String encodedRegionName, final String serverName)
+      throws IOException {
+    byte[] encodedRegionNameInBytes = Bytes.toBytes(encodedRegionName);
+    if (null == serverName || ("").equals(serverName.trim())) {
+      throw new IllegalArgumentException(
+          "The servername cannot be null or empty.");
+    }
+    HServerAddress hsa = new HServerAddress(serverName);
+    HRegionInterface rs = this.connection.getHRegionConnection(hsa, true);
+    // Close the region without updating zk state.
+    boolean regionClosed = rs.closeRegion(encodedRegionNameInBytes, false);
+    if (false == regionClosed) {
+      LOG.error("Not able to close the region " + encodedRegionName + ".");
+    }
+    return regionClosed;
+  }
 
   public void closeRegion(final HServerAddress hsa, final HRegionInfo hri)
   throws IOException {

Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java?rev=1195998&r1=1195997&r2=1195998&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java (original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java Tue
Nov  1 13:54:38 2011
@@ -343,6 +343,20 @@ public interface HRegionInterface extend
   public boolean closeRegion(final HRegionInfo region, final boolean zk)
   throws IOException;
 
+  /**
+   * Closes the region in the RS with the specified encoded regionName and will
+   * use or not use ZK during the close according to the specified flag. Note
+   * that the encoded region name is in byte format.
+   * 
+   * @param encodedRegionName
+   *          in bytes
+   * @param zk
+   *          true if to use zookeeper, false if need not.
+   * @return true if region is closed, false if not.
+   * @throws IOException
+   */
+  public boolean closeRegion(byte[] encodedRegionName, final boolean zk)
+      throws IOException;
   // Region administrative methods
 
   /**

Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1195998&r1=1195997&r2=1195998&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Tue Nov  1 13:54:38 2011
@@ -2159,6 +2159,37 @@ public class HRegionServer implements HR
     }
     return closeRegion(region, false, zk);
   }
+  
+  @Override
+  @QosPriority(priority = HIGH_QOS)
+  public boolean closeRegion(byte[] encodedRegionName, boolean zk)
+      throws IOException {
+    return closeRegion(encodedRegionName, false, zk);
+  }
+  
+  /**
+   * @param encodedRegionName
+   *          encodedregionName to close
+   * @param abort
+   *          True if we are aborting
+   * @param zk
+   *          True if we are to update zk about the region close; if the close
+   *          was orchestrated by master, then update zk. If the close is being
+   *          run by the regionserver because its going down, don't update zk.
+   * @return True if closed a region.
+   */
+  protected boolean closeRegion(byte[] encodedRegionName, final boolean abort,
+      final boolean zk) throws IOException {
+    String encodedRegionNameStr = Bytes.toString(encodedRegionName);
+    HRegion region = this.getFromOnlineRegions(encodedRegionNameStr);
+    if (null != region) {
+      return closeRegion(region.getRegionInfo(), abort, zk);
+    }
+    LOG
+        .error("Unable to close the region " + encodedRegionNameStr
+            + ".  The specified region does not exist.");
+    return false;
+  }
 
   /**
    * @param region Region to close

Modified: hbase/branches/0.90/src/main/ruby/hbase/admin.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/ruby/hbase/admin.rb?rev=1195998&r1=1195997&r2=1195998&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/ruby/hbase/admin.rb (original)
+++ hbase/branches/0.90/src/main/ruby/hbase/admin.rb Tue Nov  1 13:54:38 2011
@@ -159,9 +159,13 @@ module Hbase
     end
 
     #----------------------------------------------------------------------------------------------
-    # Closes a region
-    def close_region(region_name, server = nil)
-      @admin.closeRegion(region_name, server)
+    # Closes a region.
+    # If server name is nil, we presume region_name is full region name (HRegionInfo.getRegionName).
+    # If server name is not nil, we presume it is the region's encoded name (HRegionInfo.getEncodedName)
+    def close_region(region_name, server)
+      if (server == nil || !closeEncodedRegion?(region_name, server))         
+      	@admin.closeRegion(region_name, server)
+      end	
     end
 
     #----------------------------------------------------------------------------------------------
@@ -340,6 +344,12 @@ module Hbase
     end
 
     #----------------------------------------------------------------------------------------------
+    #Is supplied region name is encoded region name
+    def closeEncodedRegion?(region_name, server)
+       @admin.closeRegionWithEncodedRegionName(region_name, server)
+    end   
+
+    #----------------------------------------------------------------------------------------------
     # Return a new HColumnDescriptor made of passed args
     def hcd(arg, htd)
       # String arg, single parameter constructor

Modified: hbase/branches/0.90/src/main/ruby/shell/commands/close_region.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/ruby/shell/commands/close_region.rb?rev=1195998&r1=1195997&r2=1195998&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/ruby/shell/commands/close_region.rb (original)
+++ hbase/branches/0.90/src/main/ruby/shell/commands/close_region.rb Tue Nov  1 13:54:38 2011
@@ -23,12 +23,25 @@ module Shell
     class CloseRegion < Command
       def help
         return <<-EOF
-Close a single region. Optionally specify regionserver. Connects to the
-regionserver and runs close on hosting regionserver.  The close is done
-without the master's involvement (It will not know of the close).  Once
-closed, region will stay closed.  Use assign to reopen/reassign.  Use
-unassign or move to assign the region elsewhere on cluster. Use with
-caution.  For experts only.  Examples:
+Close a single region.  Ask the master to close a region out on the cluster
+or if 'SERVER_NAME' is supplied, ask the designated hosting regionserver to
+close the region directly.  Closing a region, the master expects 'REGIONNAME'
+to be a fully qualified region name.  When asking the hosting regionserver to
+directly close a region, you pass the regions' encoded name only. A region
+name looks like this:
+ 
+ TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.
+
+The trailing period is part of the regionserver name. A region's encoded name
+is the hash at the end of a region name; e.g. 527db22f95c8a9e0116f0cc13c680396 
+(without the period).  A 'SERVER_NAME' is its host and port. For
+example: host187.example.com:60020 (find servername in master ui
+or when you do detailed status in shell).  This command will end up running
+close on the region hosting regionserver.  The close is done without the
+master's involvement (It will not know of the close).  Once closed, region will
+stay closed.  Use assign to reopen/reassign.  Use unassign or move to assign
+the region elsewhere on cluster. Use with caution.  For experts only.
+Examples:
 
   hbase> close_region 'REGIONNAME'
   hbase> close_region 'REGIONNAME', 'REGIONSERVER_IP:PORT'

Modified: hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1195998&r1=1195997&r2=1195998&view=diff
==============================================================================
--- hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Tue Nov
 1 13:54:38 2011
@@ -23,6 +23,7 @@ package org.apache.hadoop.hbase.client;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -51,6 +52,7 @@ import org.apache.hadoop.hbase.executor.
 import org.apache.hadoop.hbase.executor.EventHandler.EventType;
 import org.apache.hadoop.hbase.master.AssignmentManager;
 import org.apache.hadoop.hbase.master.MasterServices;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -802,7 +804,159 @@ public class TestAdmin {
     new HTable(TEST_UTIL.getConfiguration(),
         "testTableNotFoundExceptionWithoutAnyTables");
   }
+  @Test
+  public void testShouldCloseTheRegionBasedOnTheEncodedRegionName()
+      throws Exception {
+    String tbName = "TestHBACloseRegion";
+    byte[] TABLENAME = Bytes.toBytes(tbName);
+    HBaseAdmin admin = createTable(TABLENAME);
+
+    HRegionInfo info = null;
+    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME);
+    List<HRegionInfo> onlineRegions = rs.getOnlineRegions();
+    for (HRegionInfo regionInfo : onlineRegions) {
+      if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
+        info = regionInfo;
+        admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), 
+            rs.getServerInfo().getHostnamePort());
+      }
+    }
+    Thread.sleep(1000);
+    onlineRegions = rs.getOnlineRegions();
+    assertFalse("The region should not be present in online regions list.",
+        onlineRegions.contains(info));
+  }
+
+  @Test
+  public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception {
+    String tbName = "TestCloseRegionIfInvalidRegionName";
+    byte[] TABLENAME = Bytes.toBytes(tbName);
+    HBaseAdmin admin = createTable(TABLENAME);
+
+    HRegionInfo info = null;
+    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME);
+    List<HRegionInfo> onlineRegions = rs.getOnlineRegions();
+    for (HRegionInfo regionInfo : onlineRegions) {
+      if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
+        if (regionInfo.getRegionNameAsString().contains(tbName)) {
+          info = regionInfo;
+          admin.closeRegionWithEncodedRegionName("sample", 
+              rs.getServerInfo().getHostnamePort());
+        }
+      }
+    }
+    onlineRegions = rs.getOnlineRegions();
+    assertTrue("The region should be present in online regions list.",
+        onlineRegions.contains(info));
+  }
+
+  @Test
+  public void testCloseRegionThatFetchesTheHRIFromMeta() throws Exception {
+    String tbName = "TestCloseRegionThatFetchesTheHRIFromMeta";
+    byte[] TABLENAME = Bytes.toBytes(tbName);
+    HBaseAdmin admin = createTable(TABLENAME);
+
+    HRegionInfo info = null;
+    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME);
+    List<HRegionInfo> onlineRegions = rs.getOnlineRegions();
+    for (HRegionInfo regionInfo : onlineRegions) {
+      if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
+
+        if (regionInfo.getRegionNameAsString().contains(tbName)) {
+          info = regionInfo;
+          admin.closeRegion(regionInfo.getRegionNameAsString(), 
+              rs.getServerInfo().getHostnamePort());
+        }
+      }
+    }
+    Thread.sleep(1000);
+    onlineRegions = rs.getOnlineRegions();
+    assertFalse("The region should not be present in online regions list.",
+        onlineRegions.contains(info));
+  }
+
+  @Test
+  public void testCloseRegionWhenServerNameIsNull() throws Exception {
+    String tbName = "TestCloseRegionWhenServerNameIsNull";
+    byte[] TABLENAME = Bytes.toBytes(tbName);
+    HBaseAdmin admin = createTable(TABLENAME);
 
+    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME);
+
+    try {
+      List<HRegionInfo> onlineRegions = rs.getOnlineRegions();
+      for (HRegionInfo regionInfo : onlineRegions) {
+        if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
+          if (regionInfo.getRegionNameAsString().contains(tbName)) {
+            admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(),
+                null);
+          }
+        }
+      }
+      fail("The test should throw exception if the servername passed is null.");
+    } catch (IllegalArgumentException e) {
+    }
+  }
+
+  @Test
+  public void testCloseRegionWhenServerNameIsEmpty() throws Exception {
+    String tbName = "TestHBACloseRegionWhenServerNameIsEmpty";
+    byte[] TABLENAME = Bytes.toBytes(tbName);
+    HBaseAdmin admin = createTable(TABLENAME);
+
+    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME);
+
+    try {
+      List<HRegionInfo> onlineRegions = rs.getOnlineRegions();
+      for (HRegionInfo regionInfo : onlineRegions) {
+        if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
+          if (regionInfo.getRegionNameAsString().contains(tbName)) {
+            admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(),
+                " ");
+          }
+        }
+      }
+      fail("The test should throw exception if the servername passed is empty.");
+    } catch (IllegalArgumentException e) {
+    }
+  }
+
+  @Test
+  public void testCloseRegionWhenEncodedRegionNameIsNotGiven() throws Exception {
+    String tbName = "TestCloseRegionWhenEncodedRegionNameIsNotGiven";
+    byte[] TABLENAME = Bytes.toBytes(tbName);
+    HBaseAdmin admin = createTable(TABLENAME);
+
+    HRegionInfo info = null;
+    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME);
+
+    List<HRegionInfo> onlineRegions = rs.getOnlineRegions();
+    for (HRegionInfo regionInfo : onlineRegions) {
+      if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) {
+        if (regionInfo.getRegionNameAsString().contains(tbName)) {
+          info = regionInfo;
+          admin.closeRegionWithEncodedRegionName(regionInfo.getRegionNameAsString(), 
+              rs.getServerInfo().getHostnamePort());
+        }
+      }
+    }
+    onlineRegions = rs.getOnlineRegions();
+    assertTrue("The region should be present in online regions list.",
+        onlineRegions.contains(info));
+  }
+
+  private HBaseAdmin createTable(byte[] TABLENAME) throws IOException {
+
+    Configuration config = TEST_UTIL.getConfiguration();
+    HBaseAdmin admin = new HBaseAdmin(config);
+
+    HTableDescriptor htd = new HTableDescriptor(TABLENAME);
+    HColumnDescriptor hcd = new HColumnDescriptor("value");
+
+    htd.addFamily(hcd);
+    admin.createTable(htd, null);
+    return admin;
+  }
   @Test
   public void testHundredsOfTable() throws IOException{
     final int times = 100;



Mime
View raw message