You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2011/12/06 23:15:11 UTC

svn commit: r1211204 - in /hbase/trunk/src: main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/master/ test/java/org/apache/hadoop/hbase/master/ test/java/org/apache/hadoop/hbase/regionserver/

Author: stack
Date: Tue Dec  6 22:15:11 2011
New Revision: 1211204

URL: http://svn.apache.org/viewvc?rev=1211204&view=rev
Log:
HBASE-4927 CatalogJanior:SplitParentFirstComparator doesn't sort as expected, for the last region when the endkey is empty

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java?rev=1211204&r1=1211203&r2=1211204&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java Tue Dec  6 22:15:11 2011
@@ -775,11 +775,14 @@ implements WritableComparable<HRegionInf
 
     // Compare end keys.
     result = Bytes.compareTo(this.endKey, o.endKey);
+
     if (result != 0) {
+      if (this.getEndKey().length == 0) return 1; // this is last region
+      if (o.getEndKey().length == 0) return -1; // o is the last region
       return result;
     }
     if (this.offLine == o.offLine)
-        return 0;
+      return 0;
     if (this.offLine == true) return -1;
         
     return 1;

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java?rev=1211204&r1=1211203&r2=1211204&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java Tue Dec  6 22:15:11 2011
@@ -157,7 +157,11 @@ class CatalogJanitor extends Chore {
       if (result != 0) return result;
       // Compare end keys.
       result = Bytes.compareTo(left.getEndKey(), right.getEndKey());
-      if (result != 0) return -result; // Flip the result so parent comes first.
+      if (result != 0) {
+        if (left.getEndKey().length == 0) return -1;  // left is last region
+        if (right.getEndKey().length == 0) return 1;  // right is the last region
+        return -result; // Flip the result so parent comes first.
+      }
       return result;
     }
   }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java?rev=1211204&r1=1211203&r2=1211204&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java Tue Dec  6 22:15:11 2011
@@ -336,23 +336,50 @@ public class TestCatalogJanitor {
   /**
    * Make sure parent gets cleaned up even if daughter is cleaned up before it.
    * @throws IOException
-   * @throws InterruptedException 
+   * @throws InterruptedException
    */
   @Test
   public void testParentCleanedEvenIfDaughterGoneFirst()
   throws IOException, InterruptedException {
+    parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(
+      "testParentCleanedEvenIfDaughterGoneFirst", Bytes.toBytes("eee"));
+  }
+
+  /**
+   * Make sure last parent with empty end key gets cleaned up even if daughter is cleaned up before it.
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  @Test
+  public void testLastParentCleanedEvenIfDaughterGoneFirst()
+  throws IOException, InterruptedException {
+    parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(
+      "testLastParentCleanedEvenIfDaughterGoneFirst", new byte[0]);
+  }
+
+  /**
+   * Make sure parent with specified end key gets cleaned up even if daughter is cleaned up before it.
+   *
+   * @param rootDir the test case name, used as the HBase testing utility root
+   * @param lastEndKey the end key of the split parent
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  private void parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(
+  final String rootDir, final byte[] lastEndKey)
+  throws IOException, InterruptedException {
     HBaseTestingUtility htu = new HBaseTestingUtility();
-    setRootDirAndCleanIt(htu, "testParentCleanedEvenIfDaughterGoneFirst");
+    setRootDirAndCleanIt(htu, rootDir);
     Server server = new MockServer(htu);
     MasterServices services = new MockMasterServices(server);
     CatalogJanitor janitor = new CatalogJanitor(server, services);
     final HTableDescriptor htd = createHTableDescriptor();
 
-    // Create regions: aaa->eee, aaa->ccc, aaa->bbb, bbb->ccc, etc.
+    // Create regions: aaa->{lastEndKey}, aaa->ccc, aaa->bbb, bbb->ccc, etc.
 
     // Parent
     HRegionInfo parent = new HRegionInfo(htd.getName(), Bytes.toBytes("aaa"),
-      Bytes.toBytes("eee"));
+      lastEndKey);
     // Sleep a second else the encoded name on these regions comes out
     // same for all with same start key and made in same second.
     Thread.sleep(1001);
@@ -369,13 +396,13 @@ public class TestCatalogJanitor {
 
     // Daughter b
     HRegionInfo splitb = new HRegionInfo(htd.getName(), Bytes.toBytes("ccc"),
-      Bytes.toBytes("eee"));
+      lastEndKey);
     Thread.sleep(1001);
     // Make Daughters of daughterb; splitba and splitbb.
     HRegionInfo splitba = new HRegionInfo(htd.getName(), Bytes.toBytes("ccc"),
       Bytes.toBytes("ddd"));
     HRegionInfo splitbb = new HRegionInfo(htd.getName(), Bytes.toBytes("ddd"),
-      Bytes.toBytes("eee"));
+    lastEndKey);
 
     // First test that our Comparator works right up in CatalogJanitor.
     // Just fo kicks.

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java?rev=1211204&r1=1211203&r2=1211204&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java Tue Dec  6 22:15:11 2011
@@ -115,6 +115,16 @@ public class TestHRegionInfo {
   }
 
   @Test
+  public void testLastRegionCompare() {
+    HTableDescriptor tableDesc = new HTableDescriptor("testtable");
+    HRegionInfo hrip = new HRegionInfo(
+        tableDesc.getName(), Bytes.toBytes("a"), new byte[0]);
+    HRegionInfo hric = new HRegionInfo(
+        tableDesc.getName(), Bytes.toBytes("a"), Bytes.toBytes("b"));
+    assertTrue(hrip.compareTo(hric) > 0);
+  }
+
+  @Test
   public void testMetaTables() {
     assertTrue(HRegionInfo.ROOT_REGIONINFO.isMetaTable());
     assertTrue(HRegionInfo.FIRST_META_REGIONINFO.isMetaTable());