Search in sources :

Example 26 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestAsyncRegionAdminApi method createTableAndGetOneRegion.

RegionInfo createTableAndGetOneRegion(final TableName tableName) throws IOException, InterruptedException, ExecutionException {
    TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
    admin.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), 5).get();
    // wait till the table is assigned
    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
    long timeoutTime = EnvironmentEdgeManager.currentTime() + 3000;
    while (true) {
        List<RegionInfo> regions = master.getAssignmentManager().getRegionStates().getRegionsOfTable(tableName);
        if (regions.size() > 3) {
            return regions.get(2);
        }
        long now = EnvironmentEdgeManager.currentTime();
        if (now > timeoutTime) {
            fail("Could not find an online region");
        }
        Thread.sleep(10);
    }
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster)

Example 27 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class HBaseTestingUtility method expireMasterSession.

/**
 * Expire the Master's session
 * @throws Exception
 */
public void expireMasterSession() throws Exception {
    HMaster master = getMiniHBaseCluster().getMaster();
    expireSession(master.getZooKeeper(), false);
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster)

Example 28 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class HBaseTestingUtility method moveRegionAndWait.

/**
 * Move region to destination server and wait till region is completely moved and online
 *
 * @param destRegion region to move
 * @param destServer destination server of the region
 * @throws InterruptedException
 * @throws IOException
 */
public void moveRegionAndWait(RegionInfo destRegion, ServerName destServer) throws InterruptedException, IOException {
    HMaster master = getMiniHBaseCluster().getMaster();
    // TODO: Here we start the move. The move can take a while.
    getAdmin().move(destRegion.getEncodedNameAsBytes(), destServer);
    while (true) {
        ServerName serverName = master.getAssignmentManager().getRegionStates().getRegionServerOfRegion(destRegion);
        if (serverName != null && serverName.equals(destServer)) {
            assertRegionOnServer(destRegion, serverName, 2000);
            break;
        }
        Thread.sleep(10);
    }
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster)

Example 29 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestSeparateClientZKCluster method testMasterSwitch.

@Test
public void testMasterSwitch() throws Exception {
    // get an admin instance and issue some request first
    Connection conn = TEST_UTIL.getConnection();
    try (Admin admin = conn.getAdmin()) {
        LOG.debug("Tables: " + admin.listTableDescriptors());
        SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
        // switch active master
        HMaster master = cluster.getMaster();
        master.stopMaster();
        LOG.info("Stopped master {}", master.getServerName());
        while (master.isAlive()) {
            Thread.sleep(200);
        }
        LOG.info("Shutdown master {}", master.getServerName());
        while (cluster.getMaster() == null || !cluster.getMaster().isInitialized()) {
            LOG.info("Get master {}", cluster.getMaster() == null ? "null" : cluster.getMaster().getServerName());
            Thread.sleep(200);
        }
        LOG.info("Got master {}", cluster.getMaster().getServerName());
        // confirm client access still works
        assertTrue(admin.balance(BalanceRequest.defaultInstance()).isBalancerRan());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 30 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestMasterObserverPostCalls method testPostCreateNamespace.

@Test
public void testPostCreateNamespace() throws IOException {
    final Admin admin = UTIL.getAdmin();
    final String ns = "postcreatens";
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    MasterObserverForTest observer = master.getMasterCoprocessorHost().findCoprocessor(MasterObserverForTest.class);
    // Validate that the post hook is called
    int preCount = observer.postHookCalls.get();
    NamespaceDescriptor nsDesc = NamespaceDescriptor.create(ns).build();
    admin.createNamespace(nsDesc);
    int postCount = observer.postHookCalls.get();
    assertEquals("Expected 1 invocation of postModifyNamespace", preCount + 1, postCount);
    // Then, validate that it's not called when the call fails
    preCount = observer.postHookCalls.get();
    try {
        admin.createNamespace(nsDesc);
        fail("Creating an already present namespace should fail");
    } catch (IOException e) {
    // Pass
    }
    postCount = observer.postHookCalls.get();
    assertEquals("Expected no invocations of postModifyNamespace when the operation fails", preCount, postCount);
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Aggregations

HMaster (org.apache.hadoop.hbase.master.HMaster)132 Test (org.junit.Test)91 TableName (org.apache.hadoop.hbase.TableName)42 IOException (java.io.IOException)33 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)31 ServerName (org.apache.hadoop.hbase.ServerName)24 Admin (org.apache.hadoop.hbase.client.Admin)23 Table (org.apache.hadoop.hbase.client.Table)23 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)22 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)16 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)15 Configuration (org.apache.hadoop.conf.Configuration)13 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 BeforeClass (org.junit.BeforeClass)11 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)10 List (java.util.List)9 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)9 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)9 RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)9 ClassRule (org.junit.ClassRule)9