Search in sources :

Example 16 with RegionStates

use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.

the class TestAsyncRegionAdminApi method testAssignRegionAndUnassignRegion.

@Test
public void testAssignRegionAndUnassignRegion() throws Exception {
    createTableWithDefaultConf(tableName);
    // assign region.
    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
    AssignmentManager am = master.getAssignmentManager();
    RegionInfo hri = am.getRegionStates().getRegionsOfTable(tableName).get(0);
    // assert region on server
    RegionStates regionStates = am.getRegionStates();
    ServerName serverName = regionStates.getRegionServerOfRegion(hri);
    TEST_UTIL.assertRegionOnServer(hri, serverName, 200);
    assertTrue(regionStates.getRegionState(hri).isOpened());
    // Master should not abort, and region should stay assigned.
    try {
        admin.assign(hri.getRegionName()).get();
        fail("Should fail when assigning an already onlined region");
    } catch (ExecutionException e) {
        // Expected
        assertThat(e.getCause(), instanceOf(DoNotRetryRegionException.class));
    }
    assertFalse(am.getRegionStates().getRegionStateNode(hri).isInTransition());
    assertTrue(regionStates.getRegionState(hri).isOpened());
    // unassign region
    admin.unassign(hri.getRegionName(), true).get();
    assertFalse(am.getRegionStates().getRegionStateNode(hri).isInTransition());
    assertTrue(regionStates.getRegionState(hri).isClosed());
}
Also used : RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 17 with RegionStates

use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.

the class MasterRpcServices method mergeTableRegions.

@Override
public MergeTableRegionsResponse mergeTableRegions(RpcController c, MergeTableRegionsRequest request) throws ServiceException {
    try {
        server.checkInitialized();
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
    RegionStates regionStates = server.getAssignmentManager().getRegionStates();
    RegionInfo[] regionsToMerge = new RegionInfo[request.getRegionCount()];
    for (int i = 0; i < request.getRegionCount(); i++) {
        final byte[] encodedNameOfRegion = request.getRegion(i).getValue().toByteArray();
        if (request.getRegion(i).getType() != RegionSpecifierType.ENCODED_REGION_NAME) {
            LOG.warn("MergeRegions specifier type: expected: " + RegionSpecifierType.ENCODED_REGION_NAME + " actual: region " + i + " =" + request.getRegion(i).getType());
        }
        RegionState regionState = regionStates.getRegionState(Bytes.toString(encodedNameOfRegion));
        if (regionState == null) {
            throw new ServiceException(new UnknownRegionException(Bytes.toStringBinary(encodedNameOfRegion)));
        }
        regionsToMerge[i] = regionState.getRegion();
    }
    try {
        long procId = server.mergeRegions(regionsToMerge, request.getForcible(), request.getNonceGroup(), request.getNonce());
        return MergeTableRegionsResponse.newBuilder().setProcId(procId).build();
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 18 with RegionStates

use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.

the class ServerManager method removeDeletedRegionFromLoadedFlushedSequenceIds.

/**
 * Regions may have been removed between latest persist of FlushedSequenceIds
 * and master abort. So after loading FlushedSequenceIds from file, and after
 * meta loaded, we need to remove the deleted region according to RegionStates.
 */
public void removeDeletedRegionFromLoadedFlushedSequenceIds() {
    RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    Iterator<byte[]> it = flushedSequenceIdByRegion.keySet().iterator();
    while (it.hasNext()) {
        byte[] regionEncodedName = it.next();
        if (regionStates.getRegionState(Bytes.toStringBinary(regionEncodedName)) == null) {
            it.remove();
            storeFlushedSequenceIdsByRegion.remove(regionEncodedName);
        }
    }
}
Also used : RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates)

Example 19 with RegionStates

use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.

the class HBaseTestingUtility method waitUntilAllRegionsAssigned.

/**
 * Wait until all regions for a table in hbase:meta have a non-empty
 * info:server, or until timeout.  This means all regions have been deployed,
 * master has been informed and updated hbase:meta with the regions deployed
 * server.
 * @param tableName the table name
 * @param timeout timeout, in milliseconds
 * @throws IOException
 */
public void waitUntilAllRegionsAssigned(final TableName tableName, final long timeout) throws IOException {
    if (!TableName.isMetaTableName(tableName)) {
        try (final Table meta = getConnection().getTable(TableName.META_TABLE_NAME)) {
            LOG.debug("Waiting until all regions of table " + tableName + " get assigned. Timeout = " + timeout + "ms");
            waitFor(timeout, 200, true, new ExplainingPredicate<IOException>() {

                @Override
                public String explainFailure() throws IOException {
                    return explainTableAvailability(tableName);
                }

                @Override
                public boolean evaluate() throws IOException {
                    Scan scan = new Scan();
                    scan.addFamily(HConstants.CATALOG_FAMILY);
                    boolean tableFound = false;
                    try (ResultScanner s = meta.getScanner(scan)) {
                        for (Result r; (r = s.next()) != null; ) {
                            byte[] b = r.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
                            RegionInfo info = RegionInfo.parseFromOrNull(b);
                            if (info != null && info.getTable().equals(tableName)) {
                                // Get server hosting this region from catalog family. Return false if no server
                                // hosting this region, or if the server hosting this region was recently killed
                                // (for fault tolerance testing).
                                tableFound = true;
                                byte[] server = r.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
                                if (server == null) {
                                    return false;
                                } else {
                                    byte[] startCode = r.getValue(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER);
                                    ServerName serverName = ServerName.valueOf(Bytes.toString(server).replaceFirst(":", ",") + "," + Bytes.toLong(startCode));
                                    if (!getHBaseClusterInterface().isDistributedCluster() && getHBaseCluster().isKilledRS(serverName)) {
                                        return false;
                                    }
                                }
                                if (RegionStateStore.getRegionState(r, info) != RegionState.State.OPEN) {
                                    return false;
                                }
                            }
                        }
                    }
                    if (!tableFound) {
                        LOG.warn("Didn't find the entries for table " + tableName + " in meta, already deleted?");
                    }
                    return tableFound;
                }
            });
        }
    }
    LOG.info("All regions for table " + tableName + " assigned to meta. Checking AM states.");
    // check from the master state if we are using a mini cluster
    if (!getHBaseClusterInterface().isDistributedCluster()) {
        // So, all regions are in the meta table but make sure master knows of the assignments before
        // returning -- sometimes this can lag.
        HMaster master = getHBaseCluster().getMaster();
        final RegionStates states = master.getAssignmentManager().getRegionStates();
        waitFor(timeout, 200, new ExplainingPredicate<IOException>() {

            @Override
            public String explainFailure() throws IOException {
                return explainTableAvailability(tableName);
            }

            @Override
            public boolean evaluate() throws IOException {
                List<RegionInfo> hris = states.getRegionsOfTable(tableName);
                return hris != null && !hris.isEmpty();
            }
        });
    }
    LOG.info("All regions for table " + tableName + " assigned.");
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) HMaster(org.apache.hadoop.hbase.master.HMaster) Scan(org.apache.hadoop.hbase.client.Scan) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with RegionStates

use of org.apache.hadoop.hbase.master.assignment.RegionStates in project hbase by apache.

the class TestMetaShutdownHandler method testExpireMetaRegionServer.

/**
 * This test will test the expire handling of a meta-carrying
 * region server.
 * After HBaseMiniCluster is up, we will delete the ephemeral
 * node of the meta-carrying region server, which will trigger
 * the expire of this region server on the master.
 * On the other hand, we will slow down the abort process on
 * the region server so that it is still up during the master SSH.
 * We will check that the master SSH is still successfully done.
 */
@Test
public void testExpireMetaRegionServer() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    ServerName metaServerName = regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO);
    if (master.getServerName().equals(metaServerName) || metaServerName == null || !metaServerName.equals(cluster.getServerHoldingMeta())) {
        // Move meta off master
        metaServerName = cluster.getLiveRegionServerThreads().get(0).getRegionServer().getServerName();
        master.move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), Bytes.toBytes(metaServerName.getServerName()));
        TEST_UTIL.waitUntilNoRegionsInTransition(60000);
        metaServerName = regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO);
    }
    RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper());
    assertEquals("Wrong state for meta!", RegionState.State.OPEN, metaState.getState());
    assertNotEquals("Meta is on master!", metaServerName, master.getServerName());
    HRegionServer metaRegionServer = cluster.getRegionServer(metaServerName);
    // Delete the ephemeral node of the meta-carrying region server.
    // This is trigger the expire of this region server on the master.
    String rsEphemeralNodePath = ZNodePaths.joinZNode(master.getZooKeeper().getZNodePaths().rsZNode, metaServerName.toString());
    ZKUtil.deleteNode(master.getZooKeeper(), rsEphemeralNodePath);
    LOG.info("Deleted the znode for the RegionServer hosting hbase:meta; waiting on SSH");
    // Wait for SSH to finish
    final ServerManager serverManager = master.getServerManager();
    final ServerName priorMetaServerName = metaServerName;
    TEST_UTIL.waitFor(60000, 100, () -> metaRegionServer.isStopped());
    TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return !serverManager.isServerOnline(priorMetaServerName) && !serverManager.areDeadServersInProgress();
        }
    });
    LOG.info("Past wait on RIT");
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    // Now, make sure meta is assigned
    assertTrue("Meta should be assigned", regionStates.isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO));
    // Now, make sure meta is registered in zk
    metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper());
    assertEquals("Meta should not be in transition", RegionState.State.OPEN, metaState.getState());
    assertEquals("Meta should be assigned", metaState.getServerName(), regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO));
    assertNotEquals("Meta should be assigned on a different server", metaState.getServerName(), metaServerName);
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) ServerName(org.apache.hadoop.hbase.ServerName) Waiter(org.apache.hadoop.hbase.Waiter) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Aggregations

RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)26 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)18 Test (org.junit.Test)17 TableName (org.apache.hadoop.hbase.TableName)15 IOException (java.io.IOException)13 ServerName (org.apache.hadoop.hbase.ServerName)12 HMaster (org.apache.hadoop.hbase.master.HMaster)10 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)9 List (java.util.List)7 Waiter (org.apache.hadoop.hbase.Waiter)7 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)7 FavoredNodesManager (org.apache.hadoop.hbase.favored.FavoredNodesManager)7 Table (org.apache.hadoop.hbase.client.Table)5 ArrayList (java.util.ArrayList)4 Configuration (org.apache.hadoop.conf.Configuration)3 FavoredNodeAssignmentHelper (org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper)3 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)3 Ignore (org.junit.Ignore)3 UncheckedIOException (java.io.UncheckedIOException)2 Map (java.util.Map)2