Search in sources :

Example 86 with HMaster

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

the class TestAsyncRegionAdminApi method testAssignRegionAndUnassignRegion.

@Test
public void testAssignRegionAndUnassignRegion() throws Exception {
    createTableWithDefaultConf(tableName);
    // assign region.
    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
    AssignmentManager am = master.getAssignmentManager();
    RegionInfo hri = am.getRegionStates().getRegionsOfTable(tableName).get(0);
    // assert region on server
    RegionStates regionStates = am.getRegionStates();
    ServerName serverName = regionStates.getRegionServerOfRegion(hri);
    TEST_UTIL.assertRegionOnServer(hri, serverName, 200);
    assertTrue(regionStates.getRegionState(hri).isOpened());
    // Master should not abort, and region should stay assigned.
    try {
        admin.assign(hri.getRegionName()).get();
        fail("Should fail when assigning an already onlined region");
    } catch (ExecutionException e) {
        // Expected
        assertThat(e.getCause(), instanceOf(DoNotRetryRegionException.class));
    }
    assertFalse(am.getRegionStates().getRegionStateNode(hri).isInTransition());
    assertTrue(regionStates.getRegionState(hri).isOpened());
    // unassign region
    admin.unassign(hri.getRegionName(), true).get();
    assertFalse(am.getRegionStates().getRegionStateNode(hri).isInTransition());
    assertTrue(regionStates.getRegionState(hri).isClosed());
}
Also used : RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 87 with HMaster

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

the class TestAsyncRegionAdminApi method testMoveRegion.

@Test
public void testMoveRegion() throws Exception {
    admin.balancerSwitch(false).join();
    RegionInfo hri = createTableAndGetOneRegion(tableName);
    RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin();
    ServerName serverName = rawAdmin.getRegionLocation(hri.getRegionName()).get().getServerName();
    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
    ServerManager serverManager = master.getServerManager();
    ServerName destServerName = null;
    List<JVMClusterUtil.RegionServerThread> regionServers = TEST_UTIL.getHBaseCluster().getLiveRegionServerThreads();
    for (JVMClusterUtil.RegionServerThread regionServer : regionServers) {
        HRegionServer destServer = regionServer.getRegionServer();
        destServerName = destServer.getServerName();
        if (!destServerName.equals(serverName) && serverManager.isServerOnline(destServerName)) {
            break;
        }
    }
    assertTrue(destServerName != null && !destServerName.equals(serverName));
    admin.move(hri.getRegionName(), destServerName).get();
    long timeoutTime = EnvironmentEdgeManager.currentTime() + 30000;
    while (true) {
        ServerName sn = rawAdmin.getRegionLocation(hri.getRegionName()).get().getServerName();
        if (sn != null && sn.equals(destServerName)) {
            break;
        }
        long now = EnvironmentEdgeManager.currentTime();
        if (now > timeoutTime) {
            fail("Failed to move the region in time: " + hri);
        }
        Thread.sleep(100);
    }
    admin.balancerSwitch(true).join();
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 88 with HMaster

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

the class TestAsyncRegionAdminApi2 method testMergeRegions.

@Test
public void testMergeRegions() throws Exception {
    byte[][] splitRows = new byte[][] { Bytes.toBytes("3"), Bytes.toBytes("6") };
    createTableWithDefaultConf(tableName, splitRows);
    AsyncTable<AdvancedScanResultConsumer> metaTable = ASYNC_CONN.getTable(META_TABLE_NAME);
    List<HRegionLocation> regionLocations = ClientMetaTableAccessor.getTableHRegionLocations(metaTable, tableName).get();
    RegionInfo regionA;
    RegionInfo regionB;
    RegionInfo regionC;
    RegionInfo mergedChildRegion = null;
    // merge with full name
    assertEquals(3, regionLocations.size());
    regionA = regionLocations.get(0).getRegion();
    regionB = regionLocations.get(1).getRegion();
    regionC = regionLocations.get(2).getRegion();
    admin.mergeRegions(regionA.getRegionName(), regionB.getRegionName(), false).get();
    regionLocations = ClientMetaTableAccessor.getTableHRegionLocations(metaTable, tableName).get();
    assertEquals(2, regionLocations.size());
    for (HRegionLocation rl : regionLocations) {
        if (regionC.compareTo(rl.getRegion()) != 0) {
            mergedChildRegion = rl.getRegion();
            break;
        }
    }
    assertNotNull(mergedChildRegion);
    // Need to wait GC for merged child region is done.
    HMaster services = TEST_UTIL.getHBaseCluster().getMaster();
    CatalogJanitor cj = services.getCatalogJanitor();
    assertTrue(cj.scan() > 0);
    // Wait until all procedures settled down
    while (!services.getMasterProcedureExecutor().getActiveProcIds().isEmpty()) {
        Thread.sleep(200);
    }
    // merge with encoded name
    admin.mergeRegions(regionC.getRegionName(), mergedChildRegion.getRegionName(), false).get();
    regionLocations = ClientMetaTableAccessor.getTableHRegionLocations(metaTable, tableName).get();
    assertEquals(1, regionLocations.size());
}
Also used : HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) CatalogJanitor(org.apache.hadoop.hbase.master.janitor.CatalogJanitor) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 89 with HMaster

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

the class TestMetaTableAccessor method testIsMetaWhenAllHealthy.

@Test
public void testIsMetaWhenAllHealthy() throws InterruptedException {
    HMaster m = UTIL.getMiniHBaseCluster().getMaster();
    assertTrue(m.waitForMetaOnline());
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 90 with HMaster

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

the class TestZooKeeper method testLogSplittingAfterMasterRecoveryDueToZKExpiry.

/**
 * Tests whether the logs are split when master recovers from a expired zookeeper session and an
 * RS goes down.
 */
@Test
public void testLogSplittingAfterMasterRecoveryDueToZKExpiry() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    cluster.startRegionServer();
    TableName tableName = TableName.valueOf(name.getMethodName());
    byte[] family = Bytes.toBytes("col");
    try (Admin admin = TEST_UTIL.getAdmin()) {
        byte[][] SPLIT_KEYS = new byte[][] { Bytes.toBytes("1"), Bytes.toBytes("2"), Bytes.toBytes("3"), Bytes.toBytes("4"), Bytes.toBytes("5") };
        TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();
        admin.createTable(htd, SPLIT_KEYS);
    }
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    HMaster m = cluster.getMaster();
    try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
        int numberOfPuts;
        for (numberOfPuts = 0; numberOfPuts < 6; numberOfPuts++) {
            Put p = new Put(Bytes.toBytes(numberOfPuts));
            p.addColumn(Bytes.toBytes("col"), Bytes.toBytes("ql"), Bytes.toBytes("value" + numberOfPuts));
            table.put(p);
        }
        m.abort("Test recovery from zk session expired", new KeeperException.SessionExpiredException());
        // Master doesn't recover any more
        assertTrue(m.isStopped());
        cluster.killRegionServer(TEST_UTIL.getRSForFirstRegionInTable(tableName).getServerName());
        // Without patch for HBASE-6046 this test case will always timeout
        // with patch the test case should pass.
        int numberOfRows = 0;
        try (ResultScanner scanner = table.getScanner(new Scan())) {
            while (scanner.next() != null) {
                numberOfRows++;
            }
        }
        assertEquals("Number of rows should be equal to number of puts.", numberOfPuts, numberOfRows);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Put(org.apache.hadoop.hbase.client.Put) HMaster(org.apache.hadoop.hbase.master.HMaster) Scan(org.apache.hadoop.hbase.client.Scan) KeeperException(org.apache.zookeeper.KeeperException) 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