From 480b6bb6379ab720b2e809a84ee6e7c3e72a43e6 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Tue, 15 Jun 2021 11:53:00 +0800 Subject: [PATCH] HBASE-25995 Change the method name for DoubleArrayCost.setCosts (#3381) Signed-off-by: Yulin Niu --- .../master/balancer/CostFromRegionLoadFunction.java | 4 ++-- .../hadoop/hbase/master/balancer/DoubleArrayCost.java | 11 ++++++++++- .../balancer/PrimaryRegionCountSkewCostFunction.java | 4 ++-- .../master/balancer/RegionCountSkewCostFunction.java | 4 ++-- .../hbase/master/balancer/TestDoubleArrayCost.java | 6 +++--- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CostFromRegionLoadFunction.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CostFromRegionLoadFunction.java index 34657df00ad..06eb07d67e0 100644 --- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CostFromRegionLoadFunction.java +++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CostFromRegionLoadFunction.java @@ -49,7 +49,7 @@ abstract class CostFromRegionLoadFunction extends CostFunction { void prepare(BalancerClusterState cluster) { super.prepare(cluster); cost.prepare(cluster.numServers); - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { for (int i = 0; i < costs.length; i++) { costs[i] = computeCostForRegionServer(i); } @@ -59,7 +59,7 @@ abstract class CostFromRegionLoadFunction extends CostFunction { @Override protected void regionMoved(int region, int oldServer, int newServer) { // recompute the stat for the given two region servers - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { costs[oldServer] = computeCostForRegionServer(oldServer); costs[newServer] = computeCostForRegionServer(newServer); }); diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/DoubleArrayCost.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/DoubleArrayCost.java index cf20a33d7ae..11325c08a12 100644 --- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/DoubleArrayCost.java +++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/DoubleArrayCost.java @@ -43,7 +43,16 @@ final class DoubleArrayCost { } } - void setCosts(Consumer consumer) { + /** + * We do not want to introduce a getCosts method to let upper layer get the cost array directly, + * so here we introduce this method to take a {@link Consumer} as parameter, where we will pass + * the actual cost array in, so you can change the element of the cost array in the + * {@link Consumer} implementation. + *

+ * Usually, in prepare method, you need to fill all the elements of the cost array, while in + * regionMoved method, you just need to update the element for the effect region servers. + */ + void applyCostsChange(Consumer consumer) { consumer.accept(costs); costsChanged = true; } 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 441d4a1cf69..ab1500eaedf 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 @@ -56,7 +56,7 @@ class PrimaryRegionCountSkewCostFunction extends CostFunction { return; } cost.prepare(cluster.numServers); - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { for (int i = 0; i < costs.length; i++) { costs[i] = computeCostForRegionServer(i); } @@ -65,7 +65,7 @@ class PrimaryRegionCountSkewCostFunction extends CostFunction { @Override protected void regionMoved(int region, int oldServer, int newServer) { - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { costs[oldServer] = computeCostForRegionServer(oldServer); costs[newServer] = computeCostForRegionServer(newServer); }); diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionCountSkewCostFunction.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionCountSkewCostFunction.java index 55c502bc44c..4f66ba465c3 100644 --- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionCountSkewCostFunction.java +++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionCountSkewCostFunction.java @@ -45,7 +45,7 @@ class RegionCountSkewCostFunction extends CostFunction { void prepare(BalancerClusterState cluster) { super.prepare(cluster); cost.prepare(cluster.numServers); - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { for (int i = 0; i < cluster.numServers; i++) { costs[i] = cluster.regionsPerServer[i].length; } @@ -67,7 +67,7 @@ class RegionCountSkewCostFunction extends CostFunction { @Override protected void regionMoved(int region, int oldServer, int newServer) { - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { costs[oldServer] = cluster.regionsPerServer[oldServer].length; costs[newServer] = cluster.regionsPerServer[newServer].length; }); diff --git a/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestDoubleArrayCost.java b/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestDoubleArrayCost.java index 528b654efc8..d3bef06759e 100644 --- a/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestDoubleArrayCost.java +++ b/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestDoubleArrayCost.java @@ -38,7 +38,7 @@ public class TestDoubleArrayCost { DoubleArrayCost cost = new DoubleArrayCost(); cost.prepare(100); - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { for (int i = 0; i < 100; i++) { costs[i] = 10; } @@ -46,7 +46,7 @@ public class TestDoubleArrayCost { assertEquals(0, cost.cost(), 0.01); cost.prepare(101); - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { for (int i = 0; i < 100; i++) { costs[i] = 0; } @@ -55,7 +55,7 @@ public class TestDoubleArrayCost { assertEquals(1, cost.cost(), 0.01); cost.prepare(200); - cost.setCosts(costs -> { + cost.applyCostsChange(costs -> { for (int i = 0; i < 100; i++) { costs[i] = 0; costs[i + 100] = 100;