Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,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<Cell> lastKey = f.getLastKey();
// If lastKey is null means storefile is empty.
if (!lastKey.isPresent()) {
Expand All @@ -694,7 +694,6 @@ public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte
}
} else {
//check if smaller than first key
Cell splitKey = PrivateCellUtil.createLastOnRow(splitRow);
Optional<Cell> firstKey = f.getFirstKey();
// If firstKey is null means storefile is empty.
if (!firstKey.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public static boolean waitForAssignment(AssignmentManager am, RegionInfo regionI

public static void insertData(final HBaseTestingUtility UTIL, final TableName tableName,
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);
Put p;
for (int i = 0; i < rowCount / 2; i++) {
Expand All @@ -172,9 +177,12 @@ public static void insertData(final HBaseTestingUtility UTIL, final TableName ta
p.addColumn(Bytes.toBytes(cf), Bytes.toBytes("q"), Bytes.toBytes(i));
}
t.put(p);
if (i % 5 == 0) {
if (i % 5 == 0 && !flushOnce) {
UTIL.getAdmin().flush(tableName);
}
}
if (flushOnce) {
UTIL.getAdmin().flush(tableName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import static org.apache.hadoop.hbase.master.assignment.AssignmentTestingUtil.insertData;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -28,7 +30,9 @@
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.StartMiniClusterOption;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility;
Expand Down Expand Up @@ -129,7 +133,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);
Expand All @@ -149,6 +154,50 @@ public void testSplitTableRegion() throws Exception {
UTIL.getAdmin().enableTable(tableName);
Thread.sleep(500);

assertEquals("Table region not correct.", 2,
UTIL.getHBaseCluster().getRegions(tableName).size());
}

@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()
Expand Down