Search in sources :

Example 11 with LocalHBaseCluster

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

the class TestRegionServerReportForDuty method setUp.

@Before
public void setUp() throws Exception {
    testUtil = new HBaseTestingUtil();
    testUtil.startMiniDFSCluster(1);
    testUtil.startMiniZKCluster(1);
    testUtil.createRootDir();
    cluster = new LocalHBaseCluster(testUtil.getConfiguration(), 0, 0);
}
Also used : HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) LocalHBaseCluster(org.apache.hadoop.hbase.LocalHBaseCluster) Before(org.junit.Before)

Example 12 with LocalHBaseCluster

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

the class TestRSKilledWhenInitializing method testRSTerminationAfterRegisteringToMasterBeforeCreatingEphemeralNode.

/**
 * Test verifies whether a region server is removed from online servers list in master if it went
 * down after registering with master. Test will TIMEOUT if an error!!!!
 * @throws Exception
 */
@Test
public void testRSTerminationAfterRegisteringToMasterBeforeCreatingEphemeralNode() throws Exception {
    // Create config to use for this cluster
    Configuration conf = HBaseConfiguration.create();
    conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1);
    // Start the cluster
    final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(conf);
    TEST_UTIL.startMiniDFSCluster(3);
    TEST_UTIL.startMiniZKCluster();
    TEST_UTIL.createRootDir();
    final LocalHBaseCluster cluster = new LocalHBaseCluster(conf, NUM_MASTERS, NUM_RS, HMaster.class, RegisterAndDieRegionServer.class);
    final MasterThread master = startMaster(cluster.getMasters().get(0));
    try {
        // Master is up waiting on RegionServers to check in. Now start RegionServers.
        for (int i = 0; i < NUM_RS; i++) {
            cluster.getRegionServers().get(i).start();
        }
        // Expected total regionservers depends on whether Master can host regions or not.
        int expectedTotalRegionServers = NUM_RS;
        List<ServerName> onlineServersList = null;
        do {
            onlineServersList = master.getMaster().getServerManager().getOnlineServersList();
        } while (onlineServersList.size() < expectedTotalRegionServers);
        // Wait until killedRS is set. Means RegionServer is starting to go down.
        while (killedRS.get() == null) {
            Threads.sleep(1);
        }
        // Wait on the RegionServer to fully die.
        while (cluster.getLiveRegionServers().size() >= expectedTotalRegionServers) {
            Threads.sleep(1);
        }
        // being reassigned.
        while (!master.getMaster().isInitialized()) {
            Threads.sleep(1);
        }
        // Now in steady state. How many regions open? Master should have too many regionservers
        // showing still. The downed RegionServer should still be showing as registered.
        assertTrue(master.getMaster().getServerManager().isServerOnline(killedRS.get()));
        // Find non-meta region (namespace?) and assign to the killed server. That'll trigger cleanup.
        Map<RegionInfo, ServerName> assignments = null;
        do {
            assignments = master.getMaster().getAssignmentManager().getRegionStates().getRegionAssignments();
        } while (assignments == null || assignments.size() < 2);
        RegionInfo hri = null;
        for (Map.Entry<RegionInfo, ServerName> e : assignments.entrySet()) {
            if (e.getKey().isMetaRegion())
                continue;
            hri = e.getKey();
            break;
        }
        // Try moving region to the killed server. It will fail. As by-product, we will
        // remove the RS from Master online list because no corresponding znode.
        assertEquals(expectedTotalRegionServers, master.getMaster().getServerManager().getOnlineServersList().size());
        LOG.info("Move " + hri.getEncodedName() + " to " + killedRS.get());
        master.getMaster().move(hri.getEncodedNameAsBytes(), Bytes.toBytes(killedRS.get().toString()));
        // Wait until the RS no longer shows as registered in Master.
        while (onlineServersList.size() > (NUM_RS + 1)) {
            Thread.sleep(100);
            onlineServersList = master.getMaster().getServerManager().getOnlineServersList();
        }
    } finally {
        // Shutdown is messy with complaints about fs being closed. Why? TODO.
        cluster.shutdown();
        cluster.join();
        TEST_UTIL.shutdownMiniDFSCluster();
        TEST_UTIL.shutdownMiniZKCluster();
        TEST_UTIL.cleanupTestDir();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) LocalHBaseCluster(org.apache.hadoop.hbase.LocalHBaseCluster) Map(java.util.Map) Test(org.junit.Test)

Aggregations

LocalHBaseCluster (org.apache.hadoop.hbase.LocalHBaseCluster)12 Configuration (org.apache.hadoop.conf.Configuration)6 Path (org.apache.hadoop.fs.Path)5 File (java.io.File)4 TokenProvider (org.apache.hadoop.hbase.security.token.TokenProvider)4 BeforeClass (org.junit.BeforeClass)4 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)3 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)2 MasterThread (org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread)2 ConfigurationFactory (org.apache.phoenix.query.ConfigurationFactory)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Map (java.util.Map)1 ServerName (org.apache.hadoop.hbase.ServerName)1 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)1 StartTestingClusterOption (org.apache.hadoop.hbase.StartTestingClusterOption)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 RetriesExhaustedException (org.apache.hadoop.hbase.client.RetriesExhaustedException)1 ConnectionClosedException (org.apache.hadoop.hbase.exceptions.ConnectionClosedException)1 AccessController (org.apache.hadoop.hbase.security.access.AccessController)1