hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject hbase git commit: HBASE-12716 A bug in RegionSplitter.UniformSplit algorithm (Weichen Ye)
Date Fri, 02 Jan 2015 07:39:52 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 99acd66a9 -> 74f303ba2


HBASE-12716 A bug in RegionSplitter.UniformSplit algorithm (Weichen Ye)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/74f303ba
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/74f303ba
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/74f303ba

Branch: refs/heads/0.98
Commit: 74f303ba2482b2f0c81260ee41cd0f94ef3105d8
Parents: 99acd66
Author: tedyu <yuzhihong@gmail.com>
Authored: Sun Dec 28 07:49:12 2014 -0800
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Thu Jan 1 23:35:46 2015 -0800

----------------------------------------------------------------------
 .../main/java/org/apache/hadoop/hbase/util/Bytes.java  | 13 ++++++++++++-
 .../java/org/apache/hadoop/hbase/util/TestBytes.java   |  5 +++--
 .../apache/hadoop/hbase/util/TestRegionSplitter.java   |  5 ++++-
 3 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/74f303ba/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
index ff7c850..c69b242 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
@@ -1700,8 +1700,19 @@ public class Bytes {
       diffBI = diffBI.add(BigInteger.ONE);
     }
     final BigInteger splitsBI = BigInteger.valueOf(num + 1);
+    //when diffBI < splitBI, use an additional byte to increase diffBI
     if(diffBI.compareTo(splitsBI) < 0) {
-      return null;
+      byte[] aPaddedAdditional = new byte[aPadded.length+1];
+      byte[] bPaddedAdditional = new byte[bPadded.length+1];
+      for (int i = 0; i < aPadded.length; i++){
+        aPaddedAdditional[i] = aPadded[i];
+      }
+      for (int j = 0; j < bPadded.length; j++){
+        bPaddedAdditional[j] = bPadded[j];
+      }
+      aPaddedAdditional[aPadded.length] = 0;
+      bPaddedAdditional[bPadded.length] = 0;
+      return iterateOnSplits(aPaddedAdditional, bPaddedAdditional, inclusive,  num);
     }
     final BigInteger intervalBI;
     try {

http://git-wip-us.apache.org/repos/asf/hbase/blob/74f303ba/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
index 6d2c1ae..1a76536 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
@@ -101,9 +101,10 @@ public class TestBytes extends TestCase {
     }
     assertTrue("Returned split should have 3 parts but has " + parts.length, parts.length
== 3);
 
-    // If split more than once, this should fail
+    // If split more than once, use additional byte to split
     parts = Bytes.split(low, high, 2);
-    assertTrue("Returned split but should have failed", parts == null);
+    assertTrue("Split with an additional byte", parts != null);
+    assertEquals(parts.length, low.length + 1);
 
     // Split 0 times should throw IAE
     try {

http://git-wip-us.apache.org/repos/asf/hbase/blob/74f303ba/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
index ab10888..98b65cb 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
@@ -205,6 +205,9 @@ public class TestRegionSplitter {
                 xFF, xFF, xFF}, lastRow);
         assertArrayEquals(splitPoint,
                 new byte[] {(byte)0xef, xFF, xFF, xFF, xFF, xFF, xFF, xFF});
+
+        splitPoint = splitter.split(new byte[] {'a', 'a', 'a'}, new byte[] {'a', 'a', 'b'});
+        assertArrayEquals(splitPoint, new byte[] {'a', 'a', 'a', (byte)0x80 });
     }
 
   @Test
@@ -225,7 +228,7 @@ public class TestRegionSplitter {
     assertTrue(splitFailsPrecondition(algo, "\\xAA", "\\xAA")); // range error
     assertFalse(splitFailsPrecondition(algo, "\\x00", "\\x02", 3)); // should be fine
     assertFalse(splitFailsPrecondition(algo, "\\x00", "\\x0A", 11)); // should be fine
-    assertTrue(splitFailsPrecondition(algo, "\\x00", "\\x0A", 12)); // too granular
+    assertFalse(splitFailsPrecondition(algo, "\\x00", "\\x0A", 12)); // should be fine
   }
 
   private boolean splitFailsPrecondition(SplitAlgorithm algo) {


Mime
View raw message