use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.
the class ProcedureSyncWait method waitMetaRegions.
protected static void waitMetaRegions(final MasterProcedureEnv env) throws IOException {
int timeout = env.getMasterConfiguration().getInt("hbase.client.catalog.timeout", 10000);
try {
long start = EnvironmentEdgeManager.currentTime();
for (; ; ) {
RegionStateNode rsn = env.getAssignmentManager().getRegionStates().getRegionStateNode(RegionInfoBuilder.FIRST_META_REGIONINFO);
if (rsn != null && rsn.isInState(RegionState.State.OPEN)) {
return;
}
if (EnvironmentEdgeManager.currentTime() - start >= timeout) {
throw new NotAllMetaRegionsOnlineException();
}
Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
}
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
}
use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.
the class TestFailedMetaReplicaAssigment method testFailedReplicaAssignment.
@Test
public void testFailedReplicaAssignment() throws InterruptedException {
HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
// waiting for master to come up
TEST_UTIL.waitFor(30000, () -> master.isInitialized());
AssignmentManager am = master.getAssignmentManager();
// showing one of the replicas got assigned
RegionInfo metaReplicaHri = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, 1);
// we use assignAsync so we need to wait a bit
TEST_UTIL.waitFor(30000, () -> {
RegionStateNode metaReplicaRegionNode = am.getRegionStates().getOrCreateRegionStateNode(metaReplicaHri);
return metaReplicaRegionNode.getRegionLocation() != null;
});
// showing one of the replicas failed to be assigned
RegionInfo metaReplicaHri2 = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, 2);
RegionStateNode metaReplicaRegionNode2 = am.getRegionStates().getOrCreateRegionStateNode(metaReplicaHri2);
// wait for several seconds to make sure that it is not assigned
for (int i = 0; i < 3; i++) {
Thread.sleep(2000);
assertNull(metaReplicaRegionNode2.getRegionLocation());
}
// showing master is active and running
assertFalse(master.isStopping());
assertFalse(master.isStopped());
assertTrue(master.isActiveMaster());
}
use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.
the class TestRSGroupsAdmin2 method testFailedMoveServersAndRepair.
@Test
public void testFailedMoveServersAndRepair() throws Exception {
// This UT calls moveToRSGroup() twice to test the idempotency of it.
// The first time, movement fails because a region is made in SPLITTING state
// which will not be moved.
// The second time, the region state is OPEN and check if all
// regions on target group servers after the call.
final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()), 1);
// create table
// randomly set a region state to SPLITTING to make move abort
Pair<ServerName, RegionStateNode> gotPair = createTableWithRegionSplitting(newGroup, new Random().nextInt(8) + 4);
RegionStateNode rsn = gotPair.getSecond();
ServerName srcServer = rsn.getRegionLocation();
// move server to newGroup and check regions
try {
ADMIN.moveServersToRSGroup(Sets.newHashSet(srcServer.getAddress()), newGroup.getName());
fail("should get IOException when retry exhausted but there still exists failed moved " + "regions");
} catch (Exception e) {
assertTrue(e.getMessage().contains(gotPair.getSecond().getRegionInfo().getRegionNameAsString()));
}
for (RegionInfo regionInfo : MASTER.getAssignmentManager().getAssignedRegions()) {
if (regionInfo.getTable().equals(tableName) && regionInfo.equals(rsn.getRegionInfo())) {
assertEquals(MASTER.getAssignmentManager().getRegionStates().getRegionServerOfRegion(regionInfo), srcServer);
}
}
// retry move server to newGroup and check if all regions on srcServer was moved
rsn.setState(RegionState.State.OPEN);
ADMIN.moveServersToRSGroup(Sets.newHashSet(srcServer.getAddress()), newGroup.getName());
assertEquals(MASTER.getAssignmentManager().getRegionsOnServer(srcServer).size(), 0);
}
use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.
the class TestRSGroupsAdmin2 method randomlySetRegionState.
private Pair<ServerName, RegionStateNode> randomlySetRegionState(RSGroupInfo groupInfo, RegionState.State state, TableName... tableNames) throws IOException {
Preconditions.checkArgument(tableNames.length == 1 || tableNames.length == 2, "only support one or two tables");
Map<TableName, Map<ServerName, List<String>>> tableServerRegionMap = getTableServerRegionMap();
Map<ServerName, List<String>> assignMap = tableServerRegionMap.get(tableNames[0]);
if (tableNames.length == 2) {
Map<ServerName, List<String>> assignMap2 = tableServerRegionMap.get(tableNames[1]);
assignMap2.forEach((k, v) -> {
if (!assignMap.containsKey(k)) {
assignMap.remove(k);
}
});
}
String toCorrectRegionName = null;
ServerName srcServer = null;
for (ServerName server : assignMap.keySet()) {
toCorrectRegionName = assignMap.get(server).size() >= 1 && !groupInfo.containsServer(server.getAddress()) ? assignMap.get(server).get(0) : null;
if (toCorrectRegionName != null) {
srcServer = server;
break;
}
}
assert srcServer != null;
RegionInfo toCorrectRegionInfo = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionInfo(Bytes.toBytesBinary(toCorrectRegionName));
RegionStateNode rsn = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates().getRegionStateNode(toCorrectRegionInfo);
rsn.setState(state);
return new Pair<>(srcServer, rsn);
}
use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.
the class TestRSGroupsAdmin2 method testFailedMoveBeforeRetryExhaustedWhenMoveServer.
@Test
public void testFailedMoveBeforeRetryExhaustedWhenMoveServer() throws Exception {
String groupName = getGroupName(name.getMethodName());
ADMIN.addRSGroup(groupName);
final RSGroupInfo newGroup = ADMIN.getRSGroup(groupName);
Pair<ServerName, RegionStateNode> gotPair = createTableWithRegionSplitting(newGroup, 10);
// start thread to recover region state
final ServerName movedServer = gotPair.getFirst();
final RegionStateNode rsn = gotPair.getSecond();
AtomicBoolean changed = new AtomicBoolean(false);
Thread t1 = recoverRegionStateThread(movedServer, server -> MASTER.getAssignmentManager().getRegionsOnServer(movedServer), rsn, changed);
t1.start();
// move target server to group
Thread t2 = new Thread(() -> {
LOG.info("thread2 start running, to move regions");
try {
ADMIN.moveServersToRSGroup(Sets.newHashSet(movedServer.getAddress()), newGroup.getName());
} catch (IOException e) {
LOG.error("move server error", e);
}
});
t2.start();
t1.join();
t2.join();
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() {
if (changed.get()) {
return MASTER.getAssignmentManager().getRegionsOnServer(movedServer).size() == 0 && !rsn.getRegionLocation().equals(movedServer);
}
return false;
}
});
}
Aggregations