Search in sources :

Example 36 with SingleProcessHBaseCluster

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

the class TestRegionMover1 method testDecomServerExclusion.

@Test
public void testDecomServerExclusion() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HRegionServer excludeServer = cluster.getRegionServer(0);
    List<HRegion> regions = excludeServer.getRegions();
    int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions();
    TEST_UTIL.getAdmin().decommissionRegionServers(Collections.singletonList(excludeServer.getServerName()), false);
    waitForServerDecom(excludeServer);
    HRegionServer sourceRegionServer = cluster.getRegionServer(1);
    String rsName = sourceRegionServer.getServerName().getHostname();
    int port = sourceRegionServer.getServerName().getPort();
    String hostname = rsName + ":" + Integer.toString(port);
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(hostname, TEST_UTIL.getConfiguration()).ack(false);
    int targetServerRegions = cluster.getRegionServer(2).getRegions().size();
    int sourceServerRegions = sourceRegionServer.getRegions().size();
    try (RegionMover regionMover = rmBuilder.build()) {
        Assert.assertTrue(regionMover.unload());
        LOG.info("Unloading {}", hostname);
        assertEquals(0, sourceRegionServer.getNumberOfOnlineRegions());
        assertEquals(regionsExcludeServer, cluster.getRegionServer(0).getNumberOfOnlineRegions());
        LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions());
        List<HRegion> regionList = cluster.getRegionServer(0).getRegions();
        int index = 0;
        for (HRegion hRegion : regionList) {
            Assert.assertEquals(hRegion, regions.get(index++));
        }
        Assert.assertEquals(targetServerRegions + sourceServerRegions, cluster.getRegionServer(2).getNumberOfOnlineRegions());
        Assert.assertTrue(regionMover.load());
    }
    TEST_UTIL.getAdmin().recommissionRegionServer(excludeServer.getServerName(), Collections.emptyList());
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 37 with SingleProcessHBaseCluster

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

the class TestAdmin2 method testMoveToPreviouslyAssignedRS.

@Test
public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    final TableName tableName = TableName.valueOf(name.getMethodName());
    Admin localAdmin = createTable(tableName);
    List<RegionInfo> tableRegions = localAdmin.getRegions(tableName);
    RegionInfo hri = tableRegions.get(0);
    AssignmentManager am = master.getAssignmentManager();
    ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
    localAdmin.move(hri.getEncodedNameAsBytes(), server);
    assertEquals("Current region server and region server before move should be same.", server, am.getRegionStates().getRegionServerOfRegion(hri));
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) Test(org.junit.Test)

Example 38 with SingleProcessHBaseCluster

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

the class TestRegionMergeTransactionOnCluster method beforeAllTests.

@BeforeClass
public static void beforeAllTests() throws Exception {
    // Start a cluster
    StartTestingClusterOption option = StartTestingClusterOption.builder().masterClass(MyMaster.class).numRegionServers(NB_SERVERS).numDataNodes(NB_SERVERS).build();
    TEST_UTIL.startMiniCluster(option);
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    MASTER = cluster.getMaster();
    MASTER.balanceSwitch(false);
    ADMIN = TEST_UTIL.getConnection().getAdmin();
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) BeforeClass(org.junit.BeforeClass)

Example 39 with SingleProcessHBaseCluster

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

the class TestRegionMergeTransactionOnCluster method testWholesomeMerge.

@Test
public void testWholesomeMerge() throws Exception {
    LOG.info("Starting " + name.getMethodName());
    final TableName tableName = TableName.valueOf(name.getMethodName());
    try {
        // Create table and load data.
        Table table = createTableAndLoadData(MASTER, tableName);
        // Merge 1st and 2nd region
        mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1);
        // Merge 2nd and 3th region
        PairOfSameType<RegionInfo> mergedRegions = mergeRegionsAndVerifyRegionNum(MASTER, tableName, 1, 2, INITIAL_REGION_NUM - 2);
        verifyRowCount(table, ROWSIZE);
        // Randomly choose one of the two merged regions
        RegionInfo hri = RandomUtils.nextBoolean() ? mergedRegions.getFirst() : mergedRegions.getSecond();
        SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
        AssignmentManager am = cluster.getMaster().getAssignmentManager();
        RegionStates regionStates = am.getRegionStates();
        // We should not be able to assign it again
        am.assign(hri);
        assertFalse("Merged region can't be assigned", regionStates.isRegionInTransition(hri));
        // We should not be able to unassign it either
        am.unassign(hri);
        assertFalse("Merged region can't be unassigned", regionStates.isRegionInTransition(hri));
        table.close();
    } finally {
        TEST_UTIL.deleteTable(tableName);
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Example 40 with SingleProcessHBaseCluster

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

the class TestRSGroupsOfflineMode method testOffline.

@Test
public void testOffline() throws Exception, InterruptedException {
    // Table should be after group table name so it gets assigned later.
    final TableName failoverTable = TableName.valueOf(getNameWithoutIndex(name.getMethodName()));
    TEST_UTIL.createTable(failoverTable, Bytes.toBytes("f"));
    final HRegionServer killRS = ((SingleProcessHBaseCluster) cluster).getRegionServer(0);
    final HRegionServer groupRS = ((SingleProcessHBaseCluster) cluster).getRegionServer(1);
    final HRegionServer failoverRS = ((SingleProcessHBaseCluster) cluster).getRegionServer(2);
    String newGroup = "my_group";
    Admin admin = TEST_UTIL.getAdmin();
    admin.addRSGroup(newGroup);
    if (master.getAssignmentManager().getRegionStates().getRegionAssignments().containsValue(failoverRS.getServerName())) {
        for (RegionInfo regionInfo : hbaseAdmin.getRegions(failoverRS.getServerName())) {
            hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), failoverRS.getServerName());
        }
        LOG.info("Waiting for region unassignments on failover RS...");
        TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                return !master.getServerManager().getLoad(failoverRS.getServerName()).getRegionMetrics().isEmpty();
            }
        });
    }
    // Move server to group and make sure all tables are assigned.
    admin.moveServersToRSGroup(Sets.newHashSet(groupRS.getServerName().getAddress()), newGroup);
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return groupRS.getNumberOfOnlineRegions() < 1 && master.getAssignmentManager().getRegionStates().getRegionsInTransitionCount() < 1;
        }
    });
    // Move table to group and wait.
    admin.setRSGroup(Sets.newHashSet(RSGroupInfoManagerImpl.RSGROUP_TABLE_NAME), newGroup);
    LOG.info("Waiting for move table...");
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return groupRS.getNumberOfOnlineRegions() == 1;
        }
    });
    groupRS.stop("die");
    // Race condition here.
    TEST_UTIL.getHBaseCluster().getMaster().stopMaster();
    LOG.info("Waiting for offline mode...");
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return TEST_UTIL.getHBaseCluster().getMaster() != null && TEST_UTIL.getHBaseCluster().getMaster().isActiveMaster() && TEST_UTIL.getHBaseCluster().getMaster().isInitialized() && TEST_UTIL.getHBaseCluster().getMaster().getServerManager().getOnlineServers().size() <= 3;
        }
    });
    // Get groupInfoManager from the new active master.
    RSGroupInfoManager groupMgr = ((SingleProcessHBaseCluster) cluster).getMaster().getRSGroupInfoManager();
    // Make sure balancer is in offline mode, since this is what we're testing.
    assertFalse(groupMgr.isOnline());
    // Kill final regionserver to see the failover happens for all tables except GROUP table since
    // it's group does not have any online RS.
    killRS.stop("die");
    master = TEST_UTIL.getHBaseCluster().getMaster();
    LOG.info("Waiting for new table assignment...");
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return failoverRS.getRegions(failoverTable).size() >= 1;
        }
    });
    assertEquals(0, failoverRS.getRegions(RSGroupInfoManagerImpl.RSGROUP_TABLE_NAME).size());
    // Need this for minicluster to shutdown cleanly.
    master.stopMaster();
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Admin(org.apache.hadoop.hbase.client.Admin) Waiter(org.apache.hadoop.hbase.Waiter) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) 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