Search in sources :

Example 81 with SingleProcessHBaseCluster

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

the class TestRegionMover1 method testExcludeAndDesignated.

@Test
public void testExcludeAndDesignated() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    // create designated file
    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();
    // create exclude file
    File excludeFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "exclude_file");
    HRegionServer excludeServer = cluster.getRegionServer(1);
    try (FileWriter fos = new FileWriter(excludeFile)) {
        String excludeHostname = excludeServer.getServerName().getHostname();
        int excludeServerPort = excludeServer.getServerName().getPort();
        String excludeServerName = excludeHostname + ":" + excludeServerPort;
        fos.write(excludeServerName);
    }
    int regionsInExcludeServer = excludeServer.getNumberOfOnlineRegions();
    HRegionServer targetRegionServer = cluster.getRegionServer(2);
    String rsName = targetRegionServer.getServerName().getHostname();
    int port = targetRegionServer.getServerName().getPort();
    String rs = rsName + ":" + port;
    int regionsInTargetRegionServer = targetRegionServer.getNumberOfOnlineRegions();
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs, TEST_UTIL.getConfiguration()).designatedFile(designatedFile.getCanonicalPath()).excludeFile(excludeFile.getCanonicalPath());
    try (RegionMover rm = rmBuilder.build()) {
        LOG.debug("Unloading {}", rs);
        rm.unload();
        assertEquals(0, targetRegionServer.getNumberOfOnlineRegions());
        assertEquals(regionsInDesignatedServer + regionsInTargetRegionServer, designatedServer.getNumberOfOnlineRegions());
        LOG.debug("DesignatedServer Before:{} After:{}", regionsInDesignatedServer, designatedServer.getNumberOfOnlineRegions());
        assertEquals(regionsInExcludeServer, excludeServer.getNumberOfOnlineRegions());
        LOG.debug("ExcludeServer Before:{} After:{}", regionsInExcludeServer, excludeServer.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 82 with SingleProcessHBaseCluster

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

the class TestRegionMover1 method testWithoutAck.

/**
 * Test to unload a regionserver first and then load it using no Ack mode.
 */
@Test
public void testWithoutAck() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HRegionServer regionServer = cluster.getRegionServer(0);
    String rsName = regionServer.getServerName().getAddress().toString();
    int numRegions = regionServer.getNumberOfOnlineRegions();
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(false);
    try (RegionMover rm = rmBuilder.build()) {
        LOG.info("Unloading " + regionServer.getServerName());
        rm.unload();
        TEST_UTIL.waitFor(30000, 1000, new Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                return regionServer.getNumberOfOnlineRegions() == 0;
            }
        });
        LOG.info("Successfully Unloaded\nNow Loading");
        rm.load();
        // In UT we only have 10 regions so it is not likely to fail, so here we check for all
        // regions, in the real production this may not be true.
        TEST_UTIL.waitFor(30000, 1000, new Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                return regionServer.getNumberOfOnlineRegions() == numRegions;
            }
        });
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) IOException(java.io.IOException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 83 with SingleProcessHBaseCluster

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

the class TestRegionMover1 method testExcludeAndDecomServers.

@Test
public void testExcludeAndDecomServers() 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();
    String excludeServerName = excludeHostname + ":" + Integer.toString(excludeServerPort);
    fos.write(excludeServerName);
    fos.close();
    HRegionServer decomServer = cluster.getRegionServer(2);
    TEST_UTIL.getAdmin().decommissionRegionServers(Collections.singletonList(decomServer.getServerName()), false);
    waitForServerDecom(decomServer);
    HRegionServer regionServer = cluster.getRegionServer(0);
    String rsName = regionServer.getServerName().getHostname();
    int port = regionServer.getServerName().getPort();
    String sourceServer = rsName + ":" + Integer.toString(port);
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(sourceServer, TEST_UTIL.getConfiguration()).ack(true).excludeFile(excludeFile.getCanonicalPath());
    try (RegionMover regionMover = rmBuilder.build()) {
        Assert.assertFalse(regionMover.unload());
    }
    TEST_UTIL.getAdmin().recommissionRegionServer(decomServer.getServerName(), Collections.emptyList());
}
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 84 with SingleProcessHBaseCluster

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

the class TestRegionMover3 method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.startMiniCluster(3);
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    rs0 = cluster.getRegionServer(0).getServerName();
    rs1 = cluster.getRegionServer(1).getServerName();
    rs2 = cluster.getRegionServer(2).getServerName();
    TEST_UTIL.getAdmin().balancerSwitch(false, true);
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) BeforeClass(org.junit.BeforeClass)

Example 85 with SingleProcessHBaseCluster

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

the class TestRegionMover1 method testWithAck.

@Test
public void testWithAck() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HRegionServer regionServer = cluster.getRegionServer(0);
    String rsName = regionServer.getServerName().getAddress().toString();
    int numRegions = regionServer.getNumberOfOnlineRegions();
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
    try (RegionMover rm = rmBuilder.build()) {
        LOG.info("Unloading " + regionServer.getServerName());
        rm.unload();
        assertEquals(0, regionServer.getNumberOfOnlineRegions());
        LOG.info("Successfully Unloaded\nNow Loading");
        rm.load();
        assertEquals(numRegions, regionServer.getNumberOfOnlineRegions());
        // Repeat the same load. It should be very fast because all regions are already moved.
        rm.load();
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) 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