This is an automated email from the ASF dual-hosted git repository.
junegunn pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-3 by this push:
new 4472d3a76f9 HBASE-29472 Fix splitting algorithms of RegionSplitter
tool (#7173)
4472d3a76f9 is described below
commit 4472d3a76f948766a73f15170093fd00d6dfd374
Author: Junegunn Choi <[email protected]>
AuthorDate: Sat Jul 26 15:15:47 2025 +0900
HBASE-29472 Fix splitting algorithms of RegionSplitter tool (#7173)
Signed-off-by: Nihal Jain <[email protected]>
---
.../apache/hadoop/hbase/util/RegionSplitter.java | 3 +++
.../hadoop/hbase/util/TestRegionSplitter.java | 30 ++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git
a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
index 5d0509ac3d1..430df04cd42 100644
---
a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
+++
b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
@@ -980,6 +980,9 @@ public class RegionSplitter {
* @return the midpoint of the 2 numbers
*/
public BigInteger split2(BigInteger a, BigInteger b) {
+ if (b.equals(lastRowInt)) {
+ b = b.add(BigInteger.ONE);
+ }
return a.add(b).divide(BigInteger.valueOf(2)).abs();
}
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 532e55223ad..4950188232c 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
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.hadoop.conf.Configuration;
@@ -108,6 +109,35 @@ public class TestRegionSplitter {
TableName.valueOf(name.getMethodName()));
}
+ /**
+ * Test creating a pre-split table and splitting it again using the
HexStringSplit and
+ * DecimalStringSplit algorithms.
+ */
+ @Test
+ public void testSplitPresplitTable() throws Exception {
+ testSplitPresplitTable(new HexStringSplit());
+ testSplitPresplitTable(new DecimalStringSplit());
+ }
+
+ private void testSplitPresplitTable(RegionSplitter.NumberStringSplit
splitter) throws Exception {
+ final List<byte[]> initialBounds = new ArrayList<>();
+ initialBounds.add(ArrayUtils.EMPTY_BYTE_ARRAY);
+ initialBounds.addAll(Arrays.asList(splitter.split(8)));
+ initialBounds.add(ArrayUtils.EMPTY_BYTE_ARRAY);
+
+ // Do table creation/pre-splitting and verification of region boundaries
+ final String className = splitter.getClass().getSimpleName();
+ final TableName tableName = TableName.valueOf(className);
+ preSplitTableAndVerify(initialBounds, className, tableName);
+
+ // Split the table again and verify the new region boundaries
+ final List<byte[]> expectedBounds = new ArrayList<>();
+ expectedBounds.add(ArrayUtils.EMPTY_BYTE_ARRAY);
+ expectedBounds.addAll(Arrays.asList(splitter.split(16)));
+ expectedBounds.add(ArrayUtils.EMPTY_BYTE_ARRAY);
+ rollingSplitAndVerify(tableName, className, expectedBounds);
+ }
+
/**
* Test creating a pre-split table using the UniformSplit algorithm.
*/