Search in sources :

Example 31 with RegionPlan

use of org.apache.hadoop.hbase.master.RegionPlan in project hbase by apache.

the class BalancerTestBase method reconcile.

/**
 * This assumes the RegionPlan HSI instances are the same ones in the map, so
 * actually no need to even pass in the map, but I think it's clearer.
 * @return a list of all added {@link ServerAndLoad} values.
 */
protected List<ServerAndLoad> reconcile(List<ServerAndLoad> list, List<RegionPlan> plans, Map<ServerName, List<RegionInfo>> servers) {
    List<ServerAndLoad> result = new ArrayList<>(list.size());
    Map<ServerName, ServerAndLoad> map = new HashMap<>(list.size());
    for (ServerAndLoad sl : list) {
        map.put(sl.getServerName(), sl);
    }
    if (plans != null) {
        for (RegionPlan plan : plans) {
            ServerName source = plan.getSource();
            updateLoad(map, source, -1);
            ServerName destination = plan.getDestination();
            updateLoad(map, destination, +1);
            servers.get(source).remove(plan.getRegionInfo());
            servers.get(destination).add(plan.getRegionInfo());
        }
    }
    result.clear();
    result.addAll(map.values());
    return result;
}
Also used : HashMap(java.util.HashMap) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList)

Example 32 with RegionPlan

use of org.apache.hadoop.hbase.master.RegionPlan in project hbase by apache.

the class TestSimpleLoadBalancer method testBalanceClusterOverall.

/**
 * Test the load balancing algorithm.
 *
 * Invariant is that all servers should be hosting either floor(average) or
 * ceiling(average) at both table level and cluster level
 */
@Test
public void testBalanceClusterOverall() throws Exception {
    Map<TableName, Map<ServerName, List<RegionInfo>>> clusterLoad = new TreeMap<>();
    for (int[] mockCluster : clusterStateMocks) {
        Map<ServerName, List<RegionInfo>> clusterServers = mockClusterServers(mockCluster, 30);
        List<ServerAndLoad> clusterList = convertToList(clusterServers);
        clusterLoad.put(TableName.valueOf(name.getMethodName()), clusterServers);
        HashMap<TableName, TreeMap<ServerName, List<RegionInfo>>> result = mockClusterServersWithTables(clusterServers);
        loadBalancer.setClusterLoad(clusterLoad);
        List<RegionPlan> clusterplans = new ArrayList<>();
        for (Map.Entry<TableName, TreeMap<ServerName, List<RegionInfo>>> mapEntry : result.entrySet()) {
            TableName tableName = mapEntry.getKey();
            TreeMap<ServerName, List<RegionInfo>> servers = mapEntry.getValue();
            List<ServerAndLoad> list = convertToList(servers);
            LOG.info("Mock Cluster : " + printMock(list) + " " + printStats(list));
            List<RegionPlan> partialplans = loadBalancer.balanceTable(tableName, servers);
            if (partialplans != null)
                clusterplans.addAll(partialplans);
            List<ServerAndLoad> balancedClusterPerTable = reconcile(list, partialplans, servers);
            LOG.info("Mock Balance : " + printMock(balancedClusterPerTable));
            assertClusterAsBalanced(balancedClusterPerTable);
            for (Map.Entry<ServerName, List<RegionInfo>> entry : servers.entrySet()) {
                returnRegions(entry.getValue());
                returnServer(entry.getKey());
            }
        }
        List<ServerAndLoad> balancedCluster = reconcile(clusterList, clusterplans, clusterServers);
        assertTrue(assertClusterOverallAsBalanced(balancedCluster, result.keySet().size()));
    }
}
Also used : ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TreeMap(java.util.TreeMap) TableName(org.apache.hadoop.hbase.TableName) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 33 with RegionPlan

use of org.apache.hadoop.hbase.master.RegionPlan in project hbase by apache.

the class TestRegionAssignedToMultipleRegionServers method test.

@Test
public void test() throws Exception {
    RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(NAME).get(0).getRegionInfo();
    AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
    RegionStateNode rsn = am.getRegionStates().getRegionStateNode(region);
    ServerName sn = rsn.getRegionLocation();
    ARRIVE = new CountDownLatch(1);
    HALT = true;
    am.moveAsync(new RegionPlan(region, sn, sn));
    ARRIVE.await();
    // let's restart the master
    EXCLUDE_SERVERS.add(rsn.getRegionLocation());
    KILL = true;
    HMaster activeMaster = UTIL.getMiniHBaseCluster().getMaster();
    activeMaster.abort("For testing");
    activeMaster.join();
    KILL = false;
    // sleep a while to reproduce the problem, as after the fix in HBASE-21472 the execution logic
    // is changed so the old code to reproduce the problem can not compile...
    Thread.sleep(10000);
    HALT = false;
    Thread.sleep(5000);
    HRegionServer rs = UTIL.getMiniHBaseCluster().getRegionServer(sn);
    assertNotNull(rs.getRegion(region.getEncodedName()));
    assertNull(UTIL.getOtherRegionServer(rs).getRegion(region.getEncodedName()));
}
Also used : RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 34 with RegionPlan

use of org.apache.hadoop.hbase.master.RegionPlan in project hbase by apache.

the class TestRaceBetweenSCPAndTRSP method test.

@Test
public void test() throws Exception {
    RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(NAME).get(0).getRegionInfo();
    AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
    ServerName sn = am.getRegionStates().getRegionState(region).getServerName();
    // Assign the CountDownLatches that get nulled in background threads else we NPE checking
    // the static.
    ARRIVE_REGION_OPENING = new CountDownLatch(1);
    CountDownLatch arriveRegionOpening = ARRIVE_REGION_OPENING;
    RESUME_REGION_OPENING = new CountDownLatch(1);
    ARRIVE_GET_REGIONS_ON_SERVER = new CountDownLatch(1);
    CountDownLatch arriveGetRegionsOnServer = ARRIVE_GET_REGIONS_ON_SERVER;
    RESUME_GET_REGIONS_ON_SERVER = new CountDownLatch(1);
    Future<byte[]> moveFuture = am.moveAsync(new RegionPlan(region, sn, sn));
    arriveRegionOpening.await();
    UTIL.getMiniHBaseCluster().killRegionServer(sn);
    arriveGetRegionsOnServer.await();
    RESUME_REGION_OPENING.countDown();
    moveFuture.get();
    ProcedureExecutor<?> procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
    long scpProcId = procExec.getProcedures().stream().filter(p -> p instanceof ServerCrashProcedure).map(p -> (ServerCrashProcedure) p).findAny().get().getProcId();
    RESUME_GET_REGIONS_ON_SERVER.countDown();
    UTIL.waitFor(60000, () -> procExec.isFinished(scpProcId));
}
Also used : BeforeClass(org.junit.BeforeClass) Future(java.util.concurrent.Future) HConstants(org.apache.hadoop.hbase.HConstants) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) Configuration(org.apache.hadoop.conf.Configuration) MasterServices(org.apache.hadoop.hbase.master.MasterServices) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) MasterRegion(org.apache.hadoop.hbase.master.region.MasterRegion) AfterClass(org.junit.AfterClass) KeeperException(org.apache.zookeeper.KeeperException) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) 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) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 35 with RegionPlan

use of org.apache.hadoop.hbase.master.RegionPlan in project hbase by apache.

the class TestSCPGetRegionsRace method test.

@Test
public void test() throws Exception {
    RegionInfo region = Iterables.getOnlyElement(UTIL.getMiniHBaseCluster().getRegions(NAME)).getRegionInfo();
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    AssignmentManager am = master.getAssignmentManager();
    RegionStateNode rsn = am.getRegionStates().getRegionStateNode(region);
    ServerName source = rsn.getRegionLocation();
    ServerName dest = UTIL.getAdmin().getRegionServers().stream().filter(sn -> !sn.equals(source)).findAny().get();
    ARRIVE_REPORT = new CountDownLatch(1);
    RESUME_REPORT = new CountDownLatch(1);
    Future<?> future = am.moveAsync(new RegionPlan(region, source, dest));
    ARRIVE_REPORT.await();
    ARRIVE_REPORT = null;
    // let's get procedure lock to stop the TRSP
    IdLock procExecutionLock = master.getMasterProcedureExecutor().getProcExecutionLock();
    long procId = master.getProcedures().stream().filter(p -> p instanceof RegionRemoteProcedureBase).findAny().get().getProcId();
    IdLock.Entry lockEntry = procExecutionLock.getLockEntry(procId);
    RESUME_REPORT.countDown();
    // kill the source region server
    ARRIVE_GET = new CountDownLatch(1);
    RESUME_GET = new CountDownLatch(1);
    UTIL.getMiniHBaseCluster().killRegionServer(source);
    // wait until we try to get the region list of the region server
    ARRIVE_GET.await();
    ARRIVE_GET = null;
    // release the procedure lock and let the TRSP to finish
    procExecutionLock.releaseLockEntry(lockEntry);
    future.get();
    // resume the SCP
    EXCLUDE_SERVERS.add(dest);
    RESUME_GET.countDown();
    // wait until there are no SCPs and TRSPs
    UTIL.waitFor(60000, () -> master.getProcedures().stream().allMatch(p -> p.isFinished() || (!(p instanceof ServerCrashProcedure) && !(p instanceof TransitRegionStateProcedure))));
    // assert the region is only on the dest server.
    HRegionServer rs = UTIL.getMiniHBaseCluster().getRegionServer(dest);
    assertNotNull(rs.getRegion(region.getEncodedName()));
    assertNull(UTIL.getOtherRegionServer(rs).getRegion(region.getEncodedName()));
}
Also used : BeforeClass(org.junit.BeforeClass) ReportRegionStateTransitionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse) ServerManager(org.apache.hadoop.hbase.master.ServerManager) TransitionCode(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) PleaseHoldException(org.apache.hadoop.hbase.PleaseHoldException) Configuration(org.apache.hadoop.conf.Configuration) MasterServices(org.apache.hadoop.hbase.master.MasterServices) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) MasterRegion(org.apache.hadoop.hbase.master.region.MasterRegion) AfterClass(org.junit.AfterClass) Iterables(org.apache.hbase.thirdparty.com.google.common.collect.Iterables) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) IdLock(org.apache.hadoop.hbase.util.IdLock) ReportRegionStateTransitionRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) Assert.assertNull(org.junit.Assert.assertNull) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HMaster(org.apache.hadoop.hbase.master.HMaster) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) IdLock(org.apache.hadoop.hbase.util.IdLock) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Aggregations

RegionPlan (org.apache.hadoop.hbase.master.RegionPlan)38 ServerName (org.apache.hadoop.hbase.ServerName)32 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)24 ArrayList (java.util.ArrayList)21 List (java.util.List)19 HashMap (java.util.HashMap)17 TableName (org.apache.hadoop.hbase.TableName)16 Map (java.util.Map)14 Test (org.junit.Test)14 IOException (java.io.IOException)11 TreeMap (java.util.TreeMap)11 CountDownLatch (java.util.concurrent.CountDownLatch)8 HMaster (org.apache.hadoop.hbase.master.HMaster)7 MasterServices (org.apache.hadoop.hbase.master.MasterServices)7 Configuration (org.apache.hadoop.conf.Configuration)6 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)6 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)6 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)6 MasterRegion (org.apache.hadoop.hbase.master.region.MasterRegion)6 MasterTests (org.apache.hadoop.hbase.testclassification.MasterTests)6