[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r338148191 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,306 @@ +/** + * 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.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. A + * rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. A + * rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. The costFunction is trying to fill all RegionServers + * linearly, meaning that if the global usage is at 50%, then all RegionServers should hold half of + * their capacity in terms of regions. In order to use this CostFunction, you need to set the + * following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = + LoggerFactory.getLogger(HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private final Configuration conf; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + double overallUsage; + + HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.conf = conf; +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + Review comment: I meant the empty lines within methods bodies should be avoided. For example, in this method, lines #103, #105, #113. In **cost()** further below, lines #133, #135, #139, etc could all be ripped off. This is an automated message from the Apache Git Service. To
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r337931232 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,306 @@ +/** + * 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.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. A + * rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. A + * rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. The costFunction is trying to fill all RegionServers + * linearly, meaning that if the global usage is at 50%, then all RegionServers should hold half of + * their capacity in terms of regions. In order to use this CostFunction, you need to set the + * following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = + LoggerFactory.getLogger(HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private final Configuration conf; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + double overallUsage; + + HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.conf = conf; +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + Review comment: Let's adhere to hbase's project code convention: > avoid lines with nothing but whitespace See [here](https://hbase.apache.org/book.html#common.patch.feedback.trailingspaces). This is an automated message from the Apache Git Service. To respond to
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r337922099 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,306 @@ +/** + * 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.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. A + * rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. A + * rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. The costFunction is trying to fill all RegionServers + * linearly, meaning that if the global usage is at 50%, then all RegionServers should hold half of + * their capacity in terms of regions. In order to use this CostFunction, you need to set the + * following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = + LoggerFactory.getLogger(HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; Review comment: Just a follow up: Javadoc message above mentions default as 500, while here we set 5000. You may want to fix either the comment or the variable initial value. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r337923846 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,306 @@ +/** + * 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.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. A + * rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. A + * rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. The costFunction is trying to fill all RegionServers + * linearly, meaning that if the global usage is at 50%, then all RegionServers should hold half of + * their capacity in terms of regions. In order to use this CostFunction, you need to set the + * following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = + LoggerFactory.getLogger(HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private final Configuration conf; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + double overallUsage; + + HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.conf = conf; +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + +this.rulesPath = conf.get(HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE); + +this.defaultNumberOfRegions = +conf.getInt(HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT, 200); +if (this.defaultNumberOfRegions < 0) { + LOG.warn("invalid configuration '" + HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT + + "'.
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r331881564 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,288 @@ +/** + * 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. + * A rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. + * A rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 + * * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. + * The costFunction is trying to fill all RegionServers linearly, meaning that if the global usage + * is at 50%, then all RegionServers should hold half of their capacity in terms of regions. + * In order to use this CostFunction, you need to set the following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = LoggerFactory.getLogger( + HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + + + public HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + +this.rulesPath = conf.get(HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE); + +this.defaultNumberOfRegions = conf.getInt( +HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT, 200); +if (this.defaultNumberOfRegions < 0) { + LOG.warn("invalid configuration '" + HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT + +"'. Setting default to 200"); +
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r330724758 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java ## @@ -86,7 +86,7 @@ * * * You can also add custom Cost function by setting the the following configuration value: - * + * '. There also seems to be some wrong indentation due to IDE auto formatting rules? Please address those as reported by checkstyles. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r330993967 ## File path: hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java ## @@ -366,20 +366,31 @@ protected void updateLoad(final Map map, } protected TreeMap> mockClusterServers(int[] mockCluster) { -return mockClusterServers(mockCluster, -1); +return mockClusterServers(mockCluster, -1, false); + } + + protected TreeMap> mockClusterServers(int[] mockCluster, int numTables) { +return mockClusterServers(mockCluster, -1, false); } protected BaseLoadBalancer.Cluster mockCluster(int[] mockCluster) { return new BaseLoadBalancer.Cluster( mockClusterServers(mockCluster, -1), null, null, null); } - protected TreeMap> mockClusterServers(int[] mockCluster, int numTables) { + protected TreeMap> mockClusterServers(int[] mockCluster, int numTables, boolean predictibleHosts) { int numServers = mockCluster.length; TreeMap> servers = new TreeMap<>(); for (int i = 0; i < numServers; i++) { int numRegions = mockCluster[i]; - ServerAndLoad sal = randomServer(0); + + ServerAndLoad sal; + if (predictibleHosts) { +sal = randomServer(0, "rs" + i); Review comment: My understanding is that this is the main motivation for having all these _overridings_ here in **BalancerTestBase**. However, this seems very specific for the conditions tested in **TestStochasticLoadBalancerHeterogeneousCost**, so why not leave **BalancerTestBase** untouched, and only override _randomServer(final int numRegionsPerServer)_ on **TestStochasticLoadBalancerHeterogeneousCost** instead? 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r331014143 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,288 @@ +/** + * 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. + * A rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. + * A rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 + * * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. + * The costFunction is trying to fill all RegionServers linearly, meaning that if the global usage + * is at 50%, then all RegionServers should hold half of their capacity in terms of regions. + * In order to use this CostFunction, you need to set the following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = LoggerFactory.getLogger( + HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + + + public HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + +this.rulesPath = conf.get(HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE); + +this.defaultNumberOfRegions = conf.getInt( +HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT, 200); +if (this.defaultNumberOfRegions < 0) { + LOG.warn("invalid configuration '" + HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT + +"'. Setting default to 200"); +
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r331005931 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,288 @@ +/** + * 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. + * A rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. + * A rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 + * * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. + * The costFunction is trying to fill all RegionServers linearly, meaning that if the global usage + * is at 50%, then all RegionServers should hold half of their capacity in terms of regions. + * In order to use this CostFunction, you need to set the following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = LoggerFactory.getLogger( + HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + + + public HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + +this.rulesPath = conf.get(HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE); + +this.defaultNumberOfRegions = conf.getInt( +HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT, 200); +if (this.defaultNumberOfRegions < 0) { + LOG.warn("invalid configuration '" + HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT + +"'. Setting default to 200"); +
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r330980810 ## File path: hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java ## @@ -486,18 +497,22 @@ protected void returnRegions(List regions) { private Queue serverQueue = new LinkedList<>(); - protected ServerAndLoad randomServer(final int numRegionsPerServer) { + protected ServerAndLoad randomServer(final int numRegionsPerServer, final String host) { Review comment: Change this method name? As we specify the host, does not look we are choosing server randomly. Or maybe I'm confusing things. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r331010273 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,288 @@ +/** + * 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. + * A rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. + * A rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 + * * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. + * The costFunction is trying to fill all RegionServers linearly, meaning that if the global usage + * is at 50%, then all RegionServers should hold half of their capacity in terms of regions. + * In order to use this CostFunction, you need to set the following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = LoggerFactory.getLogger( + HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + + + public HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + +this.rulesPath = conf.get(HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE); + +this.defaultNumberOfRegions = conf.getInt( +HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT, 200); +if (this.defaultNumberOfRegions < 0) { + LOG.warn("invalid configuration '" + HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT + +"'. Setting default to 200"); +
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r331002282 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,288 @@ +/** + * 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. + * A rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. + * A rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 + * * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. + * The costFunction is trying to fill all RegionServers linearly, meaning that if the global usage + * is at 50%, then all RegionServers should hold half of their capacity in terms of regions. + * In order to use this CostFunction, you need to set the following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = LoggerFactory.getLogger( + HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + + + public HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + +this.rulesPath = conf.get(HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE); + +this.defaultNumberOfRegions = conf.getInt( +HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT, 200); +if (this.defaultNumberOfRegions < 0) { + LOG.warn("invalid configuration '" + HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT + +"'. Setting default to 200"); +
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r331002689 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,288 @@ +/** + * 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. + * A rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. + * A rule is composed of a regexp for hostname, and a limit. For example, we could have: + * + * * rs[0-9] 200 + * * rs1[0-9] 50 + * + * RegionServers with hostname matching the first rules will have a limit of 200, and the others 50. + * If there's no match, a default is set. + * The costFunction is trying to fill all RegionServers linearly, meaning that if the global usage + * is at 50%, then all RegionServers should hold half of their capacity in terms of regions. + * In order to use this CostFunction, you need to set the following options: + * + * hbase.master.balancer.stochastic.additionalCostFunctions + * hbase.master.balancer.stochastic.heterogeneousRegionCountRulesFile + * hbase.master.balancer.stochastic.heterogeneousRegionCountDefault + * + */ +@InterfaceAudience.Private +public class HeterogeneousRegionCountCostFunction extends StochasticLoadBalancer.CostFunction { + + /** + * configuration used for the path where the rule file is stored. + */ + static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE = + "hbase.master.balancer.heterogeneousRegionCountRulesFile"; + private static final Logger LOG = LoggerFactory.getLogger( + HeterogeneousRegionCountCostFunction.class); + /** + * Default rule to apply when the rule file is not found. Default to 200. + */ + private static final String HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT = + "hbase.master.balancer.heterogeneousRegionCountDefault"; + /** + * Cost for the function. Default to 500, can be changed. + */ + private static final String REGION_COUNT_SKEW_COST_KEY = + "hbase.master.balancer.stochastic.heterogeneousRegionCountCost"; + private static final float DEFAULT_REGION_COUNT_SKEW_COST = 5000; + private final String rulesPath; + + /** + * Contains the rules, key is the regexp for ServerName, value is the limit + */ + private final Map limitPerRule; + + /** + * This is a cache, used to not go through all the limitPerRule map when searching for limit + */ + private final Map limitPerRS; + private int defaultNumberOfRegions; + + /** + * Total capacity of regions for the cluster, based on the online RS and their associated rules + */ + private int totalCapacity = 0; + + + public HeterogeneousRegionCountCostFunction(final Configuration conf) { +super(conf); +this.limitPerRS = new HashMap<>(); +this.limitPerRule = new HashMap<>(); +this.setMultiplier(conf.getFloat(REGION_COUNT_SKEW_COST_KEY, DEFAULT_REGION_COUNT_SKEW_COST)); + +this.rulesPath = conf.get(HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_FILE); + +this.defaultNumberOfRegions = conf.getInt( +HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT, 200); +if (this.defaultNumberOfRegions < 0) { + LOG.warn("invalid configuration '" + HBASE_MASTER_BALANCER_HETEROGENEOUS_RULES_DEFAULT + +"'. Setting default to 200"); +
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r330982258 ## File path: hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java ## @@ -366,20 +366,31 @@ protected void updateLoad(final Map map, } protected TreeMap> mockClusterServers(int[] mockCluster) { -return mockClusterServers(mockCluster, -1); +return mockClusterServers(mockCluster, -1, false); + } + + protected TreeMap> mockClusterServers(int[] mockCluster, int numTables) { +return mockClusterServers(mockCluster, -1, false); } protected BaseLoadBalancer.Cluster mockCluster(int[] mockCluster) { return new BaseLoadBalancer.Cluster( mockClusterServers(mockCluster, -1), null, null, null); } - protected TreeMap> mockClusterServers(int[] mockCluster, int numTables) { + protected TreeMap> mockClusterServers(int[] mockCluster, int numTables, boolean predictibleHosts) { Review comment: nit: Since we are here, address checkstyle max column number violation. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r330909237 ## File path: hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java ## @@ -366,20 +366,31 @@ protected void updateLoad(final Map map, } protected TreeMap> mockClusterServers(int[] mockCluster) { -return mockClusterServers(mockCluster, -1); +return mockClusterServers(mockCluster, -1, false); + } + + protected TreeMap> mockClusterServers(int[] mockCluster, int numTables) { Review comment: unused parameter _numTables_? Seems like we don't need this overload. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r330983936 ## File path: hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java ## @@ -366,20 +366,31 @@ protected void updateLoad(final Map map, } protected TreeMap> mockClusterServers(int[] mockCluster) { -return mockClusterServers(mockCluster, -1); +return mockClusterServers(mockCluster, -1, false); + } + + protected TreeMap> mockClusterServers(int[] mockCluster, int numTables) { +return mockClusterServers(mockCluster, -1, false); } protected BaseLoadBalancer.Cluster mockCluster(int[] mockCluster) { return new BaseLoadBalancer.Cluster( mockClusterServers(mockCluster, -1), null, null, null); } - protected TreeMap> mockClusterServers(int[] mockCluster, int numTables) { + protected TreeMap> mockClusterServers(int[] mockCluster, int numTables, boolean predictibleHosts) { Review comment: nit: _predictableHosts_ instead of _predictibleHosts_ 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r331006305 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java ## @@ -0,0 +1,288 @@ +/** + * 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an optional Cost function designed to allow region count skew across RegionServers. + * A rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. Review comment: May need to review this assertion regarding local FS. See comment for _readFile_. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hbase] wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule
wchevreuil commented on a change in pull request #677: HBASE-23073 Add an optional costFunction to balance regions according to a capacity rule URL: https://github.com/apache/hbase/pull/677#discussion_r330904090 ## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java ## @@ -654,6 +654,22 @@ protected double computeCost(Cluster cluster, double previousCost) { return total; } + /** Review comment: Is this method really needed? It appears to be used on a test only, just to assert the related cost function was loaded, but maybe we can just assert the expected result for the cost function, instead of checking internals of StochasticLoadBalancer. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services