public Future<byte[]> moveAsync(RegionPlan regionPlan) throws HBaseIOException { TransitRegionStateProcedure proc = createMoveRegionProcedure(regionPlan.getRegionInfo(), regionPlan.getDestination()); return ProcedureSyncWait.submitProcedure(master.getMasterProcedureExecutor(), proc); }
@Override protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { super.serializeStateData(serializer); final MoveRegionStateData.Builder state = MoveRegionStateData.newBuilder() // No need to serialize the RegionInfo. The super class has the region. .setSourceServer(ProtobufUtil.toServerName(plan.getSource())); if (plan.getDestination() != null) { state.setDestinationServer(ProtobufUtil.toServerName(plan.getDestination())); } serializer.serialize(state.build()); }
List<Integer> pos = returnMap.get(regionsToReturn.get(i).getDestination()); if (pos == null) { pos = new ArrayList<>(); returnMap.put(regionsToReturn.get(i).getDestination(), pos); if (pos != null && pos.size() != 0) { regionsToReturn.get(pos.get(pos.size() - 1)).setDestination( regionsToReturn.get(regionsToReturn.size() - 1).getDestination()); pos.remove(pos.size() - 1); regionsToReturn.remove(regionsToReturn.size() - 1);
/** * 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; }
assert rp.getDestination() != null: rp.toString() + " " + dest; this.cpHost.preMove(hri, rp.getSource(), rp.getDestination()); serverManager.sendRegionWarmup(rp.getDestination(), hri); this.cpHost.postMove(hri, rp.getSource(), rp.getDestination());
if(plan.getSource().equals(serverA)) { regionsMoveFromServerA.add(plan.getRegionInfo()); targetServers.add(plan.getDestination());
protected ArrayListMultimap<String, ServerAndLoad> reconcile( ArrayListMultimap<String, ServerAndLoad> previousLoad, List<RegionPlan> plans) { ArrayListMultimap<String, ServerAndLoad> result = ArrayListMultimap .create(); result.putAll(previousLoad); if (plans != null) { for (RegionPlan plan : plans) { ServerName source = plan.getSource(); updateLoad(result, source, -1); ServerName destination = plan.getDestination(); updateLoad(result, destination, +1); } } return result; }
if(plan.getSource().equals(serverA)) { regionsMoveFromServerA.add(plan.getRegionInfo()); targetServers.add(plan.getDestination());
if (e.getValue() == null || e.getValue().getDestination() == null) continue; if (!e.getValue().getDestination().equals(sn)) continue; RegionState rs = null; synchronized (this.regionsInTransition) {
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); }
this.regionPlans.entrySet().iterator(); i.hasNext();) { Map.Entry<String, RegionPlan> e = i.next(); ServerName otherSn = e.getValue().getDestination();
existingPlan = this.regionPlans.get(encodedName); if (existingPlan != null && existingPlan.getDestination() != null) { LOG.debug("Found an existing plan for " + state.getRegion().getRegionNameAsString() + " destination server is " + existingPlan.getDestination().toString()); || existingPlan.getDestination() == null || drainingServers.contains(existingPlan.getDestination())) { newPlan = true; randomPlan = new RegionPlan(state.getRegion(), null, balancer
existingPlan = this.regionPlans.get(encodedName); if (existingPlan != null && existingPlan.getDestination() != null) { LOG.debug("Found an existing plan for " + region.getRegionNameAsString() + " destination server is " + existingPlan.getDestination() + " accepted as a dest server = " + destServers.contains(existingPlan.getDestination())); || existingPlan.getDestination() == null || !destServers.contains(existingPlan.getDestination())) { newPlan = true;
@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); }
@Override protected void chore() { // If bulkAssign in progress, suspend checks if (this.bulkAssign) return; boolean allRSsOffline = this.serverManager.getOnlineServersList(). isEmpty(); synchronized (regionsInTransition) { // Iterate all regions in transition checking for time outs long now = System.currentTimeMillis(); for (RegionState regionState : regionsInTransition.values()) { if (regionState.getStamp() + timeout <= now) { //decide on action upon timeout actOnTimeOut(regionState); } else if (this.allRegionServersOffline && !allRSsOffline) { RegionPlan existingPlan = regionPlans.get(regionState.getRegion().getEncodedName()); if (existingPlan == null || !this.serverManager.isServerOnline(existingPlan.getDestination())) { // if some RSs just came back online, we can start the // the assignment right away actOnTimeOut(regionState); } } } } setAllRegionServersOffline(allRSsOffline); }
i.hasNext();) { Map.Entry<String, RegionPlan> e = i.next(); ServerName otherSn = e.getValue().getDestination();
/** * 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(); } }
private ArrayListMultimap<String, ServerAndLoad> reconcile( ArrayListMultimap<String, ServerAndLoad> previousLoad, List<RegionPlan> plans) { ArrayListMultimap<String, ServerAndLoad> result = ArrayListMultimap .create(); result.putAll(previousLoad); if (plans != null) { for (RegionPlan plan : plans) { ServerName source = plan.getSource(); updateLoad(result, source, -1); ServerName destination = plan.getDestination(); updateLoad(result, destination, +1); } } return result; }
checkInitialized(); if (this.cpHost != null) { if (this.cpHost.preMove(hri, rp.getSource(), rp.getDestination())) { return; serverManager.sendRegionWarmup(rp.getDestination(), hri); this.cpHost.postMove(hri, rp.getSource(), rp.getDestination());