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 a342a48eff2..9e79be35322 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 @@ -1701,8 +1701,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 { 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 6d2c1ae0934..1a765362a27 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 { 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 475ee19f6bf..e3435880f9c 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 @@ -207,6 +207,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 @@ -227,7 +230,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) {