From 10176955cd3415929ee418f2d6ee59ef09e1b8bd Mon Sep 17 00:00:00 2001 From: haxiaolin Date: Tue, 24 Nov 2020 12:05:05 +0800 Subject: [PATCH] HBASE-25322 Redundant Reference file in bottom region of split --- .../hbase/regionserver/HRegionFileSystem.java | 3 +- .../master/assignment/TestRegionSplit.java | 46 ++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java index d5ef30ecc79f..bb2328c6c0b5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java @@ -682,9 +682,9 @@ public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte // If it is outside the range, return directly. f.initReader(); try { + Cell splitKey = PrivateCellUtil.createFirstOnRow(splitRow); if (top) { //check if larger than last key. - Cell splitKey = PrivateCellUtil.createFirstOnRow(splitRow); Optional lastKey = f.getLastKey(); // If lastKey is null means storefile is empty. if (!lastKey.isPresent()) { @@ -695,7 +695,6 @@ public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte } } else { //check if smaller than first key - Cell splitKey = PrivateCellUtil.createLastOnRow(splitRow); Optional firstKey = f.getFirstKey(); // If firstKey is null means storefile is empty. if (!firstKey.isPresent()) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionSplit.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionSplit.java index 5fe45b7a387b..186edf9eae95 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionSplit.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionSplit.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hbase.master.assignment; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.IOException; import org.apache.hadoop.conf.Configuration; @@ -33,6 +34,7 @@ import org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility; import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; +import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; @@ -126,7 +128,8 @@ public void testSplitTableRegion() throws Exception { ProcedureTestingUtility.waitProcedure(procExec, procId); ProcedureTestingUtility.assertProcNotFailed(procExec, procId); - assertTrue("not able to split table", UTIL.getHBaseCluster().getRegions(tableName).size() == 2); + assertTrue("not able to split table", + UTIL.getHBaseCluster().getRegions(tableName).size() == 2); //disable table UTIL.getAdmin().disableTable(tableName); @@ -150,6 +153,47 @@ public void testSplitTableRegion() throws Exception { UTIL.getHBaseCluster().getRegions(tableName).size()); } + @Test + public void testSplitStoreFiles() throws Exception { + final TableName tableName = TableName.valueOf(name.getMethodName()); + final ProcedureExecutor procExec = getMasterProcedureExecutor(); + + RegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName, + null, ColumnFamilyName); + // flush the memstore + insertData(tableName); + + // assert the hfile count of the table + int storeFilesCountSum = 0; + for(HRegion region : UTIL.getHBaseCluster().getRegions(tableName)){ + storeFilesCountSum += region.getStore(Bytes.toBytes(ColumnFamilyName)).getStorefiles().size(); + } + assertEquals(1, storeFilesCountSum); + + // split at the start row + byte[] splitKey = Bytes.toBytes("" + startRowNum); + + assertNotNull("Not able to find a splittable region", regions); + assertEquals("Not able to find a splittable region", 1, regions.length); + + // Split region of the table + long procId = procExec.submitProcedure( + new SplitTableRegionProcedure(procExec.getEnvironment(), regions[0], splitKey)); + // Wait the completion + ProcedureTestingUtility.waitProcedure(procExec, procId); + ProcedureTestingUtility.assertProcNotFailed(procExec, procId); + + assertEquals("Not able to split table", + 2, UTIL.getHBaseCluster().getRegions(tableName).size()); + + // assert sum of the hfiles of all regions + int childStoreFilesSum = 0; + for(HRegion region : UTIL.getHBaseCluster().getRegions(tableName)){ + childStoreFilesSum += region.getStore(Bytes.toBytes(ColumnFamilyName)).getStorefiles().size(); + } + assertEquals(1, childStoreFilesSum); + } + private void insertData(final TableName tableName) throws IOException { Table t = UTIL.getConnection().getTable(tableName); Put p;