Search in sources :

Example 26 with MiniHBaseCluster

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

the class TestRegionMover method testUnloadWithAck.

@Test
public void testUnloadWithAck() throws Exception {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HRegionServer regionServer = cluster.getRegionServer(0);
    String rsName = regionServer.getServerName().getHostname();
    int port = regionServer.getServerName().getPort();
    String rs = rsName + ":" + Integer.toString(port);
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs).ack(true);
    RegionMover rm = rmBuilder.build();
    rm.setConf(TEST_UTIL.getConfiguration());
    rm.unload();
    LOG.info("Unloading " + rs);
    assertEquals(0, regionServer.getNumberOfOnlineRegions());
}
Also used : RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 27 with MiniHBaseCluster

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

the class TestRegionMover method testUnloadWithoutAck.

@Test
public void testUnloadWithoutAck() throws Exception {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    final HRegionServer regionServer = cluster.getRegionServer(0);
    final int noRegions = regionServer.getNumberOfOnlineRegions();
    String rsName = regionServer.getServerName().getHostname();
    int port = regionServer.getServerName().getPort();
    String rs = rsName + ":" + Integer.toString(port);
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs).ack(false);
    RegionMover rm = rmBuilder.build();
    rm.setConf(TEST_UTIL.getConfiguration());
    LOG.info("Unloading " + rs);
    rm.unload();
    TEST_UTIL.waitFor(5000, 500, new Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return regionServer.getNumberOfOnlineRegions() < noRegions;
        }
    });
}
Also used : RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 28 with MiniHBaseCluster

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

the class TestHTableMultiplexerFlushCache method testOnRegionMove.

@Test
public void testOnRegionMove() throws Exception {
    // This test is doing near exactly the same thing that testOnRegionChange but avoiding the
    // potential to get a ConnectionClosingException. By moving the region, we can be certain that
    // the connection is still valid and that the implementation is correctly handling an invalid
    // Region cache (and not just tearing down the entire connection).
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final int NUM_REGIONS = 10;
    Table htable = TEST_UTIL.createTable(tableName, new byte[][] { FAMILY }, 3, Bytes.toBytes("aaaaa"), Bytes.toBytes("zzzzz"), NUM_REGIONS);
    HTableMultiplexer multiplexer = new HTableMultiplexer(TEST_UTIL.getConfiguration(), PER_REGIONSERVER_QUEUE_SIZE);
    final RegionLocator regionLocator = TEST_UTIL.getConnection().getRegionLocator(tableName);
    Pair<byte[][], byte[][]> startEndRows = regionLocator.getStartEndKeys();
    byte[] row = startEndRows.getFirst()[1];
    assertTrue("2nd region should not start with empty row", row != null && row.length > 0);
    Put put = new Put(row).addColumn(FAMILY, QUALIFIER1, VALUE1);
    assertTrue("multiplexer.put returns", multiplexer.put(tableName, put));
    checkExistence(htable, row, FAMILY, QUALIFIER1, VALUE1);
    final HRegionLocation loc = regionLocator.getRegionLocation(row);
    final MiniHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster();
    // The current server for the region we're writing to
    final ServerName originalServer = loc.getServerName();
    ServerName newServer = null;
    // Find a new server to move that region to
    for (int i = 0; i < SLAVES; i++) {
        HRegionServer rs = hbaseCluster.getRegionServer(0);
        if (!rs.getServerName().equals(originalServer.getServerName())) {
            newServer = rs.getServerName();
            break;
        }
    }
    assertNotNull("Did not find a new RegionServer to use", newServer);
    // Move the region
    LOG.info("Moving " + loc.getRegionInfo().getEncodedName() + " from " + originalServer + " to " + newServer);
    TEST_UTIL.getAdmin().move(loc.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(newServer.getServerName()));
    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
    // Send a new Put
    put = new Put(row).addColumn(FAMILY, QUALIFIER2, VALUE2);
    assertTrue("multiplexer.put returns", multiplexer.put(tableName, put));
    // We should see the update make it to the new server eventually
    checkExistence(htable, row, FAMILY, QUALIFIER2, VALUE2);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 29 with MiniHBaseCluster

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

the class TestRollingRestart method testBasicRollingRestart.

@Test(timeout = 500000)
public void testBasicRollingRestart() throws Exception {
    // Start a cluster with 2 masters and 4 regionservers
    final int NUM_MASTERS = 2;
    final int NUM_RS = 3;
    final int NUM_REGIONS_TO_CREATE = 20;
    int expectedNumRS = 3;
    // Start the cluster
    log("Starting cluster");
    Configuration conf = HBaseConfiguration.create();
    HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
    TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    log("Waiting for active/ready master");
    cluster.waitForActiveAndReadyMaster();
    // Create a table with regions
    final TableName tableName = TableName.valueOf(name.getMethodName());
    byte[] family = Bytes.toBytes("family");
    log("Creating table with " + NUM_REGIONS_TO_CREATE + " regions");
    Table ht = TEST_UTIL.createMultiRegionTable(tableName, family, NUM_REGIONS_TO_CREATE);
    int numRegions = -1;
    try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
        numRegions = r.getStartKeys().length;
    }
    // catalogs
    numRegions += 1;
    log("Waiting for no more RIT\n");
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    log("Disabling table\n");
    TEST_UTIL.getAdmin().disableTable(tableName);
    log("Waiting for no more RIT\n");
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    NavigableSet<String> regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
    log("Verifying only catalog and namespace regions are assigned\n");
    if (regions.size() != 2) {
        for (String oregion : regions) log("Region still online: " + oregion);
    }
    assertEquals(2, regions.size());
    log("Enabling table\n");
    TEST_UTIL.getAdmin().enableTable(tableName);
    log("Waiting for no more RIT\n");
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    log("Verifying there are " + numRegions + " assigned on cluster\n");
    regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
    assertRegionsAssigned(cluster, regions);
    assertEquals(expectedNumRS, cluster.getRegionServerThreads().size());
    // Add a new regionserver
    log("Adding a fourth RS");
    RegionServerThread restarted = cluster.startRegionServer();
    expectedNumRS++;
    restarted.waitForServerOnline();
    log("Additional RS is online");
    log("Waiting for no more RIT");
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    log("Verifying there are " + numRegions + " assigned on cluster");
    assertRegionsAssigned(cluster, regions);
    assertEquals(expectedNumRS, cluster.getRegionServerThreads().size());
    // Master Restarts
    List<MasterThread> masterThreads = cluster.getMasterThreads();
    MasterThread activeMaster = null;
    MasterThread backupMaster = null;
    assertEquals(2, masterThreads.size());
    if (masterThreads.get(0).getMaster().isActiveMaster()) {
        activeMaster = masterThreads.get(0);
        backupMaster = masterThreads.get(1);
    } else {
        activeMaster = masterThreads.get(1);
        backupMaster = masterThreads.get(0);
    }
    // Bring down the backup master
    log("Stopping backup master\n\n");
    backupMaster.getMaster().stop("Stop of backup during rolling restart");
    cluster.hbaseCluster.waitOnMaster(backupMaster);
    // Bring down the primary master
    log("Stopping primary master\n\n");
    activeMaster.getMaster().stop("Stop of active during rolling restart");
    cluster.hbaseCluster.waitOnMaster(activeMaster);
    // Start primary master
    log("Restarting primary master\n\n");
    activeMaster = cluster.startMaster();
    cluster.waitForActiveAndReadyMaster();
    // Start backup master
    log("Restarting backup master\n\n");
    backupMaster = cluster.startMaster();
    assertEquals(expectedNumRS, cluster.getRegionServerThreads().size());
    // RegionServer Restarts
    // Bring them down, one at a time, waiting between each to complete
    List<RegionServerThread> regionServers = cluster.getLiveRegionServerThreads();
    int num = 1;
    int total = regionServers.size();
    for (RegionServerThread rst : regionServers) {
        ServerName serverName = rst.getRegionServer().getServerName();
        log("Stopping region server " + num + " of " + total + " [ " + serverName + "]");
        rst.getRegionServer().stop("Stopping RS during rolling restart");
        cluster.hbaseCluster.waitOnRegionServer(rst);
        log("Waiting for RS shutdown to be handled by master");
        waitForRSShutdownToStartAndFinish(activeMaster, serverName);
        log("RS shutdown done, waiting for no more RIT");
        TEST_UTIL.waitUntilNoRegionsInTransition(60000);
        log("Verifying there are " + numRegions + " assigned on cluster");
        assertRegionsAssigned(cluster, regions);
        expectedNumRS--;
        assertEquals(expectedNumRS, cluster.getRegionServerThreads().size());
        log("Restarting region server " + num + " of " + total);
        restarted = cluster.startRegionServer();
        restarted.waitForServerOnline();
        expectedNumRS++;
        log("Region server " + num + " is back online");
        log("Waiting for no more RIT");
        TEST_UTIL.waitUntilNoRegionsInTransition(60000);
        log("Verifying there are " + numRegions + " assigned on cluster");
        assertRegionsAssigned(cluster, regions);
        assertEquals(expectedNumRS, cluster.getRegionServerThreads().size());
        num++;
    }
    Thread.sleep(1000);
    assertRegionsAssigned(cluster, regions);
    // TODO: Bring random 3 of 4 RS down at the same time
    ht.close();
    // Stop the cluster
    TEST_UTIL.shutdownMiniCluster();
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) ServerName(org.apache.hadoop.hbase.ServerName) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Test(org.junit.Test)

Example 30 with MiniHBaseCluster

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

the class TestMasterShutdown method testMasterShutdown.

/**
   * Simple test of shutdown.
   * <p>
   * Starts with three masters.  Tells the active master to shutdown the cluster.
   * Verifies that all masters are properly shutdown.
   * @throws Exception
   */
@Test(timeout = 120000)
public void testMasterShutdown() throws Exception {
    final int NUM_MASTERS = 3;
    final int NUM_RS = 3;
    // Create config to use for this cluster
    Configuration conf = HBaseConfiguration.create();
    // Start the cluster
    HBaseTestingUtility htu = new HBaseTestingUtility(conf);
    htu.startMiniCluster(NUM_MASTERS, NUM_RS);
    MiniHBaseCluster cluster = htu.getHBaseCluster();
    // get all the master threads
    List<MasterThread> masterThreads = cluster.getMasterThreads();
    // wait for each to come online
    for (MasterThread mt : masterThreads) {
        assertTrue(mt.isAlive());
    }
    // find the active master
    HMaster active = null;
    for (int i = 0; i < masterThreads.size(); i++) {
        if (masterThreads.get(i).getMaster().isActiveMaster()) {
            active = masterThreads.get(i).getMaster();
            break;
        }
    }
    assertNotNull(active);
    // make sure the other two are backup masters
    ClusterStatus status = active.getClusterStatus();
    assertEquals(2, status.getBackupMastersSize());
    assertEquals(2, status.getBackupMasters().size());
    // tell the active master to shutdown the cluster
    active.shutdown();
    for (int i = NUM_MASTERS - 1; i >= 0; --i) {
        cluster.waitOnMaster(i);
    }
    // make sure all the masters properly shutdown
    assertEquals(0, masterThreads.size());
    htu.shutdownMiniCluster();
}
Also used : HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Test(org.junit.Test)

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