Search in sources :

Example 86 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestSplitWALProcedure method testMasterRestart.

@Test
public void testMasterRestart() throws Exception {
    Table table = TEST_UTIL.createTable(TABLE_NAME, FAMILY, TEST_UTIL.KEYS_FOR_HBA_CREATE_TABLE);
    for (int i = 0; i < 10; i++) {
        TEST_UTIL.loadTable(table, FAMILY);
    }
    HRegionServer testServer = TEST_UTIL.getHBaseCluster().getRegionServer(0);
    List<FileStatus> wals = splitWALManager.getWALsToSplit(testServer.getServerName(), false);
    Assert.assertEquals(1, wals.size());
    SplitWALProcedure splitWALProcedure = new SplitWALProcedure(wals.get(0).getPath().toString(), testServer.getServerName());
    long pid = ProcedureTestingUtility.submitProcedure(master.getMasterProcedureExecutor(), splitWALProcedure, HConstants.NO_NONCE, HConstants.NO_NONCE);
    TEST_UTIL.waitFor(5000, () -> splitWALProcedure.getWorker() != null);
    // Kill master
    TEST_UTIL.getHBaseCluster().killMaster(master.getServerName());
    TEST_UTIL.getHBaseCluster().waitForMasterToStop(master.getServerName(), 20000);
    // restart master
    TEST_UTIL.getHBaseCluster().startMaster();
    TEST_UTIL.getHBaseCluster().waitForActiveAndReadyMaster();
    this.master = TEST_UTIL.getHBaseCluster().getMaster();
    ProcedureTestingUtility.waitProcedure(master.getMasterProcedureExecutor(), pid);
    Optional<Procedure<?>> procedure = master.getProcedures().stream().filter(p -> p.getProcId() == pid).findAny();
    // make sure procedure is successful and wal is deleted
    Assert.assertTrue(procedure.isPresent());
    Assert.assertTrue(procedure.get().isSuccess());
    Assert.assertFalse(TEST_UTIL.getTestFileSystem().exists(wals.get(0).getPath()));
}
Also used : HBASE_SPLIT_WAL_COORDINATED_BY_ZK(org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK) FileStatus(org.apache.hadoop.fs.FileStatus) HConstants(org.apache.hadoop.hbase.HConstants) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) After(org.junit.After) ClassRule(org.junit.ClassRule) Bytes(org.apache.hadoop.hbase.util.Bytes) Before(org.junit.Before) TableName(org.apache.hadoop.hbase.TableName) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) HBASE_SPLIT_WAL_MAX_SPLITTER(org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_MAX_SPLITTER) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) ProcedureTestingUtility(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) SplitWALManager(org.apache.hadoop.hbase.master.SplitWALManager) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) List(java.util.List) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) Optional(java.util.Optional) Table(org.apache.hadoop.hbase.client.Table) Assert(org.junit.Assert) HMaster(org.apache.hadoop.hbase.master.HMaster) Table(org.apache.hadoop.hbase.client.Table) FileStatus(org.apache.hadoop.fs.FileStatus) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 87 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestRegionMoverWithRSGroupEnable method testUnloadRegions.

@Test
public void testUnloadRegions() throws Exception {
    Address decommission = rsservers.get(0);
    Address online = rsservers.get(1);
    String filename = new Path(TEST_UTIL.getDataTestDir(), "testRSGroupUnload").toString();
    RegionMoverBuilder builder = new RegionMoverBuilder(decommission.toString(), TEST_UTIL.getConfiguration());
    try (RegionMover rm = builder.filename(filename).ack(true).build()) {
        LOG.info("Unloading " + decommission.getHostname());
        rm.unload();
    }
    HRegionServer onlineRS = TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().stream().map(JVMClusterUtil.RegionServerThread::getRegionServer).filter(rs -> rs.getServerName().getAddress().equals(online)).findFirst().get();
    assertEquals(9, onlineRS.getNumberOfOnlineRegions());
}
Also used : Path(org.apache.hadoop.fs.Path) Address(org.apache.hadoop.hbase.net.Address) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 88 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestRegionMover1 method testDecomServerExclusionWithAck.

@Test
public void testDecomServerExclusionWithAck() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HRegionServer excludeServer = cluster.getRegionServer(1);
    List<HRegion> regions = excludeServer.getRegions();
    int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions();
    TEST_UTIL.getAdmin().decommissionRegionServers(Collections.singletonList(excludeServer.getServerName()), false);
    waitForServerDecom(excludeServer);
    HRegionServer regionServer = cluster.getRegionServer(0);
    String rsName = regionServer.getServerName().getHostname();
    int port = regionServer.getServerName().getPort();
    String hostname = rsName + ":" + Integer.toString(port);
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(hostname, TEST_UTIL.getConfiguration()).ack(true);
    int targetServerRegions = cluster.getRegionServer(2).getRegions().size();
    int sourceServerRegions = regionServer.getRegions().size();
    try (RegionMover regionMover = rmBuilder.build()) {
        Assert.assertTrue(regionMover.unload());
        LOG.info("Unloading {}", hostname);
        assertEquals(0, regionServer.getNumberOfOnlineRegions());
        assertEquals(regionsExcludeServer, cluster.getRegionServer(1).getNumberOfOnlineRegions());
        LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions());
        List<HRegion> regionList = cluster.getRegionServer(1).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 89 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestRegionMover1 method testDesignatedFile.

@Test
public void testDesignatedFile() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    File designatedFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "designated_file");
    HRegionServer designatedServer = cluster.getRegionServer(0);
    try (FileWriter fos = new FileWriter(designatedFile)) {
        String designatedHostname = designatedServer.getServerName().getHostname();
        int designatedServerPort = designatedServer.getServerName().getPort();
        String excludeServerName = designatedHostname + ":" + designatedServerPort;
        fos.write(excludeServerName);
    }
    int regionsInDesignatedServer = designatedServer.getNumberOfOnlineRegions();
    HRegionServer regionServer = cluster.getRegionServer(1);
    String rsName = regionServer.getServerName().getHostname();
    int port = regionServer.getServerName().getPort();
    String rs = rsName + ":" + port;
    int regionsInRegionServer = regionServer.getNumberOfOnlineRegions();
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs, TEST_UTIL.getConfiguration()).designatedFile(designatedFile.getCanonicalPath());
    try (RegionMover rm = rmBuilder.build()) {
        LOG.debug("Unloading {} regions", rs);
        rm.unload();
        assertEquals(0, regionServer.getNumberOfOnlineRegions());
        assertEquals(regionsInDesignatedServer + regionsInRegionServer, designatedServer.getNumberOfOnlineRegions());
        LOG.debug("Before:{} After:{}", regionsInDesignatedServer, designatedServer.getNumberOfOnlineRegions());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) FileWriter(java.io.FileWriter) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) File(java.io.File) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 90 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestRegionMover1 method testExclude.

/**
 * To test that we successfully exclude a server from the unloading process We test for the number
 * of regions on Excluded server and also test that regions are unloaded successfully
 */
@Test
public void testExclude() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    File excludeFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "exclude_file");
    FileWriter fos = new FileWriter(excludeFile);
    HRegionServer excludeServer = cluster.getRegionServer(1);
    String excludeHostname = excludeServer.getServerName().getHostname();
    int excludeServerPort = excludeServer.getServerName().getPort();
    int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions();
    String excludeServerName = excludeHostname + ":" + Integer.toString(excludeServerPort);
    fos.write(excludeServerName);
    fos.close();
    HRegionServer regionServer = cluster.getRegionServer(0);
    String rsName = regionServer.getServerName().getHostname();
    int port = regionServer.getServerName().getPort();
    String rs = rsName + ":" + Integer.toString(port);
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs, TEST_UTIL.getConfiguration()).ack(true).excludeFile(excludeFile.getCanonicalPath());
    try (RegionMover rm = rmBuilder.build()) {
        rm.unload();
        LOG.info("Unloading " + rs);
        assertEquals(0, regionServer.getNumberOfOnlineRegions());
        assertEquals(regionsExcludeServer, cluster.getRegionServer(1).getNumberOfOnlineRegions());
        LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) FileWriter(java.io.FileWriter) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) File(java.io.File) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Aggregations

HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)253 Test (org.junit.Test)188 TableName (org.apache.hadoop.hbase.TableName)70 Table (org.apache.hadoop.hbase.client.Table)67 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)59 IOException (java.io.IOException)53 Region (org.apache.hadoop.hbase.regionserver.Region)49 Configuration (org.apache.hadoop.conf.Configuration)47 ServerName (org.apache.hadoop.hbase.ServerName)46 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)41 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)41 Put (org.apache.hadoop.hbase.client.Put)39 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)32 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)32 JVMClusterUtil (org.apache.hadoop.hbase.util.JVMClusterUtil)23 List (java.util.List)22 HMaster (org.apache.hadoop.hbase.master.HMaster)22 ArrayList (java.util.ArrayList)21 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)21 Waiter (org.apache.hadoop.hbase.Waiter)21