Skip to content

Commit 09c6375

Browse files
committed
HBASE-25995 Change the method name for DoubleArrayCost.setCosts (#3381)
Signed-off-by: Yulin Niu <[email protected]>
1 parent 5ffb1ec commit 09c6375

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/DoubleArrayCost.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ void prepare(int length) {
4343
}
4444
}
4545

46-
void setCosts(Consumer<double[]> consumer) {
46+
/**
47+
* We do not want to introduce a getCosts method to let upper layer get the cost array directly,
48+
* so here we introduce this method to take a {@link Consumer} as parameter, where we will pass
49+
* the actual cost array in, so you can change the element of the cost array in the
50+
* {@link Consumer} implementation.
51+
* <p/>
52+
* Usually, in prepare method, you need to fill all the elements of the cost array, while in
53+
* regionMoved method, you just need to update the element for the effect region servers.
54+
*/
55+
void applyCostsChange(Consumer<double[]> consumer) {
4756
consumer.accept(costs);
4857
costsChanged = true;
4958
}

hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ static class RegionCountSkewCostFunction extends CostFunction {
864864
void init(Cluster cluster) {
865865
super.init(cluster);
866866
cost.prepare(cluster.numServers);
867-
cost.setCosts(costs -> {
867+
cost.applyCostsChange(costs -> {
868868
for (int i = 0; i < cluster.numServers; i++) {
869869
costs[i] = cluster.regionsPerServer[i].length;
870870
}
@@ -886,7 +886,7 @@ protected double cost() {
886886

887887
@Override
888888
protected void regionMoved(int region, int oldServer, int newServer) {
889-
cost.setCosts(costs -> {
889+
cost.applyCostsChange(costs -> {
890890
costs[oldServer] = cluster.regionsPerServer[oldServer].length;
891891
costs[newServer] = cluster.regionsPerServer[newServer].length;
892892
});
@@ -928,7 +928,7 @@ void init(Cluster cluster) {
928928
return;
929929
}
930930
cost.prepare(cluster.numServers);
931-
cost.setCosts(costs -> {
931+
cost.applyCostsChange(costs -> {
932932
for (int i = 0; i < costs.length; i++) {
933933
costs[i] = computeCostForRegionServer(i);
934934
}
@@ -942,7 +942,7 @@ boolean isNeeded() {
942942

943943
@Override
944944
protected void regionMoved(int region, int oldServer, int newServer) {
945-
cost.setCosts(costs -> {
945+
cost.applyCostsChange(costs -> {
946946
costs[oldServer] = computeCostForRegionServer(oldServer);
947947
costs[newServer] = computeCostForRegionServer(newServer);
948948
});
@@ -1110,7 +1110,7 @@ private double computeCostForRegionServer(int regionServerIndex) {
11101110
void init(Cluster cluster) {
11111111
super.init(cluster);
11121112
cost.prepare(cluster.numServers);
1113-
cost.setCosts(costs -> {
1113+
cost.applyCostsChange(costs -> {
11141114
for (int i = 0; i < costs.length; i++) {
11151115
costs[i] = computeCostForRegionServer(i);
11161116
}
@@ -1120,7 +1120,7 @@ void init(Cluster cluster) {
11201120
@Override
11211121
protected void regionMoved(int region, int oldServer, int newServer) {
11221122
// recompute the stat for the given two region servers
1123-
cost.setCosts(costs -> {
1123+
cost.applyCostsChange(costs -> {
11241124
costs[oldServer] = computeCostForRegionServer(oldServer);
11251125
costs[newServer] = computeCostForRegionServer(newServer);
11261126
});

hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestDoubleArrayCost.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public void testComputeCost() {
3838
DoubleArrayCost cost = new DoubleArrayCost();
3939

4040
cost.prepare(100);
41-
cost.setCosts(costs -> {
41+
cost.applyCostsChange(costs -> {
4242
for (int i = 0; i < 100; i++) {
4343
costs[i] = 10;
4444
}
4545
});
4646
assertEquals(0, cost.cost(), 0.01);
4747

4848
cost.prepare(101);
49-
cost.setCosts(costs -> {
49+
cost.applyCostsChange(costs -> {
5050
for (int i = 0; i < 100; i++) {
5151
costs[i] = 0;
5252
}
@@ -55,7 +55,7 @@ public void testComputeCost() {
5555
assertEquals(1, cost.cost(), 0.01);
5656

5757
cost.prepare(200);
58-
cost.setCosts(costs -> {
58+
cost.applyCostsChange(costs -> {
5959
for (int i = 0; i < 100; i++) {
6060
costs[i] = 0;
6161
costs[i + 100] = 100;

0 commit comments

Comments
 (0)