Search in sources :

Example 6 with HRegionServer

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

the class TestAsyncRegionAdminApi method testCloseRegionIfInvalidRegionNameIsPassed.

@Test
public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception {
    final String name = "TestHBACloseRegion1";
    byte[] TABLENAME = Bytes.toBytes(name);
    createTableWithDefaultConf(TableName.valueOf(TABLENAME));
    HRegionInfo info = null;
    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TableName.valueOf(TABLENAME));
    List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
    for (HRegionInfo regionInfo : onlineRegions) {
        if (!regionInfo.isMetaTable()) {
            if (regionInfo.getRegionNameAsString().contains(name)) {
                info = regionInfo;
                boolean catchNotServingException = false;
                try {
                    admin.closeRegionWithEncodedRegionName("sample", rs.getServerName().getServerName()).get();
                } catch (Exception e) {
                    catchNotServingException = true;
                // expected, ignore it
                }
                assertTrue(catchNotServingException);
            }
        }
    }
    onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
    assertTrue("The region should be present in online regions list.", onlineRegions.contains(info));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 7 with HRegionServer

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

the class TestAdmin2 method testCloseRegionWhenEncodedRegionNameIsNotGiven.

@Test(timeout = 300000)
public void testCloseRegionWhenEncodedRegionNameIsNotGiven() throws Exception {
    final byte[] tableName = Bytes.toBytes(name.getMethodName());
    createTableWithDefaultConf(tableName);
    HRegionInfo info = null;
    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TableName.valueOf(tableName));
    List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
    for (HRegionInfo regionInfo : onlineRegions) {
        if (!regionInfo.isMetaTable()) {
            if (regionInfo.getRegionNameAsString().contains(name.getMethodName())) {
                info = regionInfo;
                try {
                    admin.closeRegionWithEncodedRegionName(regionInfo.getRegionNameAsString(), rs.getServerName().getServerName());
                } catch (NotServingRegionException nsre) {
                // expected, ignore it.
                }
            }
        }
    }
    onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
    assertTrue("The region should be present in online regions list.", onlineRegions.contains(info));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 8 with HRegionServer

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

the class TestAdmin2 method testCloseRegionWhenServerNameIsNull.

@Test(timeout = 300000)
public void testCloseRegionWhenServerNameIsNull() throws Exception {
    final byte[] tableName = Bytes.toBytes(name.getMethodName());
    createTableWithDefaultConf(tableName);
    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TableName.valueOf(tableName));
    try {
        List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
        for (HRegionInfo regionInfo : onlineRegions) {
            if (!regionInfo.isMetaTable()) {
                if (regionInfo.getRegionNameAsString().contains(name.getMethodName())) {
                    admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), null);
                }
            }
        }
        fail("The test should throw exception if the servername passed is null.");
    } catch (IllegalArgumentException e) {
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 9 with HRegionServer

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

the class TestHBaseStorageFlowRunCompaction method testWriteFlowRunCompaction.

@Test
public void testWriteFlowRunCompaction() throws Exception {
    String cluster = "kompaction_cluster1";
    String user = "kompaction_FlowRun__user1";
    String flow = "kompaction_flowRun_flow_name";
    String flowVersion = "AF1021C19F1351";
    long runid = 1449526652000L;
    int start = 10;
    int count = 2000;
    int appIdSuffix = 1;
    HBaseTimelineWriterImpl hbi = null;
    long insertTs = System.currentTimeMillis() - count;
    Configuration c1 = util.getConfiguration();
    TimelineEntities te1 = null;
    TimelineEntity entityApp1 = null;
    try {
        hbi = new HBaseTimelineWriterImpl();
        hbi.init(c1);
        // of metric1 and 100 of metric2
        for (int i = start; i < start + count; i++) {
            String appName = "application_10240000000000_" + appIdSuffix;
            insertTs++;
            te1 = new TimelineEntities();
            entityApp1 = TestFlowDataGenerator.getEntityMetricsApp1(insertTs, c1);
            te1.addEntity(entityApp1);
            hbi.write(cluster, user, flow, flowVersion, runid, appName, te1);
            appName = "application_2048000000000_7" + appIdSuffix;
            insertTs++;
            te1 = new TimelineEntities();
            entityApp1 = TestFlowDataGenerator.getEntityMetricsApp2(insertTs);
            te1.addEntity(entityApp1);
            hbi.write(cluster, user, flow, flowVersion, runid, appName, te1);
        }
    } finally {
        String appName = "application_10240000000000_" + appIdSuffix;
        te1 = new TimelineEntities();
        entityApp1 = TestFlowDataGenerator.getEntityMetricsApp1Complete(insertTs + 1, c1);
        te1.addEntity(entityApp1);
        if (hbi != null) {
            hbi.write(cluster, user, flow, flowVersion, runid, appName, te1);
            hbi.flush();
            hbi.close();
        }
    }
    // check in flow run table
    HRegionServer server = util.getRSForFirstRegionInTable(TableName.valueOf(FlowRunTable.DEFAULT_TABLE_NAME));
    List<Region> regions = server.getOnlineRegions(TableName.valueOf(FlowRunTable.DEFAULT_TABLE_NAME));
    assertTrue("Didn't find any regions for primary table!", regions.size() > 0);
    // flush and compact all the regions of the primary table
    for (Region region : regions) {
        region.flush(true);
        region.compact(true);
    }
    // check flow run for one flow many apps
    checkFlowRunTable(cluster, user, flow, runid, c1, 4);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TimelineEntities(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntities) Region(org.apache.hadoop.hbase.regionserver.Region) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) HBaseTimelineWriterImpl(org.apache.hadoop.yarn.server.timelineservice.storage.HBaseTimelineWriterImpl) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 10 with HRegionServer

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

the class TestRegionRebalancing method assertRegionsAreBalanced.

/**
   * Determine if regions are balanced. Figure out the total, divide by the
   * number of online servers, then test if each server is +/- 1 of average
   * rounded up.
   */
private void assertRegionsAreBalanced() throws IOException {
    // TODO: Fix this test.  Old balancer used to run with 'slop'.  New
    // balancer does not.
    boolean success = false;
    float slop = (float) UTIL.getConfiguration().getFloat("hbase.regions.slop", 0.1f);
    if (slop <= 0)
        slop = 1;
    for (int i = 0; i < 5; i++) {
        success = true;
        // make sure all the regions are reassigned before we test balance
        waitForAllRegionsAssigned();
        long regionCount = UTIL.getMiniHBaseCluster().countServedRegions();
        List<HRegionServer> servers = getOnlineRegionServers();
        double avg = UTIL.getHBaseCluster().getMaster().getAverageLoad();
        int avgLoadPlusSlop = (int) Math.ceil(avg * (1 + slop));
        int avgLoadMinusSlop = (int) Math.floor(avg * (1 - slop)) - 1;
        LOG.debug("There are " + servers.size() + " servers and " + regionCount + " regions. Load Average: " + avg + " low border: " + avgLoadMinusSlop + ", up border: " + avgLoadPlusSlop + "; attempt: " + i);
        for (HRegionServer server : servers) {
            int serverLoad = ProtobufUtil.getOnlineRegions(server.getRSRpcServices()).size();
            LOG.debug(server.getServerName() + " Avg: " + avg + " actual: " + serverLoad);
            if (!(avg > 2.0 && serverLoad <= avgLoadPlusSlop && serverLoad >= avgLoadMinusSlop)) {
                for (HRegionInfo hri : ProtobufUtil.getOnlineRegions(server.getRSRpcServices())) {
                    if (hri.isMetaRegion())
                        serverLoad--;
                // LOG.debug(hri.getRegionNameAsString());
                }
                if (!(serverLoad <= avgLoadPlusSlop && serverLoad >= avgLoadMinusSlop)) {
                    LOG.debug(server.getServerName() + " Isn't balanced!!! Avg: " + avg + " actual: " + serverLoad + " slop: " + slop);
                    success = false;
                    break;
                }
            }
        }
        if (!success) {
            // chance to catch up. then, go back to the retry loop.
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
            }
            UTIL.getHBaseCluster().getMaster().balance();
            continue;
        }
        // if we get here, all servers were balanced, so we should just return.
        return;
    }
    // if we get here, we tried 5 times and never got to short circuit out of
    // the retry loop, so this is a failure.
    fail("After 5 attempts, region assignments were not balanced.");
}
Also used : HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Aggregations

HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)121 Test (org.junit.Test)91 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)48 Table (org.apache.hadoop.hbase.client.Table)38 Region (org.apache.hadoop.hbase.regionserver.Region)33 TableName (org.apache.hadoop.hbase.TableName)32 ServerName (org.apache.hadoop.hbase.ServerName)26 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)25 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)22 IOException (java.io.IOException)21 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)21 Configuration (org.apache.hadoop.conf.Configuration)19 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)18 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)18 Ignore (org.junit.Ignore)16 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)15 Put (org.apache.hadoop.hbase.client.Put)14 Waiter (org.apache.hadoop.hbase.Waiter)12 Admin (org.apache.hadoop.hbase.client.Admin)11 ArrayList (java.util.ArrayList)10