Search in sources :

Example 61 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestMaster method testMoveRegionWhenNotInitialized.

@Test
public void testMoveRegionWhenNotInitialized() {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HMaster m = cluster.getMaster();
    try {
        // fake it, set back later
        m.setInitialized(false);
        HRegionInfo meta = HRegionInfo.FIRST_META_REGIONINFO;
        m.move(meta.getEncodedNameAsBytes(), null);
        fail("Region should not be moved since master is not initialized");
    } catch (IOException ioe) {
        assertTrue(ioe instanceof PleaseHoldException);
    } finally {
        m.setInitialized(true);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) PleaseHoldException(org.apache.hadoop.hbase.PleaseHoldException) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) IOException(java.io.IOException) Test(org.junit.Test)

Example 62 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestAssignmentManagerOnCluster method testRestartMetaRegionServer.

/**
   * This tests restarting meta regionserver
   */
@Test(timeout = 180000)
public void testRestartMetaRegionServer() throws Exception {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    boolean stoppedARegionServer = false;
    try {
        HMaster master = cluster.getMaster();
        RegionStates regionStates = master.getAssignmentManager().getRegionStates();
        ServerName metaServerName = regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO);
        if (master.getServerName().equals(metaServerName)) {
            // Move meta off master
            metaServerName = cluster.getLiveRegionServerThreads().get(0).getRegionServer().getServerName();
            master.move(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), Bytes.toBytes(metaServerName.getServerName()));
            TEST_UTIL.waitUntilNoRegionsInTransition(60000);
        }
        RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper());
        assertEquals("Meta should be not in transition", metaState.getState(), RegionState.State.OPEN);
        assertNotEquals("Meta should be moved off master", metaState.getServerName(), master.getServerName());
        assertEquals("Meta should be on the meta server", metaState.getServerName(), metaServerName);
        cluster.killRegionServer(metaServerName);
        stoppedARegionServer = true;
        cluster.waitForRegionServerToStop(metaServerName, 60000);
        // Wait for SSH to finish
        final ServerName oldServerName = metaServerName;
        final ServerManager serverManager = master.getServerManager();
        TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                return serverManager.isServerDead(oldServerName) && !serverManager.areDeadServersInProgress();
            }
        });
        TEST_UTIL.waitUntilNoRegionsInTransition(60000);
        // Now, make sure meta is assigned
        assertTrue("Meta should be assigned", regionStates.isRegionOnline(HRegionInfo.FIRST_META_REGIONINFO));
        // Now, make sure meta is registered in zk
        metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper());
        assertEquals("Meta should be not in transition", metaState.getState(), RegionState.State.OPEN);
        assertEquals("Meta should be assigned", metaState.getServerName(), regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO));
        assertNotEquals("Meta should be assigned on a different server", metaState.getServerName(), metaServerName);
    } finally {
        if (stoppedARegionServer) {
            cluster.startRegionServer();
        }
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Waiter(org.apache.hadoop.hbase.Waiter) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) Test(org.junit.Test)

Example 63 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestAssignmentManagerOnCluster method testAssignOfflinedRegionBySSH.

/**
   * Test offlined region is assigned by SSH
   */
@Test(timeout = 60000)
public void testAssignOfflinedRegionBySSH() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    MyMaster master = null;
    try {
        HTableDescriptor desc = new HTableDescriptor(tableName);
        desc.addFamily(new HColumnDescriptor(FAMILY));
        admin.createTable(desc);
        Table meta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME);
        HRegionInfo hri = new HRegionInfo(desc.getTableName(), Bytes.toBytes("A"), Bytes.toBytes("Z"));
        MetaTableAccessor.addRegionToMeta(meta, hri);
        // Assign the region
        master = (MyMaster) cluster.getMaster();
        AssignmentManager am = master.getAssignmentManager();
        am.assign(hri);
        RegionStates regionStates = am.getRegionStates();
        ServerName metaServer = regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO);
        ServerName oldServerName = null;
        while (true) {
            assertTrue(am.waitForAssignment(hri));
            RegionState state = regionStates.getRegionState(hri);
            oldServerName = state.getServerName();
            if (!ServerName.isSameHostnameAndPort(oldServerName, metaServer)) {
                // Mark the hosting server aborted, but don't actually kill it.
                // It doesn't have meta on it.
                MyRegionServer.abortedServer = oldServerName;
                break;
            }
            int i = cluster.getServerWithMeta();
            HRegionServer rs = cluster.getRegionServer(i == 0 ? 1 : 0);
            oldServerName = rs.getServerName();
            master.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(oldServerName.getServerName()));
        }
        // Make sure the region is assigned on the dead server
        assertTrue(regionStates.isRegionOnline(hri));
        assertEquals(oldServerName, regionStates.getRegionServerOfRegion(hri));
        // Kill the hosting server, which doesn't have meta on it.
        cluster.killRegionServer(oldServerName);
        cluster.waitForRegionServerToStop(oldServerName, -1);
        ServerManager serverManager = master.getServerManager();
        while (!serverManager.isServerDead(oldServerName) || serverManager.getDeadServers().areDeadServersInProgress()) {
            Thread.sleep(100);
        }
        // Let's check if it's assigned after it's out of transition.
        // no need to assign it manually, SSH should do it
        am.waitOnRegionToClearRegionsInTransition(hri);
        assertTrue(am.waitForAssignment(hri));
        ServerName serverName = master.getAssignmentManager().getRegionStates().getRegionServerOfRegion(hri);
        TEST_UTIL.assertRegionOnlyOnServer(hri, serverName, 200);
    } finally {
        MyRegionServer.abortedServer = null;
        TEST_UTIL.deleteTable(tableName);
        cluster.startRegionServer();
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 64 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestAssignmentListener method areAllRegionsLocatedOnSameServer.

private boolean areAllRegionsLocatedOnSameServer(TableName TABLE_NAME) {
    MiniHBaseCluster miniCluster = TEST_UTIL.getMiniHBaseCluster();
    int serverCount = 0;
    for (JVMClusterUtil.RegionServerThread regionThread : miniCluster.getRegionServerThreads()) {
        if (!regionThread.getRegionServer().getOnlineRegions(TABLE_NAME).isEmpty()) {
            ++serverCount;
        }
        if (serverCount > 1) {
            return false;
        }
    }
    return serverCount == 1;
}
Also used : JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster)

Example 65 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestRSGroups method afterMethod.

@After
public void afterMethod() throws Exception {
    deleteTableIfNecessary();
    deleteNamespaceIfNecessary();
    deleteGroups();
    int missing = NUM_SLAVES_BASE - getNumServers();
    LOG.info("Restoring servers: " + missing);
    for (int i = 0; i < missing; i++) {
        ((MiniHBaseCluster) cluster).startRegionServer();
    }
    rsGroupAdmin.addRSGroup("master");
    ServerName masterServerName = ((MiniHBaseCluster) cluster).getMaster().getServerName();
    try {
        rsGroupAdmin.moveServers(Sets.newHashSet(masterServerName.getAddress()), "master");
    } catch (Exception ex) {
        LOG.warn("Got this on setup, FYI", ex);
    }
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            LOG.info("Waiting for cleanup to finish " + rsGroupAdmin.listRSGroups());
            return rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size() == NUM_SLAVES_BASE;
        }
    });
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Waiter(org.apache.hadoop.hbase.Waiter) IOException(java.io.IOException) After(org.junit.After)

Aggregations

MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)86 Test (org.junit.Test)58 TableName (org.apache.hadoop.hbase.TableName)32 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)25 Table (org.apache.hadoop.hbase.client.Table)23 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)21 HMaster (org.apache.hadoop.hbase.master.HMaster)21 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)20 ServerName (org.apache.hadoop.hbase.ServerName)19 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)19 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)18 JVMClusterUtil (org.apache.hadoop.hbase.util.JVMClusterUtil)14 Admin (org.apache.hadoop.hbase.client.Admin)12 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 IOException (java.io.IOException)11 Region (org.apache.hadoop.hbase.regionserver.Region)11 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)10 Put (org.apache.hadoop.hbase.client.Put)8 TreeMap (java.util.TreeMap)7 Waiter (org.apache.hadoop.hbase.Waiter)7