Search in sources :

Example 16 with SingleProcessHBaseCluster

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

the class MasterProcedureTestingUtility method waitBackupMaster.

public static void waitBackupMaster(final HBaseTestingUtil testUtil, final HMaster oldMaster) throws Exception {
    SingleProcessHBaseCluster cluster = testUtil.getMiniHBaseCluster();
    HMaster newMaster = cluster.getMaster();
    while (newMaster == null || newMaster == oldMaster) {
        Thread.sleep(250);
        newMaster = cluster.getMaster();
    }
    while (!(newMaster.isActiveMaster() && newMaster.isInitialized())) {
        Thread.sleep(250);
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) HMaster(org.apache.hadoop.hbase.master.HMaster)

Example 17 with SingleProcessHBaseCluster

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

the class TestMasterObserver method testTableDescriptorsEnumeration.

@Test
public void testTableDescriptorsEnumeration() throws Exception {
    SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
    cp.resetStates();
    GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>) null);
    master.getMasterRpcServices().getTableDescriptors(null, req);
    assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled());
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HMaster(org.apache.hadoop.hbase.master.HMaster) GetTableDescriptorsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsRequest) Test(org.junit.Test)

Example 18 with SingleProcessHBaseCluster

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

the class TestMasterObserver method testTableOperations.

@Test
public void testTableOperations() throws Exception {
    SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
    final TableName tableName = TableName.valueOf(name.getMethodName());
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
    cp.resetStates();
    assertFalse("No table created yet", cp.wasCreateTableCalled());
    // create a table
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(TEST_FAMILY)).build();
    try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
        Admin admin = connection.getAdmin()) {
        tableCreationLatch = new CountDownLatch(1);
        admin.createTable(tableDescriptor, Arrays.copyOfRange(HBaseTestingUtil.KEYS, 1, HBaseTestingUtil.KEYS.length));
        assertTrue("Test table should be created", cp.wasCreateTableCalled());
        tableCreationLatch.await();
        assertTrue("Table pre create handler called.", cp.wasPreCreateTableActionCalled());
        assertTrue("Table create handler should be called.", cp.wasCreateTableActionCalled());
        RegionLocator regionLocator = connection.getRegionLocator(tableDescriptor.getTableName());
        List<HRegionLocation> regions = regionLocator.getAllRegionLocations();
        admin.mergeRegionsAsync(regions.get(0).getRegion().getEncodedNameAsBytes(), regions.get(1).getRegion().getEncodedNameAsBytes(), true).get();
        assertTrue("Coprocessor should have been called on region merge", cp.wasMergeRegionsCalled());
        tableCreationLatch = new CountDownLatch(1);
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        assertTrue("Coprocessor should have been called on table disable", cp.wasDisableTableCalled());
        assertTrue("Disable table handler should be called.", cp.wasDisableTableActionCalled());
        // enable
        assertFalse(cp.wasEnableTableCalled());
        admin.enableTable(tableName);
        assertTrue(admin.isTableEnabled(tableName));
        assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled());
        assertTrue("Enable table handler should be called.", cp.wasEnableTableActionCalled());
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        // modify table
        tableDescriptor = TableDescriptorBuilder.newBuilder(tableDescriptor).setMaxFileSize(512 * 1024 * 1024).build();
        modifyTableSync(admin, tableName, tableDescriptor);
        assertTrue("Test table should have been modified", cp.wasModifyTableCalled());
        // truncate table
        admin.truncateTable(tableName, false);
        // delete table
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        deleteTable(admin, tableName);
        assertFalse("Test table should have been deleted", admin.tableExists(tableName));
        assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled());
        assertTrue("Delete table handler should be called.", cp.wasDeleteTableActionCalled());
        // When bypass was supported, we'd turn off bypass and rerun tests. Leaving rerun in place.
        cp.resetStates();
        admin.createTable(tableDescriptor);
        assertTrue("Test table should be created", cp.wasCreateTableCalled());
        tableCreationLatch.await();
        assertTrue("Table pre create handler called.", cp.wasPreCreateTableActionCalled());
        assertTrue("Table create handler should be called.", cp.wasCreateTableActionCalled());
        // disable
        assertFalse(cp.wasDisableTableCalled());
        assertFalse(cp.wasDisableTableActionCalled());
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        assertTrue("Coprocessor should have been called on table disable", cp.wasDisableTableCalled());
        assertTrue("Disable table handler should be called.", cp.wasDisableTableActionCalled());
        // modify table
        tableDescriptor = TableDescriptorBuilder.newBuilder(tableDescriptor).setMaxFileSize(512 * 1024 * 1024).build();
        modifyTableSync(admin, tableName, tableDescriptor);
        assertTrue("Test table should have been modified", cp.wasModifyTableCalled());
        // enable
        assertFalse(cp.wasEnableTableCalled());
        assertFalse(cp.wasEnableTableActionCalled());
        admin.enableTable(tableName);
        assertTrue(admin.isTableEnabled(tableName));
        assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled());
        assertTrue("Enable table handler should be called.", cp.wasEnableTableActionCalled());
        // disable again
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        // delete table
        assertFalse("No table deleted yet", cp.wasDeleteTableCalled());
        assertFalse("Delete table handler should not be called.", cp.wasDeleteTableActionCalled());
        deleteTable(admin, tableName);
        assertFalse("Test table should have been deleted", admin.tableExists(tableName));
        assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled());
        assertTrue("Delete table handler should be called.", cp.wasDeleteTableActionCalled());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) HMaster(org.apache.hadoop.hbase.master.HMaster) Connection(org.apache.hadoop.hbase.client.Connection) Admin(org.apache.hadoop.hbase.client.Admin) CountDownLatch(java.util.concurrent.CountDownLatch) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 19 with SingleProcessHBaseCluster

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

the class TestMasterObserver method testRegionTransitionOperations.

@Test
public void testRegionTransitionOperations() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
    cp.resetStates();
    Table table = UTIL.createMultiRegionTable(tableName, TEST_FAMILY);
    try (RegionLocator r = UTIL.getConnection().getRegionLocator(tableName)) {
        UTIL.waitUntilAllRegionsAssigned(tableName);
        List<HRegionLocation> regions = r.getAllRegionLocations();
        HRegionLocation firstGoodPair = null;
        for (HRegionLocation e : regions) {
            if (e.getServerName() != null) {
                firstGoodPair = e;
                break;
            }
        }
        assertNotNull("Found a non-null entry", firstGoodPair);
        LOG.info("Found " + firstGoodPair.toString());
        // Try to force a move
        Collection<ServerName> servers = master.getClusterMetrics().getLiveServerMetrics().keySet();
        String destName = null;
        String serverNameForFirstRegion = firstGoodPair.getServerName().toString();
        LOG.info("serverNameForFirstRegion=" + serverNameForFirstRegion);
        ServerName masterServerName = master.getServerName();
        boolean found = false;
        // Find server that is NOT carrying the first region
        for (ServerName info : servers) {
            LOG.info("ServerName=" + info);
            if (!serverNameForFirstRegion.equals(info.getServerName()) && !masterServerName.equals(info)) {
                destName = info.toString();
                found = true;
                break;
            }
        }
        assertTrue("Found server", found);
        LOG.info("Found " + destName);
        master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(firstGoodPair.getRegion().getEncodedNameAsBytes(), ServerName.valueOf(destName)));
        assertTrue("Coprocessor should have been called on region move", cp.wasMoveCalled());
        // make sure balancer is on
        master.balanceSwitch(true);
        assertTrue("Coprocessor should have been called on balance switch", cp.wasBalanceSwitchCalled());
        // turn balancer off
        master.balanceSwitch(false);
        // wait for assignments to finish, if any
        UTIL.waitUntilNoRegionsInTransition();
        // move half the open regions from RS 0 to RS 1
        HRegionServer rs = cluster.getRegionServer(0);
        byte[] destRS = Bytes.toBytes(cluster.getRegionServer(1).getServerName().toString());
        // Make sure no regions are in transition now
        UTIL.waitUntilNoRegionsInTransition();
        List<RegionInfo> openRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
        int moveCnt = openRegions.size() / 2;
        for (int i = 0; i < moveCnt; i++) {
            RegionInfo info = openRegions.get(i);
            if (!info.isMetaRegion()) {
                master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(openRegions.get(i).getEncodedNameAsBytes(), ServerName.valueOf(Bytes.toString(destRS))));
            }
        }
        // Make sure no regions are in transition now
        UTIL.waitUntilNoRegionsInTransition();
        // now trigger a balance
        master.balanceSwitch(true);
        master.balance();
        assertTrue("Coprocessor should be called on region rebalancing", cp.wasBalanceCalled());
    } finally {
        Admin admin = UTIL.getAdmin();
        admin.disableTable(tableName);
        deleteTable(admin, tableName);
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) Table(org.apache.hadoop.hbase.client.Table) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Admin(org.apache.hadoop.hbase.client.Admin) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 20 with SingleProcessHBaseCluster

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

the class TestMasterObserver method testAbortProcedureOperation.

@Test
public void testAbortProcedureOperation() throws Exception {
    SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
    cp.resetStates();
    master.abortProcedure(1, true);
    assertTrue("Coprocessor should be called on abort procedure request", cp.wasAbortProcedureCalled());
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HMaster(org.apache.hadoop.hbase.master.HMaster) 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