rmdmattingly commented on code in PR #6651:
URL: https://github.com/apache/hbase/pull/6651#discussion_r1932832072


##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java:
##########
@@ -711,6 +726,44 @@ enum LocalityType {
     RACK
   }
 
+  public List<RegionPlan> convertActionToPlans(BalanceAction action) {

Review Comment:
   RegionPlans are much simpler than balance actions because they can represent 
the consequences of every type of balance action. With that in mind, I chose to 
have balancer conditionals only be concerned with RegionPlans so that their 
implementations could be simpler — but it means that I need to convert 
BalanceActions to region plans, without applying the plans, for evaluation 
against conditionals. Thus, this method needed to be added



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java:
##########
@@ -905,6 +975,52 @@ int[] addRegion(int[] regions, int regionIndex) {
     return newRegions;
   }
 
+  int[] removeRegions(int[] regions, Set<Integer> regionIndicesToRemove) {

Review Comment:
   This method, and the below addRegions, are just a nicer way to add/remove 
regions from the BCS arrays in bulk



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerConditionals.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.master.RegionPlan;
+import org.apache.hadoop.hbase.util.ReflectionUtils;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet;
+
+/**
+ * Balancer conditionals supplement cost functions in the {@link 
StochasticLoadBalancer}. Cost
+ * functions are insufficient and difficult to work with when making discrete 
decisions; this is
+ * because they operate on a continuous scale, and each cost function's 
multiplier affects the
+ * relative importance of every other cost function. So it is difficult to 
meaningfully and clearly
+ * value many aspects of your region distribution via cost functions alone. 
Conditionals allow you
+ * to very clearly define discrete rules that your balancer would ideally 
follow. To clarify, a
+ * conditional violation will not block a region assignment because we would 
prefer to have uptime
+ * than have perfectly intentional balance. But conditionals allow you to, for 
example, define that
+ * a region's primary and secondary should not live on the same rack. Another 
example, conditionals
+ * make it easy to define that system tables will ideally be isolated on their 
own RegionServer
+ * (without needing to manage distinct RegionServer groups). Use of 
conditionals may cause an
+ * extremely unbalanced cluster to exceed its max balancer runtime. This is 
necessary because
+ * conditional candidate generation is quite expensive, and cutting it off 
early could prevent us
+ * from finding a solution.
+ */
[email protected]
+final class BalancerConditionals implements Configurable {

Review Comment:
   This acts as a unified interface for interacting with whatever 
conditional(s) one might have enabled



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.master.RegionPlan;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
[email protected]
[email protected]
+public abstract class RegionPlanConditional {
+  private static final Logger LOG = 
LoggerFactory.getLogger(RegionPlanConditional.class);
+  private BalancerClusterState cluster;
+
+  RegionPlanConditional(Configuration conf, BalancerClusterState cluster) {
+    this.cluster = cluster;
+  }
+
+  public enum ValidationLevel {
+    SERVER, // Just check server
+    HOST, // Check host and server
+    RACK // Check rack, host, and server
+  }

Review Comment:
   All 3 checks will be necessary for replica balancing, but for most 
conditionals (I envision a system table isolation conditional, for example) my 
guess is that only server validation will be necessary. So I figured that this 
is a nice way to let implementations be as simple as possible



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalanceAction.java:
##########
@@ -28,6 +28,7 @@ enum Type {
     ASSIGN_REGION,
     MOVE_REGION,
     SWAP_REGIONS,
+    MOVE_BATCH,

Review Comment:
   Conditional candidate generators will look at the entire cluster state, and 
produce a series of moves that should move us towards compliance. To support 
this, I thought a "batch move" balance action made sense



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/SlopFixingCandidateGenerator.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.ServerName;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A simple candidate generator that attempts to move regions from the 
most-loaded servers to the
+ * least-loaded servers.
+ */
[email protected]
+final class SlopFixingCandidateGenerator extends 
RegionPlanConditionalCandidateGenerator {

Review Comment:
   This is a very time-effective way to resolve the sloppy servers that may be 
produced by randomly distributing replicas across the cluster. I probably 
anticipate this being useful in future conditionals too



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java:
##########
@@ -515,6 +557,7 @@ private long calculateMaxSteps(BalancerClusterState 
cluster) {
    * approach the optimal state given enough steps.
    */
   @Override
+  @SuppressWarnings("checkstyle:MethodLength")

Review Comment:
   Open to the idea that we should actually clean this up a bit instead of 
suppressing this warning, but the diff here is already big so I didn't want to 
add a bunch of refactoring that made it harder to read



-- 
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]

Reply via email to