HBASE-25995 Change the method name for DoubleArrayCost.setCosts (#3381)

Signed-off-by: Yulin Niu <niuyulin@apache.org>
This commit is contained in:
Duo Zhang 2021-06-15 11:53:00 +08:00 committed by GitHub
parent e551cd6b60
commit 480b6bb637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 10 deletions

View File

@ -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);
});

View File

@ -43,7 +43,16 @@ final class DoubleArrayCost {
}
}
void setCosts(Consumer<double[]> 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.
* <p/>
* 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<double[]> consumer) {
consumer.accept(costs);
costsChanged = true;
}

View File

@ -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);
});

View File

@ -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;
});

View File

@ -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;