@Override public TableName getTableName() { return plan.getRegionInfo().getTable(); }
public Future<byte[]> moveAsync(RegionPlan regionPlan) throws HBaseIOException { TransitRegionStateProcedure proc = createMoveRegionProcedure(regionPlan.getRegionInfo(), regionPlan.getDestination()); return ProcedureSyncWait.submitProcedure(master.getMasterProcedureExecutor(), proc); }
/** * 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. * * @param list * @param plans * @return */ 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; }
plan.getRegionInfo().getEncodedName(), server); moveAsync(plan);
for(RegionPlan plan : plans) { if(plan.getSource().equals(serverA)) { regionsMoveFromServerA.add(plan.getRegionInfo()); targetServers.add(plan.getDestination());
for(RegionPlan plan : plans) { if(plan.getSource().equals(serverA)) { regionsMoveFromServerA.add(plan.getRegionInfo()); targetServers.add(plan.getDestination());
@Override public int compare(RegionPlan l, RegionPlan r) { long diff = r.getRegionInfo().getRegionId() - l.getRegionInfo().getRegionId(); if (diff < 0) return -1; if (diff > 0) return 1; return 0; } }
@Override public int compare(RegionPlan l, RegionPlan r) { long diff = r.getRegionInfo().getRegionId() - l.getRegionInfo().getRegionId(); if (diff < 0) return -1; if (diff > 0) return 1; return 0; } }
/** * @param plan Plan to execute. */ void balance(final RegionPlan plan) { synchronized (this.regionPlans) { this.regionPlans.put(plan.getRegionName(), plan); } unassign(plan.getRegionInfo()); }
public static List<RegionPlan> makePlan(HBaseAdmin admin, List<RegionPlan> newRegionPlan) throws IOException { // snapshot current region assignment Map<HRegionInfo, ServerName> regionAssignmentMap = createRegionAssignmentMap(admin); // update with new plan for (RegionPlan regionPlan : newRegionPlan) { regionAssignmentMap.put(regionPlan.getRegionInfo(), regionPlan.getDestination()); } Map<ServerName, List<HRegionInfo>> clusterState = initializeRegionMap(admin); for (Map.Entry<HRegionInfo, ServerName> entry : regionAssignmentMap.entrySet()) clusterState.get(entry.getValue()).add(entry.getKey()); StochasticLoadBalancer balancer = new StochasticLoadBalancer(); Configuration conf = admin.getConfiguration(); conf.setFloat("hbase.regions.slop", 0.2f); balancer.setConf(conf); return balancer.balanceCluster(clusterState); }
@SuppressWarnings("deprecation") private void balance(Args args, List<RegionPlan> regionPlanList, Phase phase, boolean asynchronous) throws IOException, InterruptedException { int progress = 1; for (RegionPlan regionPlan : regionPlanList) { String tableName = Bytes.toString(regionPlan.getRegionInfo().getTableName()); String encodedRegionName = regionPlan.getRegionInfo().getEncodedName(); String serverNameDest = regionPlan.getDestination().getServerName(); String serverNameSource; if (regionPlan.getSource() == null) { serverNameSource = "N/A"; } else { serverNameSource = regionPlan.getSource().getServerName(); } String planStr = progress++ + "/" + regionPlanList.size() + " - move " + encodedRegionName + " of " + tableName + " from " + serverNameSource + " to " + serverNameDest; if (phase == Phase.BALANCE) { System.out.print(planStr); } else { System.out.println(planStr); } if (phase == Phase.BALANCE) { Common.moveWithPrintingResult(args, admin, tableName, encodedRegionName, serverNameDest, asynchronous); } } if (asynchronous && phase == Phase.BALANCE) Thread.sleep(Constant.SMALL_WAIT_INTERVAL_MS); }
/** * 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. * * @param list * @param plans * @return */ 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; }
/** * @param plan Plan to execute. */ public void balance(final RegionPlan plan) { HRegionInfo hri = plan.getRegionInfo(); TableName tableName = hri.getTable(); if (tableStateManager.isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) { LOG.info("Ignored moving region of disabling/disabled table " + tableName); return; } // Move the region only if it's assigned String encodedName = hri.getEncodedName(); ReentrantLock lock = locker.acquireLock(encodedName); try { if (!regionStates.isRegionOnline(hri)) { RegionState state = regionStates.getRegionState(encodedName); LOG.info("Ignored moving region not assigned: " + hri + ", " + (state == null ? "not in region states" : state)); return; } synchronized (this.regionPlans) { this.regionPlans.put(plan.getRegionName(), plan); } unassign(hri, false, plan.getDestination()); } finally { lock.unlock(); } }
this.regionsInTransition.remove(plan.getRegionInfo() .getEncodedName()); this.regions.put(plan.getRegionInfo(), plan.getDestination());