HBASE-18480 The cost of BaseLoadBalancer.cluster is changed even if the rollback is done
This commit is contained in:
parent
3f540f3801
commit
b4f8377aa0
|
@ -805,6 +805,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
||||||
} else if (oldServer >= 0 && (numRegionsPerServerPerTable[oldServer][tableIndex] + 1)
|
} else if (oldServer >= 0 && (numRegionsPerServerPerTable[oldServer][tableIndex] + 1)
|
||||||
== numMaxRegionsPerTable[tableIndex]) {
|
== numMaxRegionsPerTable[tableIndex]) {
|
||||||
//recompute maxRegionsPerTable since the previous value was coming from the old server
|
//recompute maxRegionsPerTable since the previous value was coming from the old server
|
||||||
|
numMaxRegionsPerTable[tableIndex] = 0;
|
||||||
for (int serverIndex = 0 ; serverIndex < numRegionsPerServerPerTable.length; serverIndex++) {
|
for (int serverIndex = 0 ; serverIndex < numRegionsPerServerPerTable.length; serverIndex++) {
|
||||||
if (numRegionsPerServerPerTable[serverIndex][tableIndex] > numMaxRegionsPerTable[tableIndex]) {
|
if (numRegionsPerServerPerTable[serverIndex][tableIndex] > numMaxRegionsPerTable[tableIndex]) {
|
||||||
numMaxRegionsPerTable[tableIndex] = numRegionsPerServerPerTable[serverIndex][tableIndex];
|
numMaxRegionsPerTable[tableIndex] = numRegionsPerServerPerTable[serverIndex][tableIndex];
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.master.balancer;
|
package org.apache.hadoop.hbase.master.balancer;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -318,6 +319,12 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
return balanceCluster(clusterState);
|
return balanceCluster(clusterState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
Cluster.Action nextAction(Cluster cluster) {
|
||||||
|
return candidateGenerators.get(RANDOM.nextInt(candidateGenerators.size()))
|
||||||
|
.generate(cluster);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given the cluster state this will try and approach an optimal balance. This
|
* Given the cluster state this will try and approach an optimal balance. This
|
||||||
* should always approach the optimal state given enough steps.
|
* should always approach the optimal state given enough steps.
|
||||||
|
@ -384,9 +391,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
long step;
|
long step;
|
||||||
|
|
||||||
for (step = 0; step < computedMaxSteps; step++) {
|
for (step = 0; step < computedMaxSteps; step++) {
|
||||||
int generatorIdx = RANDOM.nextInt(candidateGenerators.size());
|
Cluster.Action action = nextAction(cluster);
|
||||||
CandidateGenerator p = candidateGenerators.get(generatorIdx);
|
|
||||||
Cluster.Action action = p.generate(cluster);
|
|
||||||
|
|
||||||
if (action.type == Type.NULL) {
|
if (action.type == Type.NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -280,6 +280,27 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
|
||||||
assertEquals(1, costFunction.cost(), 0.01);
|
assertEquals(1, costFunction.cost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCostAfterUndoAction() {
|
||||||
|
final int runs = 10;
|
||||||
|
loadBalancer.setConf(conf);
|
||||||
|
for (int[] mockCluster : clusterStateMocks) {
|
||||||
|
BaseLoadBalancer.Cluster cluster = mockCluster(mockCluster);
|
||||||
|
loadBalancer.initCosts(cluster);
|
||||||
|
for (int i = 0; i != runs; ++i) {
|
||||||
|
final double expectedCost = loadBalancer.computeCost(cluster, Double.MAX_VALUE);
|
||||||
|
Cluster.Action action = loadBalancer.nextAction(cluster);
|
||||||
|
cluster.doAction(action);
|
||||||
|
loadBalancer.updateCostsWithAction(cluster, action);
|
||||||
|
Cluster.Action undoAction = action.undoAction();
|
||||||
|
cluster.doAction(undoAction);
|
||||||
|
loadBalancer.updateCostsWithAction(cluster, undoAction);
|
||||||
|
final double actualCost = loadBalancer.computeCost(cluster, Double.MAX_VALUE);
|
||||||
|
assertEquals(expectedCost, actualCost, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTableSkewCost() {
|
public void testTableSkewCost() {
|
||||||
Configuration conf = HBaseConfiguration.create();
|
Configuration conf = HBaseConfiguration.create();
|
||||||
|
|
Loading…
Reference in New Issue