Search in sources :

Example 66 with SingleProcessHBaseCluster

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

the class TestPerColumnFamilyFlush method getRegionWithName.

// Find the (first) region which has the specified name.
private static Pair<HRegion, HRegionServer> getRegionWithName(TableName tableName) {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
    List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
    for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
        HRegionServer hrs = rsts.get(i).getRegionServer();
        for (HRegion region : hrs.getRegions(tableName)) {
            return Pair.newPair(region, hrs);
        }
    }
    return null;
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster)

Example 67 with SingleProcessHBaseCluster

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

the class TestMultiSlaveReplication method rollWALAndWait.

private void rollWALAndWait(final HBaseTestingUtil utility, final TableName table, final byte[] row) throws IOException {
    final Admin admin = utility.getAdmin();
    final SingleProcessHBaseCluster cluster = utility.getMiniHBaseCluster();
    // find the region that corresponds to the given row.
    HRegion region = null;
    for (HRegion candidate : cluster.getRegions(table)) {
        if (HRegion.rowIsInRange(candidate.getRegionInfo(), row)) {
            region = candidate;
            break;
        }
    }
    assertNotNull("Couldn't find the region for row '" + Arrays.toString(row) + "'", region);
    final CountDownLatch latch = new CountDownLatch(1);
    // listen for successful log rolls
    final WALActionsListener listener = new WALActionsListener() {

        @Override
        public void postLogRoll(final Path oldPath, final Path newPath) throws IOException {
            latch.countDown();
        }
    };
    region.getWAL().registerWALActionsListener(listener);
    // request a roll
    admin.rollWALWriter(cluster.getServerHoldingRegion(region.getTableDescriptor().getTableName(), region.getRegionInfo().getRegionName()));
    // wait
    try {
        latch.await();
    } catch (InterruptedException exception) {
        LOG.warn("Interrupted while waiting for the wal of '" + region + "' to roll. If later " + "replication tests fail, it's probably because we should still be waiting.");
        Thread.currentThread().interrupt();
    }
    region.getWAL().unregisterWALActionsListener(listener);
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) Path(org.apache.hadoop.fs.Path) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) Admin(org.apache.hadoop.hbase.client.Admin) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 68 with SingleProcessHBaseCluster

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

the class TestShutdownBackupMaster method testShutdownWhileBecomingActive.

@Test
public void testShutdownWhileBecomingActive() throws InterruptedException {
    SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster activeMaster = null;
    HMaster backupMaster = null;
    for (MasterThread t : cluster.getMasterThreads()) {
        if (t.getMaster().isActiveMaster()) {
            activeMaster = t.getMaster();
        } else {
            backupMaster = t.getMaster();
        }
    }
    assertNotNull(activeMaster);
    assertNotNull(backupMaster);
    ARRIVE = new CountDownLatch(1);
    CONTINUE = new CountDownLatch(1);
    activeMaster.abort("Aborting active master for test");
    // wait until we arrive the initClusterSchemaService
    ARRIVE.await();
    // killall RSes
    cluster.getRegionServerThreads().stream().map(t -> t.getRegionServer()).forEachOrdered(rs -> rs.abort("Aborting RS for test"));
    CONTINUE.countDown();
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) CountDownLatch(java.util.concurrent.CountDownLatch) HConstants(org.apache.hadoop.hbase.HConstants) Configuration(org.apache.hadoop.conf.Configuration) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) ClassRule(org.junit.ClassRule) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 69 with SingleProcessHBaseCluster

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

the class TestRetainAssignmentOnRestart method testRetainAssignmentOnClusterRestart.

/**
 * This tests retaining assignments on a cluster restart
 */
@Test
public void testRetainAssignmentOnClusterRestart() throws Exception {
    setupCluster();
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
    List<JVMClusterUtil.RegionServerThread> threads = cluster.getLiveRegionServerThreads();
    assertEquals(NUM_OF_RS, threads.size());
    int[] rsPorts = new int[NUM_OF_RS];
    for (int i = 0; i < NUM_OF_RS; i++) {
        rsPorts[i] = threads.get(i).getRegionServer().getServerName().getPort();
    }
    // We don't have to use SnapshotOfRegionAssignmentFromMeta. We use it here because AM used to
    // use it to load all user region placements
    SnapshotOfRegionAssignmentFromMeta snapshot = new SnapshotOfRegionAssignmentFromMeta(master.getConnection());
    snapshot.initialize();
    Map<RegionInfo, ServerName> regionToRegionServerMap = snapshot.getRegionToRegionServerMap();
    for (ServerName serverName : regionToRegionServerMap.values()) {
        // Test only, no need to optimize
        boolean found = false;
        for (int k = 0; k < NUM_OF_RS && !found; k++) {
            found = serverName.getPort() == rsPorts[k];
        }
        assertTrue(found);
    }
    LOG.info("\n\nShutting down HBase cluster");
    cluster.stopMaster(0);
    cluster.shutdown();
    cluster.waitUntilShutDown();
    LOG.info("\n\nSleeping a bit");
    Thread.sleep(2000);
    LOG.info("\n\nStarting cluster the second time with the same ports");
    cluster.getConf().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 3);
    master = cluster.startMaster().getMaster();
    for (int i = 0; i < NUM_OF_RS; i++) {
        cluster.getConf().setInt(HConstants.REGIONSERVER_PORT, rsPorts[i]);
        cluster.startRegionServer();
    }
    ensureServersWithSamePort(master, rsPorts);
    // Wait till master is initialized and all regions are assigned
    for (TableName TABLE : TABLES) {
        UTIL.waitTableAvailable(TABLE);
    }
    UTIL.waitUntilNoRegionsInTransition(60000);
    snapshot = new SnapshotOfRegionAssignmentFromMeta(master.getConnection());
    snapshot.initialize();
    Map<RegionInfo, ServerName> newRegionToRegionServerMap = snapshot.getRegionToRegionServerMap();
    assertEquals(regionToRegionServerMap.size(), newRegionToRegionServerMap.size());
    for (Map.Entry<RegionInfo, ServerName> entry : newRegionToRegionServerMap.entrySet()) {
        ServerName oldServer = regionToRegionServerMap.get(entry.getKey());
        ServerName currentServer = entry.getValue();
        LOG.info("Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer);
        assertEquals(entry.getKey().toString(), oldServer.getAddress(), currentServer.getAddress());
        assertNotEquals(oldServer.getStartcode(), currentServer.getStartcode());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) Map(java.util.Map) Test(org.junit.Test)

Example 70 with SingleProcessHBaseCluster

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

the class TestRetainAssignmentOnRestart method testRetainAssignmentOnSingleRSRestart.

/**
 * This tests retaining assignments on a single node restart
 */
@Test
public void testRetainAssignmentOnSingleRSRestart() throws Exception {
    setupCluster();
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
    List<JVMClusterUtil.RegionServerThread> threads = cluster.getLiveRegionServerThreads();
    assertEquals(NUM_OF_RS, threads.size());
    int[] rsPorts = new int[NUM_OF_RS];
    for (int i = 0; i < NUM_OF_RS; i++) {
        rsPorts[i] = threads.get(i).getRegionServer().getServerName().getPort();
    }
    // We don't have to use SnapshotOfRegionAssignmentFromMeta. We use it here because AM used to
    // use it to load all user region placements
    SnapshotOfRegionAssignmentFromMeta snapshot = new SnapshotOfRegionAssignmentFromMeta(master.getConnection());
    snapshot.initialize();
    Map<RegionInfo, ServerName> regionToRegionServerMap = snapshot.getRegionToRegionServerMap();
    for (ServerName serverName : regionToRegionServerMap.values()) {
        // Test only, no need to optimize
        boolean found = false;
        for (int k = 0; k < NUM_OF_RS && !found; k++) {
            found = serverName.getPort() == rsPorts[k];
        }
        assertTrue(found);
    }
    // Server to be restarted
    ServerName deadRS = threads.get(0).getRegionServer().getServerName();
    LOG.info("\n\nStopping HMaster and {} server", deadRS);
    // Stopping master first so that region server SCP will not be initiated
    cluster.stopMaster(0);
    cluster.waitForMasterToStop(master.getServerName(), 5000);
    cluster.stopRegionServer(deadRS);
    LOG.info("\n\nSleeping a bit");
    Thread.sleep(2000);
    LOG.info("\n\nStarting HMaster and region server {} second time with the same port", deadRS);
    cluster.getConf().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 3);
    master = cluster.startMaster().getMaster();
    cluster.getConf().setInt(HConstants.REGIONSERVER_PORT, deadRS.getPort());
    cluster.startRegionServer();
    ensureServersWithSamePort(master, rsPorts);
    // Wait till master is initialized and all regions are assigned
    for (TableName TABLE : TABLES) {
        UTIL.waitTableAvailable(TABLE);
    }
    UTIL.waitUntilNoRegionsInTransition(60000);
    snapshot = new SnapshotOfRegionAssignmentFromMeta(master.getConnection());
    snapshot.initialize();
    Map<RegionInfo, ServerName> newRegionToRegionServerMap = snapshot.getRegionToRegionServerMap();
    assertEquals(regionToRegionServerMap.size(), newRegionToRegionServerMap.size());
    for (Map.Entry<RegionInfo, ServerName> entry : newRegionToRegionServerMap.entrySet()) {
        ServerName oldServer = regionToRegionServerMap.get(entry.getKey());
        ServerName currentServer = entry.getValue();
        LOG.info("Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer);
        assertEquals(entry.getKey().toString(), oldServer.getAddress(), currentServer.getAddress());
        if (deadRS.getPort() == oldServer.getPort()) {
            // Restarted RS start code wont be same
            assertNotEquals(oldServer.getStartcode(), currentServer.getStartcode());
        } else {
            assertEquals(oldServer.getStartcode(), currentServer.getStartcode());
        }
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) Map(java.util.Map) Test(org.junit.Test)

Aggregations

SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)85 Test (org.junit.Test)69 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)31 TableName (org.apache.hadoop.hbase.TableName)26 Admin (org.apache.hadoop.hbase.client.Admin)24 Table (org.apache.hadoop.hbase.client.Table)22 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)22 HMaster (org.apache.hadoop.hbase.master.HMaster)21 ServerName (org.apache.hadoop.hbase.ServerName)18 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)18 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)14 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)13 IOException (java.io.IOException)12 Configuration (org.apache.hadoop.conf.Configuration)12 Put (org.apache.hadoop.hbase.client.Put)12 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)12 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)10 File (java.io.File)9 Path (org.apache.hadoop.fs.Path)9 RegionMoverBuilder (org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder)9