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;
}
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()));
}
}
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()));
}
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));
}
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()));
}
Aggregations