From afbdd4115b7302053e0684b26c6404ed68ee0b42 Mon Sep 17 00:00:00 2001 From: clarax Date: Fri, 3 Sep 2021 18:36:55 -0700 Subject: [PATCH] HBASE-26237 Improve computation complexity for primaryRegionCountSkewCostFunction (#3657) Signed-off-by: Duo Zhang Signed-off-by: Huaxiang Sun --- .../balancer/PrimaryRegionCountSkewCostFunction.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/PrimaryRegionCountSkewCostFunction.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/PrimaryRegionCountSkewCostFunction.java index ab1500eaedf..a78ff8992f6 100644 --- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/PrimaryRegionCountSkewCostFunction.java +++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/PrimaryRegionCountSkewCostFunction.java @@ -66,8 +66,12 @@ class PrimaryRegionCountSkewCostFunction extends CostFunction { @Override protected void regionMoved(int region, int oldServer, int newServer) { cost.applyCostsChange(costs -> { - costs[oldServer] = computeCostForRegionServer(oldServer); - costs[newServer] = computeCostForRegionServer(newServer); + if (region == cluster.regionIndexToPrimaryIndex[region]) { + if (oldServer >= 0) { + costs[oldServer]--; + } + costs[newServer]++; + } }); } @@ -80,4 +84,4 @@ class PrimaryRegionCountSkewCostFunction extends CostFunction { protected double cost() { return cost.cost(); } -} \ No newline at end of file +}