HBASE-25322 Redundant Reference file in bottom region of split (#3814)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
ebd89b58eb
commit
2fbb375cd5
|
@ -667,9 +667,9 @@ public class HRegionFileSystem {
|
||||||
// If it is outside the range, return directly.
|
// If it is outside the range, return directly.
|
||||||
f.initReader();
|
f.initReader();
|
||||||
try {
|
try {
|
||||||
|
Cell splitKey = PrivateCellUtil.createFirstOnRow(splitRow);
|
||||||
if (top) {
|
if (top) {
|
||||||
//check if larger than last key.
|
//check if larger than last key.
|
||||||
Cell splitKey = PrivateCellUtil.createFirstOnRow(splitRow);
|
|
||||||
Optional<Cell> lastKey = f.getLastKey();
|
Optional<Cell> lastKey = f.getLastKey();
|
||||||
// If lastKey is null means storefile is empty.
|
// If lastKey is null means storefile is empty.
|
||||||
if (!lastKey.isPresent()) {
|
if (!lastKey.isPresent()) {
|
||||||
|
@ -680,7 +680,6 @@ public class HRegionFileSystem {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//check if smaller than first key
|
//check if smaller than first key
|
||||||
Cell splitKey = PrivateCellUtil.createLastOnRow(splitRow);
|
|
||||||
Optional<Cell> firstKey = f.getFirstKey();
|
Optional<Cell> firstKey = f.getFirstKey();
|
||||||
// If firstKey is null means storefile is empty.
|
// If firstKey is null means storefile is empty.
|
||||||
if (!firstKey.isPresent()) {
|
if (!firstKey.isPresent()) {
|
||||||
|
|
|
@ -159,6 +159,11 @@ public final class AssignmentTestingUtil {
|
||||||
|
|
||||||
public static void insertData(final HBaseTestingUtility UTIL, final TableName tableName,
|
public static void insertData(final HBaseTestingUtility UTIL, final TableName tableName,
|
||||||
int rowCount, int startRowNum, String... cfs) throws IOException {
|
int rowCount, int startRowNum, String... cfs) throws IOException {
|
||||||
|
insertData(UTIL, tableName, rowCount, startRowNum, false, cfs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertData(final HBaseTestingUtility UTIL, final TableName tableName,
|
||||||
|
int rowCount, int startRowNum, boolean flushOnce, String... cfs) throws IOException {
|
||||||
Table t = UTIL.getConnection().getTable(tableName);
|
Table t = UTIL.getConnection().getTable(tableName);
|
||||||
Put p;
|
Put p;
|
||||||
for (int i = 0; i < rowCount / 2; i++) {
|
for (int i = 0; i < rowCount / 2; i++) {
|
||||||
|
@ -172,9 +177,12 @@ public final class AssignmentTestingUtil {
|
||||||
p.addColumn(Bytes.toBytes(cf), Bytes.toBytes("q"), Bytes.toBytes(i));
|
p.addColumn(Bytes.toBytes(cf), Bytes.toBytes("q"), Bytes.toBytes(i));
|
||||||
}
|
}
|
||||||
t.put(p);
|
t.put(p);
|
||||||
if (i % 5 == 0) {
|
if (i % 5 == 0 && !flushOnce) {
|
||||||
UTIL.getAdmin().flush(tableName);
|
UTIL.getAdmin().flush(tableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (flushOnce) {
|
||||||
|
UTIL.getAdmin().flush(tableName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@ package org.apache.hadoop.hbase.master.assignment;
|
||||||
|
|
||||||
import static org.apache.hadoop.hbase.master.assignment.AssignmentTestingUtil.insertData;
|
import static org.apache.hadoop.hbase.master.assignment.AssignmentTestingUtil.insertData;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
@ -39,6 +41,7 @@ import org.apache.hadoop.hbase.testclassification.MasterTests;
|
||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.apache.hadoop.hbase.util.JVMClusterUtil;
|
import org.apache.hadoop.hbase.util.JVMClusterUtil;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -157,6 +160,54 @@ public class TestRegionSplit {
|
||||||
regionInfoMap.get(tableRegions.get(1).getRegionInfo()));
|
regionInfoMap.get(tableRegions.get(1).getRegionInfo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSplitStoreFiles() throws Exception {
|
||||||
|
final TableName tableName = TableName.valueOf(name.getMethodName());
|
||||||
|
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
|
||||||
|
|
||||||
|
RegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName,
|
||||||
|
null, columnFamilyName);
|
||||||
|
// flush the memstore
|
||||||
|
insertData(UTIL, tableName, rowCount, startRowNum, true, columnFamilyName);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
List<HRegion> tableRegions = UTIL.getHBaseCluster().getRegions(tableName);
|
||||||
|
assertEquals("Table region not correct.", 2, tableRegions.size());
|
||||||
|
Map<RegionInfo, ServerName> regionInfoMap = UTIL.getHBaseCluster().getMaster()
|
||||||
|
.getAssignmentManager().getRegionStates().getRegionAssignments();
|
||||||
|
assertEquals(regionInfoMap.get(tableRegions.get(0).getRegionInfo()),
|
||||||
|
regionInfoMap.get(tableRegions.get(1).getRegionInfo()));
|
||||||
|
}
|
||||||
|
|
||||||
private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
|
private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
|
||||||
return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor();
|
return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue