Skip to content

Commit 23f9b2a

Browse files
committed
HBASE-25322 Redundant Reference file in bottom region of split (#3814)
Signed-off-by: Duo Zhang <[email protected]>
1 parent 8ea5484 commit 23f9b2a

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,9 @@ public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte
703703
// If it is outside the range, return directly.
704704
f.initReader();
705705
try {
706+
Cell splitKey = PrivateCellUtil.createFirstOnRow(splitRow);
706707
if (top) {
707708
//check if larger than last key.
708-
Cell splitKey = PrivateCellUtil.createFirstOnRow(splitRow);
709709
Optional<Cell> lastKey = f.getLastKey();
710710
// If lastKey is null means storefile is empty.
711711
if (!lastKey.isPresent()) {
@@ -716,7 +716,6 @@ public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte
716716
}
717717
} else {
718718
//check if smaller than first key
719-
Cell splitKey = PrivateCellUtil.createLastOnRow(splitRow);
720719
Optional<Cell> firstKey = f.getFirstKey();
721720
// If firstKey is null means storefile is empty.
722721
if (!firstKey.isPresent()) {

hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/AssignmentTestingUtil.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public static boolean waitForAssignment(AssignmentManager am, RegionInfo regionI
159159

160160
public static void insertData(final HBaseTestingUtility UTIL, final TableName tableName,
161161
int rowCount, int startRowNum, String... cfs) throws IOException {
162+
insertData(UTIL, tableName, rowCount, startRowNum, false, cfs);
163+
}
164+
165+
public static void insertData(final HBaseTestingUtil UTIL, final TableName tableName,
166+
int rowCount, int startRowNum, boolean flushOnce, String... cfs) throws IOException {
162167
Table t = UTIL.getConnection().getTable(tableName);
163168
Put p;
164169
for (int i = 0; i < rowCount / 2; i++) {
@@ -172,9 +177,12 @@ public static void insertData(final HBaseTestingUtility UTIL, final TableName ta
172177
p.addColumn(Bytes.toBytes(cf), Bytes.toBytes("q"), Bytes.toBytes(i));
173178
}
174179
t.put(p);
175-
if (i % 5 == 0) {
180+
if (i % 5 == 0 && !flushOnce) {
176181
UTIL.getAdmin().flush(tableName);
177182
}
178183
}
184+
if (flushOnce) {
185+
UTIL.getAdmin().flush(tableName);
186+
}
179187
}
180188
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionSplit.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import static org.apache.hadoop.hbase.master.assignment.AssignmentTestingUtil.insertData;
2121
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertNotNull;
2223
import static org.junit.Assert.assertTrue;
24+
2325
import java.util.List;
2426
import java.util.Map;
2527
import org.apache.hadoop.conf.Configuration;
@@ -39,6 +41,7 @@
3941
import org.apache.hadoop.hbase.testclassification.MediumTests;
4042
import org.apache.hadoop.hbase.util.Bytes;
4143
import org.apache.hadoop.hbase.util.JVMClusterUtil;
44+
4245
import org.junit.After;
4346
import org.junit.AfterClass;
4447
import org.junit.Before;
@@ -157,6 +160,54 @@ public void testSplitTableRegion() throws Exception {
157160
regionInfoMap.get(tableRegions.get(1).getRegionInfo()));
158161
}
159162

163+
@Test
164+
public void testSplitStoreFiles() throws Exception {
165+
final TableName tableName = TableName.valueOf(name.getMethodName());
166+
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
167+
168+
RegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName,
169+
null, columnFamilyName);
170+
// flush the memstore
171+
insertData(UTIL, tableName, rowCount, startRowNum, true, columnFamilyName);
172+
173+
// assert the hfile count of the table
174+
int storeFilesCountSum = 0;
175+
for(HRegion region : UTIL.getHBaseCluster().getRegions(tableName)){
176+
storeFilesCountSum += region.getStore(Bytes.toBytes(columnFamilyName)).getStorefiles().size();
177+
}
178+
assertEquals(1, storeFilesCountSum);
179+
180+
// split at the start row
181+
byte[] splitKey = Bytes.toBytes("" + startRowNum);
182+
183+
assertNotNull("Not able to find a splittable region", regions);
184+
assertEquals("Not able to find a splittable region", 1, regions.length);
185+
186+
// Split region of the table
187+
long procId = procExec.submitProcedure(
188+
new SplitTableRegionProcedure(procExec.getEnvironment(), regions[0], splitKey));
189+
// Wait the completion
190+
ProcedureTestingUtility.waitProcedure(procExec, procId);
191+
ProcedureTestingUtility.assertProcNotFailed(procExec, procId);
192+
193+
assertEquals("Not able to split table",
194+
2, UTIL.getHBaseCluster().getRegions(tableName).size());
195+
196+
// assert sum of the hfiles of all regions
197+
int childStoreFilesSum = 0;
198+
for(HRegion region : UTIL.getHBaseCluster().getRegions(tableName)){
199+
childStoreFilesSum += region.getStore(Bytes.toBytes(columnFamilyName)).getStorefiles().size();
200+
}
201+
assertEquals(1, childStoreFilesSum);
202+
203+
List<HRegion> tableRegions = UTIL.getHBaseCluster().getRegions(tableName);
204+
assertEquals("Table region not correct.", 2, tableRegions.size());
205+
Map<RegionInfo, ServerName> regionInfoMap = UTIL.getHBaseCluster().getMaster()
206+
.getAssignmentManager().getRegionStates().getRegionAssignments();
207+
assertEquals(regionInfoMap.get(tableRegions.get(0).getRegionInfo()),
208+
regionInfoMap.get(tableRegions.get(1).getRegionInfo()));
209+
}
210+
160211
private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
161212
return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor();
162213
}

0 commit comments

Comments
 (0)