Search in sources :

Example 31 with SingleProcessHBaseCluster

use of org.apache.hadoop.hbase.SingleProcessHBaseCluster 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 32 with SingleProcessHBaseCluster

use of org.apache.hadoop.hbase.SingleProcessHBaseCluster 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 33 with SingleProcessHBaseCluster

use of org.apache.hadoop.hbase.SingleProcessHBaseCluster 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)

Example 34 with SingleProcessHBaseCluster

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

the class TestRegionMover1 method testRegionServerPort.

@Test
public void testRegionServerPort() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HRegionServer regionServer = cluster.getRegionServer(0);
    String rsName = regionServer.getServerName().getHostname();
    final int PORT = 16021;
    Configuration conf = TEST_UTIL.getConfiguration();
    String originalPort = conf.get(HConstants.REGIONSERVER_PORT);
    conf.set(HConstants.REGIONSERVER_PORT, Integer.toString(PORT));
    RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, conf);
    assertEquals(PORT, rmBuilder.port);
    if (originalPort != null) {
        conf.set(HConstants.REGIONSERVER_PORT, originalPort);
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) Configuration(org.apache.hadoop.conf.Configuration) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 35 with SingleProcessHBaseCluster

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

the class TestRegionMover3 method testRegionUnloadWithRack.

@Test
public void testRegionUnloadWithRack() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    Admin admin = TEST_UTIL.getAdmin();
    Table table = TEST_UTIL.getConnection().getTable(tableName);
    List<Put> puts = IntStream.range(10, 50000).mapToObj(i -> new Put(Bytes.toBytes(i)).addColumn(Bytes.toBytes("fam1"), Bytes.toBytes("q1"), Bytes.toBytes("val_" + i))).collect(Collectors.toList());
    table.put(puts);
    admin.flush(tableName);
    admin.compact(tableName);
    Thread.sleep(3000);
    HRegionServer hRegionServer0 = cluster.getRegionServer(0);
    HRegionServer hRegionServer1 = cluster.getRegionServer(1);
    HRegionServer hRegionServer2 = cluster.getRegionServer(2);
    int numRegions0 = hRegionServer0.getNumberOfOnlineRegions();
    int numRegions1 = hRegionServer1.getNumberOfOnlineRegions();
    int numRegions2 = hRegionServer2.getNumberOfOnlineRegions();
    Assert.assertTrue(numRegions0 >= 3);
    Assert.assertTrue(numRegions1 >= 3);
    Assert.assertTrue(numRegions2 >= 3);
    int totalRegions = numRegions0 + numRegions1 + numRegions2;
    // source RS: rs0
    String sourceRSName = rs0.getAddress().toString();
    // move all regions from rs1 to rs0
    for (HRegion region : hRegionServer1.getRegions()) {
        TEST_UTIL.getAdmin().move(region.getRegionInfo().getEncodedNameAsBytes(), rs0);
    }
    TEST_UTIL.waitFor(5000, () -> {
        int newNumRegions0 = hRegionServer0.getNumberOfOnlineRegions();
        int newNumRegions1 = hRegionServer1.getNumberOfOnlineRegions();
        return newNumRegions1 == 0 && newNumRegions0 == (numRegions0 + numRegions1);
    });
    // regionMover obj on rs0. While unloading regions from rs0
    // with default rackManager, which resolves "/default-rack" for each server, no region
    // is moved while using unloadFromRack() as all rs belong to same rack.
    RegionMover.RegionMoverBuilder rmBuilder = new RegionMover.RegionMoverBuilder(sourceRSName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
    try (RegionMover regionMover = rmBuilder.build()) {
        regionMover.unloadFromRack();
        int newNumRegions0 = hRegionServer0.getNumberOfOnlineRegions();
        int newNumRegions1 = hRegionServer1.getNumberOfOnlineRegions();
        int newNumRegions2 = hRegionServer2.getNumberOfOnlineRegions();
        Assert.assertEquals(0, newNumRegions1);
        Assert.assertEquals(totalRegions, newNumRegions0 + newNumRegions2);
    }
    // use custom rackManager, which resolves "rack-1" for rs0 and rs1,
    // while "rack-2" for rs2. Hence, unloadFromRack() from rs0 should move all
    // regions that belong to rs0 to rs2 only, and nothing should be moved to rs1
    // as rs0 and rs1 belong to same rack.
    rmBuilder.rackManager(new MockRackManager());
    try (RegionMover regionMover = rmBuilder.build()) {
        regionMover.unloadFromRack();
        int newNumRegions0 = hRegionServer0.getNumberOfOnlineRegions();
        int newNumRegions1 = hRegionServer1.getNumberOfOnlineRegions();
        int newNumRegions2 = hRegionServer2.getNumberOfOnlineRegions();
        Assert.assertEquals(0, newNumRegions0);
        Assert.assertEquals(0, newNumRegions1);
        Assert.assertEquals(totalRegions, newNumRegions2);
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) IntStream(java.util.stream.IntStream) BeforeClass(org.junit.BeforeClass) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) ArrayList(java.util.ArrayList) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TestName(org.junit.rules.TestName) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Before(org.junit.Before) RackManager(org.apache.hadoop.hbase.master.RackManager) MiscTests(org.apache.hadoop.hbase.testclassification.MiscTests) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Put(org.apache.hadoop.hbase.client.Put) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) List(java.util.List) Rule(org.junit.Rule) Admin(org.apache.hadoop.hbase.client.Admin) Table(org.apache.hadoop.hbase.client.Table) Assert(org.junit.Assert) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Table(org.apache.hadoop.hbase.client.Table) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) 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