Search in sources :

Example 91 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer 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 92 with HRegionServer

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

Example 93 with HRegionServer

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

the class TestRegionMover1 method testLoadMetaRegion.

/**
 * UT for HBASE-21746
 */
@Test
public void testLoadMetaRegion() throws Exception {
    HRegionServer rsWithMeta = TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()).filter(rs -> rs.getRegions(TableName.META_TABLE_NAME).size() > 0).findFirst().get();
    int onlineRegions = rsWithMeta.getNumberOfOnlineRegions();
    String rsName = rsWithMeta.getServerName().getAddress().toString();
    try (RegionMover rm = new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).build()) {
        LOG.info("Unloading " + rsWithMeta.getServerName());
        rm.unload();
        assertEquals(0, rsWithMeta.getNumberOfOnlineRegions());
        LOG.info("Loading " + rsWithMeta.getServerName());
        rm.load();
        assertEquals(onlineRegions, rsWithMeta.getNumberOfOnlineRegions());
    }
}
Also used : BeforeClass(org.junit.BeforeClass) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) LoggerFactory(org.slf4j.LoggerFactory) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) HConstants(org.apache.hadoop.hbase.HConstants) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TestName(org.junit.rules.TestName) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) Path(org.apache.hadoop.fs.Path) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Before(org.junit.Before) MiscTests(org.apache.hadoop.hbase.testclassification.MiscTests) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Predicate(org.apache.hadoop.hbase.Waiter.Predicate) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) FileWriter(java.io.FileWriter) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) File(java.io.File) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) List(java.util.List) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Assert(org.junit.Assert) Collections(java.util.Collections) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) RegionMoverBuilder(org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 94 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer 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 95 with HRegionServer

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

the class TestAdmin2 method testGetRegionInfo.

/**
 * TestCase for HBASE-21355
 */
@Test
public void testGetRegionInfo() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    Table table = TEST_UTIL.createTable(tableName, Bytes.toBytes("f"));
    for (int i = 0; i < 100; i++) {
        table.put(new Put(Bytes.toBytes(i)).addColumn(Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes(i)));
    }
    ADMIN.flush(tableName);
    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(table.getName());
    List<HRegion> regions = rs.getRegions(tableName);
    Assert.assertEquals(1, regions.size());
    HRegion region = regions.get(0);
    byte[] regionName = region.getRegionInfo().getRegionName();
    HStore store = region.getStore(Bytes.toBytes("f"));
    long expectedStoreFilesSize = store.getStorefilesSize();
    Assert.assertNotNull(store);
    Assert.assertEquals(expectedStoreFilesSize, store.getSize());
    for (int i = 0; i < 10; i++) {
        RegionInfo ri = ProtobufUtil.toRegionInfo(TEST_UTIL.getAsyncConnection().getRegionServerAdmin(rs.getServerName()).getRegionInfo(RequestConverter.buildGetRegionInfoRequest(regionName)).get().getRegionInfo());
        Assert.assertEquals(region.getRegionInfo(), ri);
        // Make sure that the store size is still the actual file system's store size.
        Assert.assertEquals(expectedStoreFilesSize, store.getSize());
    }
    // Test querying using the encoded name only. When encoded name passed,
    // and the target server is the Master, we return the full region name.
    // Convenience.
    ServerName sn = null;
    try (Admin admin = TEST_UTIL.getConnection().getAdmin()) {
        sn = admin.getMaster();
    }
    RegionInfo ri = region.getRegionInfo();
    testGetWithRegionName(sn, ri, ri.getEncodedNameAsBytes());
    testGetWithRegionName(sn, ri, ri.getRegionName());
    // Try querying meta encoded name.
    ri = RegionInfoBuilder.FIRST_META_REGIONINFO;
    testGetWithRegionName(sn, ri, ri.getEncodedNameAsBytes());
    testGetWithRegionName(sn, ri, ri.getRegionName());
}
Also used : HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) ServerName(org.apache.hadoop.hbase.ServerName) HStore(org.apache.hadoop.hbase.regionserver.HStore) 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