rmdmattingly commented on code in PR #6722: URL: https://github.com/apache/hbase/pull/6722#discussion_r1971665300
########## hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/TableIsolationCandidateGenerator.java: ########## @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.master.balancer; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + [email protected] +public abstract class TableIsolationCandidateGenerator + extends RegionPlanConditionalCandidateGenerator { + + private static final Logger LOG = LoggerFactory.getLogger(TableIsolationCandidateGenerator.class); + + TableIsolationCandidateGenerator(BalancerConditionals balancerConditionals) { + super(balancerConditionals); + } + + abstract boolean shouldBeIsolated(RegionInfo regionInfo); + + @Override + BalanceAction generate(BalancerClusterState cluster) { + return generateCandidate(cluster, false); + } + + BalanceAction generateCandidate(BalancerClusterState cluster, boolean isWeighing) { + if (!getBalancerConditionals().isTableIsolationEnabled()) { + return BalanceAction.NULL_ACTION; + } + + List<MoveRegionAction> moves = new ArrayList<>(); + List<Integer> serverIndicesHoldingIsolatedRegions = new ArrayList<>(); + int isolatedTableMaxReplicaCount = 1; + for (int serverIdx : cluster.getShuffledServerIndices()) { + if (EnvironmentEdgeManager.currentTime() > cluster.getStopRequestedAt()) { + break; + } + boolean hasRegionsToIsolate = false; + Set<Integer> regionsToMove = new HashSet<>(); + + // Move non-target regions away from target regions, + // and track replica counts so we know how many isolated hosts we need + for (int regionIdx : cluster.regionsPerServer[serverIdx]) { + RegionInfo regionInfo = cluster.regions[regionIdx]; + if (shouldBeIsolated(regionInfo)) { + hasRegionsToIsolate = true; + int replicaCount = regionInfo.getReplicaId() + 1; + if (replicaCount > isolatedTableMaxReplicaCount) { + isolatedTableMaxReplicaCount = replicaCount; + } + } else { + regionsToMove.add(regionIdx); + } + } + + if (hasRegionsToIsolate) { + serverIndicesHoldingIsolatedRegions.add(serverIdx); + } + + // Generate non-system regions to move, if applicable + if (hasRegionsToIsolate && !regionsToMove.isEmpty()) { + for (int regionToMove : regionsToMove) { + for (int i = 0; i < cluster.numServers; i++) { + int targetServer = pickOtherRandomServer(cluster, serverIdx); + MoveRegionAction possibleMove = + new MoveRegionAction(regionToMove, serverIdx, targetServer); + if (!getBalancerConditionals().isViolating(cluster, possibleMove)) { + if (isWeighing) { + return possibleMove; Review Comment: Good question. So all candidate generators maintain a "weight" which influences their likelihood of being selected for the next proposed action. Conditional candidate generators, on brand with their binary decision making, are weighed based on whether they have any work to do — if they do, then we'll prioritize their moves over the more generic generators (like the `RandomCandidateGenerator`). So `generateAction` can get called in two distinct ways: to produce a robust plan of action, or to weigh whether there is _any_ work to do. In the latter, we'd like to exit as early as possible to speed things up -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
