use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.
the class TestHBaseFsckReplicas method testSplitAndDupeRegionWithRegionReplica.
/**
* Creates and fixes a bad table with a successful split that have a deployed
* start and end keys and region replicas enabled
*/
@Test(timeout = 180000)
public void testSplitAndDupeRegionWithRegionReplica() throws Exception {
TableName table = TableName.valueOf("testSplitAndDupeRegionWithRegionReplica");
Table meta = null;
try {
setupTableWithRegionReplica(table, 2);
assertNoErrors(doFsck(conf, false));
assertEquals(ROWKEYS.length, countRows());
// No Catalog Janitor running
admin.enableCatalogJanitor(false);
meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService);
HRegionLocation loc = this.connection.getRegionLocation(table, SPLITS[0], false);
HRegionInfo hriParent = loc.getRegionInfo();
// Split Region A just before B
this.connection.getAdmin().split(table, Bytes.toBytes("A@"));
Thread.sleep(1000);
// We need to make sure the parent region is not in a split state, so we put it in CLOSED state.
regionStates.updateRegionState(hriParent, RegionState.State.CLOSED);
TEST_UTIL.assignRegion(hriParent);
MetaTableAccessor.addRegionToMeta(meta, hriParent);
ServerName server = regionStates.getRegionServerOfRegion(hriParent);
if (server != null)
TEST_UTIL.assertRegionOnServer(hriParent, server, REGION_ONLINE_TIMEOUT);
while (findDeployedHSI(getDeployedHRIs((HBaseAdmin) admin), hriParent) == null) {
Thread.sleep(250);
}
LOG.debug("Finished assignment of parent region");
// TODO why is dupe region different from dupe start keys?
HBaseFsck hbck = doFsck(conf, false);
assertErrors(hbck, new HBaseFsck.ErrorReporter.ERROR_CODE[] { HBaseFsck.ErrorReporter.ERROR_CODE.NOT_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.DUPE_STARTKEYS, HBaseFsck.ErrorReporter.ERROR_CODE.DUPE_STARTKEYS, HBaseFsck.ErrorReporter.ERROR_CODE.OVERLAP_IN_REGION_CHAIN });
assertEquals(3, hbck.getOverlapGroups(table).size());
// fix the degenerate region.
hbck = new HBaseFsck(conf, hbfsckExecutorService);
// i.e. -details
hbck.setDisplayFullReport();
hbck.setTimeLag(0);
hbck.setFixHdfsOverlaps(true);
hbck.setRemoveParents(true);
hbck.setFixReferenceFiles(true);
hbck.setFixHFileLinks(true);
hbck.connect();
hbck.onlineHbck();
hbck.close();
hbck = doFsck(conf, false);
assertNoErrors(hbck);
assertEquals(0, hbck.getOverlapGroups(table).size());
assertEquals(ROWKEYS.length, countRows());
} finally {
cleanupTable(table);
}
}
use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.
the class TestHBaseFsckOneRS method testSplitDaughtersNotInMeta.
/**
* Split crashed after write to hbase:meta finished for the parent region, but
* failed to write daughters (pre HBASE-7721 codebase)
*/
@Test(timeout = 75000)
public void testSplitDaughtersNotInMeta() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService);
try {
setupTable(tableName);
assertEquals(ROWKEYS.length, countRows());
// make sure data in regions, if in wal only there is no data loss
admin.flush(tableName);
try (RegionLocator rl = connection.getRegionLocator(tbl.getName())) {
HRegionLocation location = rl.getRegionLocation(Bytes.toBytes("B"));
HRegionInfo hri = location.getRegionInfo();
// Disable CatalogJanitor to prevent it from cleaning up the parent region
// after split.
admin.enableCatalogJanitor(false);
// do a regular split
byte[] regionName = location.getRegionInfo().getRegionName();
admin.splitRegion(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM"));
TestEndToEndSplitTransaction.blockUntilRegionSplit(conf, 60000, regionName, true);
PairOfSameType<HRegionInfo> daughters = MetaTableAccessor.getDaughterRegions(meta.get(new Get(regionName)));
// Delete daughter regions from meta, but not hdfs, unassign it.
ServerName firstSN = rl.getRegionLocation(daughters.getFirst().getStartKey()).getServerName();
ServerName secondSN = rl.getRegionLocation(daughters.getSecond().getStartKey()).getServerName();
undeployRegion(connection, firstSN, daughters.getFirst());
undeployRegion(connection, secondSN, daughters.getSecond());
List<Delete> deletes = new ArrayList<>(2);
deletes.add(new Delete(daughters.getFirst().getRegionName()));
deletes.add(new Delete(daughters.getSecond().getRegionName()));
meta.delete(deletes);
// Remove daughters from regionStates
RegionStates regionStates = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
regionStates.deleteRegion(daughters.getFirst());
regionStates.deleteRegion(daughters.getSecond());
HBaseFsck hbck = doFsck(conf, false);
assertErrors(hbck, new HBaseFsck.ErrorReporter.ERROR_CODE[] { HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, //no LINGERING_SPLIT_PARENT
HBaseFsck.ErrorReporter.ERROR_CODE.HOLE_IN_REGION_CHAIN });
// now fix it. The fix should not revert the region split, but add daughters to META
hbck = doFsck(conf, true, true, false, false, false, false, false, false, false, false, false, false, null);
assertErrors(hbck, new HBaseFsck.ErrorReporter.ERROR_CODE[] { HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.HOLE_IN_REGION_CHAIN });
// assert that the split hbase:meta entry is still there.
Get get = new Get(hri.getRegionName());
Result result = meta.get(get);
assertNotNull(result);
assertNotNull(MetaTableAccessor.getHRegionInfo(result));
assertEquals(ROWKEYS.length, countRows());
// assert that we still have the split regions
//SPLITS + 1 is # regions
assertEquals(rl.getStartKeys().length, SPLITS.length + 1 + 1);
// pre-split.
//should be fixed by now
assertNoErrors(doFsck(conf, false));
}
} finally {
admin.enableCatalogJanitor(true);
meta.close();
cleanupTable(tableName);
}
}
use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.
the class TestHBaseFsckOneRS method testValidLingeringSplitParent.
/**
* Tests that LINGERING_SPLIT_PARENT is not erroneously reported for
* valid cases where the daughters are there.
*/
@Test(timeout = 180000)
public void testValidLingeringSplitParent() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
Table meta = null;
try {
setupTable(tableName);
assertEquals(ROWKEYS.length, countRows());
// make sure data in regions, if in wal only there is no data loss
admin.flush(tableName);
try (RegionLocator rl = connection.getRegionLocator(tbl.getName())) {
HRegionLocation location = rl.getRegionLocation(Bytes.toBytes("B"));
meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService);
HRegionInfo hri = location.getRegionInfo();
// do a regular split
byte[] regionName = location.getRegionInfo().getRegionName();
admin.splitRegion(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM"));
TestEndToEndSplitTransaction.blockUntilRegionSplit(conf, 60000, regionName, true);
// TODO: fixHdfsHoles does not work against splits, since the parent dir lingers on
// for some time until children references are deleted. HBCK erroneously sees this as
// overlapping regions
HBaseFsck hbck = doFsck(conf, true, true, false, false, false, true, true, true, true, false, false, false, null);
// no LINGERING_SPLIT_PARENT reported
//no LINGERING_SPLIT_PARENT reported
assertErrors(hbck, new HBaseFsck.ErrorReporter.ERROR_CODE[] {});
// assert that the split hbase:meta entry is still there.
Get get = new Get(hri.getRegionName());
Result result = meta.get(get);
assertNotNull(result);
assertNotNull(MetaTableAccessor.getHRegionInfo(result));
assertEquals(ROWKEYS.length, countRows());
// assert that we still have the split regions
//SPLITS + 1 is # regions pre-split.
assertEquals(rl.getStartKeys().length, SPLITS.length + 1 + 1);
assertNoErrors(doFsck(conf, false));
}
} finally {
cleanupTable(tableName);
IOUtils.closeQuietly(meta);
}
}
use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.
the class TestRegionSizeCalculator method mockRegionLocator.
/**
* Makes some table with given region names.
* */
private RegionLocator mockRegionLocator(String... regionNames) throws IOException {
RegionLocator mockedTable = Mockito.mock(RegionLocator.class);
when(mockedTable.getName()).thenReturn(TableName.valueOf("sizeTestTable"));
List<HRegionLocation> regionLocations = new ArrayList<>(regionNames.length);
when(mockedTable.getAllRegionLocations()).thenReturn(regionLocations);
for (String regionName : regionNames) {
HRegionInfo info = Mockito.mock(HRegionInfo.class);
when(info.getRegionName()).thenReturn(regionName.getBytes());
regionLocations.add(new HRegionLocation(info, sn));
}
return mockedTable;
}
use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.
the class TestRegionSplitter method verifyBounds.
private void verifyBounds(List<byte[]> expectedBounds, TableName tableName) throws Exception {
// Get region boundaries from the cluster and verify their endpoints
final int numRegions = expectedBounds.size() - 1;
try (Table table = UTIL.getConnection().getTable(tableName);
RegionLocator locator = UTIL.getConnection().getRegionLocator(tableName)) {
final List<HRegionLocation> regionInfoMap = locator.getAllRegionLocations();
assertEquals(numRegions, regionInfoMap.size());
for (HRegionLocation entry : regionInfoMap) {
final HRegionInfo regionInfo = entry.getRegionInfo();
byte[] regionStart = regionInfo.getStartKey();
byte[] regionEnd = regionInfo.getEndKey();
// This region's start key should be one of the region boundaries
int startBoundaryIndex = indexOfBytes(expectedBounds, regionStart);
assertNotSame(-1, startBoundaryIndex);
// This region's end key should be the region boundary that comes
// after the starting boundary.
byte[] expectedRegionEnd = expectedBounds.get(startBoundaryIndex + 1);
assertEquals(0, Bytes.compareTo(regionEnd, expectedRegionEnd));
}
}
}
Aggregations