use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.
the class TestAsyncRegionAdminApi method testGetRegionByStateOfTable.
@Test
public void testGetRegionByStateOfTable() throws Exception {
RegionInfo hri = createTableAndGetOneRegion(tableName);
RegionStates regionStates = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
assertTrue(regionStates.getRegionByStateOfTable(tableName).get(RegionState.State.OPEN).stream().anyMatch(r -> RegionInfo.COMPARATOR.compare(r, hri) == 0));
assertFalse(regionStates.getRegionByStateOfTable(TableName.valueOf("I_am_the_phantom")).get(RegionState.State.OPEN).stream().anyMatch(r -> RegionInfo.COMPARATOR.compare(r, hri) == 0));
}
use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.
the class TestSplitTransactionOnCluster method testSplitRegionWithNoStoreFiles.
/**
* If a table has regions that have no store files in a region, they should split successfully
* into two regions with no store files.
*/
@Test
public void testSplitRegionWithNoStoreFiles() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
// Create table then get the single region for our new table.
createTableAndWait(tableName, HConstants.CATALOG_FAMILY);
List<HRegion> regions = cluster.getRegions(tableName);
RegionInfo hri = getAndCheckSingleTableRegion(regions);
ensureTableRegionNotOnSameServerAsMeta(admin, hri);
int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionInfo().getRegionName());
HRegionServer regionServer = cluster.getRegionServer(regionServerIndex);
// Turn off balancer so it doesn't cut in and mess up our placements.
this.admin.balancerSwitch(false, true);
// Turn off the meta scanner so it don't remove parent on us.
cluster.getMaster().setCatalogJanitorEnabled(false);
try {
// Precondition: we created a table with no data, no store files.
printOutRegions(regionServer, "Initial regions: ");
Configuration conf = cluster.getConfiguration();
HBaseFsck.debugLsr(conf, new Path("/"));
Path rootDir = CommonFSUtils.getRootDir(conf);
FileSystem fs = TESTING_UTIL.getDFSCluster().getFileSystem();
Map<String, Path> storefiles = FSUtils.getTableStoreFilePathMap(null, fs, rootDir, tableName);
assertEquals("Expected nothing but found " + storefiles.toString(), 0, storefiles.size());
// find a splittable region. Refresh the regions list
regions = cluster.getRegions(tableName);
final HRegion region = findSplittableRegion(regions);
assertTrue("not able to find a splittable region", region != null);
// Now split.
try {
requestSplitRegion(regionServer, region, Bytes.toBytes("row2"));
} catch (IOException e) {
fail("Split execution should have succeeded with no exceptions thrown");
}
// Postcondition: split the table with no store files into two regions, but still have no
// store files
List<HRegion> daughters = cluster.getRegions(tableName);
assertEquals(2, daughters.size());
// check dirs
HBaseFsck.debugLsr(conf, new Path("/"));
Map<String, Path> storefilesAfter = FSUtils.getTableStoreFilePathMap(null, fs, rootDir, tableName);
assertEquals("Expected nothing but found " + storefilesAfter.toString(), 0, storefilesAfter.size());
// split parent
hri = region.getRegionInfo();
AssignmentManager am = cluster.getMaster().getAssignmentManager();
RegionStates regionStates = am.getRegionStates();
long start = EnvironmentEdgeManager.currentTime();
while (!regionStates.isRegionInState(hri, State.SPLIT)) {
LOG.debug("Waiting for SPLIT state on: " + hri);
assertFalse("Timed out in waiting split parent to be in state SPLIT", EnvironmentEdgeManager.currentTime() - start > 60000);
Thread.sleep(500);
}
assertTrue(regionStates.isRegionInState(daughters.get(0).getRegionInfo(), State.OPEN));
assertTrue(regionStates.isRegionInState(daughters.get(1).getRegionInfo(), State.OPEN));
// We should not be able to assign it again
try {
am.assign(hri);
} catch (DoNotRetryIOException e) {
// Expected
}
assertFalse("Split region can't be assigned", regionStates.isRegionInTransition(hri));
assertTrue(regionStates.isRegionInState(hri, State.SPLIT));
// We should not be able to unassign it either
try {
am.unassign(hri);
fail("Should have thrown exception");
} catch (DoNotRetryIOException e) {
// Expected
}
assertFalse("Split region can't be unassigned", regionStates.isRegionInTransition(hri));
assertTrue(regionStates.isRegionInState(hri, State.SPLIT));
} finally {
admin.balancerSwitch(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
}
}
use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.
the class CloneSnapshotFromClientAfterSplittingRegionTestBase method testCloneSnapshotAfterSplittingRegion.
@Test
public void testCloneSnapshotAfterSplittingRegion() throws IOException, InterruptedException {
// Turn off the CatalogJanitor
admin.catalogJanitorSwitch(false);
try {
List<RegionInfo> regionInfos = admin.getRegions(tableName);
RegionReplicaUtil.removeNonDefaultRegions(regionInfos);
// Split the first region
splitRegion(regionInfos.get(0));
// Take a snapshot
admin.snapshot(snapshotName2, tableName);
// Clone the snapshot to another table
TableName clonedTableName = TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime());
admin.cloneSnapshot(snapshotName2, clonedTableName);
SnapshotTestingUtils.waitForTableToBeOnline(TEST_UTIL, clonedTableName);
verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows);
RegionStates regionStates = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
// The region count of the cloned table should be the same as the one of the original table
int openRegionCountOfOriginalTable = regionStates.getRegionByStateOfTable(tableName).get(RegionState.State.OPEN).size();
int openRegionCountOfClonedTable = regionStates.getRegionByStateOfTable(clonedTableName).get(RegionState.State.OPEN).size();
assertEquals(openRegionCountOfOriginalTable, openRegionCountOfClonedTable);
int splitRegionCountOfOriginalTable = regionStates.getRegionByStateOfTable(tableName).get(RegionState.State.SPLIT).size();
int splitRegionCountOfClonedTable = regionStates.getRegionByStateOfTable(clonedTableName).get(RegionState.State.SPLIT).size();
assertEquals(splitRegionCountOfOriginalTable, splitRegionCountOfClonedTable);
TEST_UTIL.deleteTable(clonedTableName);
} finally {
admin.catalogJanitorSwitch(true);
}
}
use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.
the class TestFavoredStochasticLoadBalancer method testBalancerWithoutFavoredNodes.
@Test
public void testBalancerWithoutFavoredNodes() throws Exception {
TableName tableName = TableName.valueOf("testBalancerWithoutFavoredNodes");
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
admin.createTable(tableDescriptor, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM);
TEST_UTIL.waitTableAvailable(tableName);
final RegionInfo region = admin.getRegions(tableName).get(0);
LOG.info("Region thats supposed to be in transition: " + region);
FavoredNodesManager fnm = master.getFavoredNodesManager();
List<ServerName> currentFN = fnm.getFavoredNodes(region);
assertNotNull(currentFN);
fnm.deleteFavoredNodesForRegions(Lists.newArrayList(region));
RegionStates regionStates = master.getAssignmentManager().getRegionStates();
admin.balancerSwitch(true, true);
// Balancer should unassign the region
assertTrue("Balancer did not run", admin.balance());
TEST_UTIL.waitUntilNoRegionsInTransition();
admin.assign(region.getEncodedNameAsBytes());
TEST_UTIL.waitUntilNoRegionsInTransition(60000);
currentFN = fnm.getFavoredNodes(region);
assertNotNull(currentFN);
assertEquals("Expected number of FN not present", FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, currentFN.size());
assertTrue("Balancer did not run", admin.balance());
TEST_UTIL.waitUntilNoRegionsInTransition(60000);
checkFavoredNodeAssignments(tableName, fnm, regionStates);
}
use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.
the class TestFavoredStochasticLoadBalancer method testMisplacedRegions.
@Ignore
@Test
public void testMisplacedRegions() throws Exception {
TableName tableName = TableName.valueOf("testMisplacedRegions");
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
admin.createTable(tableDescriptor, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM);
TEST_UTIL.waitTableAvailable(tableName);
final RegionInfo misplacedRegion = admin.getRegions(tableName).get(0);
FavoredNodesManager fnm = master.getFavoredNodesManager();
List<ServerName> currentFN = fnm.getFavoredNodes(misplacedRegion);
assertNotNull(currentFN);
List<ServerName> serversForNewFN = Lists.newArrayList();
for (ServerName sn : admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) {
serversForNewFN.add(ServerName.valueOf(sn.getHostname(), sn.getPort(), NON_STARTCODE));
}
for (ServerName sn : currentFN) {
serversForNewFN.remove(sn);
}
FavoredNodeAssignmentHelper helper = new FavoredNodeAssignmentHelper(serversForNewFN, conf);
helper.initialize();
List<ServerName> newFavoredNodes = helper.generateFavoredNodes(misplacedRegion);
assertNotNull(newFavoredNodes);
assertEquals(FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, newFavoredNodes.size());
Map<RegionInfo, List<ServerName>> regionFNMap = Maps.newHashMap();
regionFNMap.put(misplacedRegion, newFavoredNodes);
fnm.updateFavoredNodes(regionFNMap);
final RegionStates regionStates = master.getAssignmentManager().getRegionStates();
final ServerName current = regionStates.getRegionServerOfRegion(misplacedRegion);
assertNull("Misplaced region is still hosted on favored node, not expected.", FavoredNodesPlan.getFavoredServerPosition(fnm.getFavoredNodes(misplacedRegion), current));
admin.balancerSwitch(true, true);
assertTrue("Balancer did not run", admin.balance());
TEST_UTIL.waitFor(120000, 30000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
ServerName host = regionStates.getRegionServerOfRegion(misplacedRegion);
return !ServerName.isSameAddress(host, current);
}
});
checkFavoredNodeAssignments(tableName, fnm, regionStates);
}
Aggregations