Search in sources :

Example 11 with RegionStateNode

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);
    }
}
Also used : NotAllMetaRegionsOnlineException(org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException) InterruptedIOException(java.io.InterruptedIOException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode)

Example 12 with RegionStateNode

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());
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Test(org.junit.Test)

Example 13 with RegionStateNode

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);
}
Also used : Random(java.util.Random) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Test(org.junit.Test)

Example 14 with RegionStateNode

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Map(java.util.Map) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Pair(org.apache.hadoop.hbase.util.Pair)

Example 15 with RegionStateNode

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;
        }
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerName(org.apache.hadoop.hbase.ServerName) IOException(java.io.IOException) Waiter(org.apache.hadoop.hbase.Waiter) IOException(java.io.IOException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Test(org.junit.Test)

Aggregations

RegionStateNode (org.apache.hadoop.hbase.master.assignment.RegionStateNode)18 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)11 Test (org.junit.Test)9 IOException (java.io.IOException)7 ServerName (org.apache.hadoop.hbase.ServerName)7 TableName (org.apache.hadoop.hbase.TableName)6 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)5 TransitRegionStateProcedure (org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure)5 List (java.util.List)4 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 Waiter (org.apache.hadoop.hbase.Waiter)3 ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)3 InterruptedIOException (java.io.InterruptedIOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Random (java.util.Random)2 UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)2 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)2 FavoredNodeAssignmentHelper (org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper)2 FavoredNodesManager (org.apache.hadoop.hbase.favored.FavoredNodesManager)2