Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ protected List<RegionPlan> balanceTable(TableName tableName,
BalancerClusterState cluster = createState(loadOfOneTable, loads, finder, rackManager);

long startTime = EnvironmentEdgeManager.currentTime();
cluster.setStopRequestedAt(startTime + maxRunningTime);

initCosts(cluster);
balancerConditionals.loadClusterState(cluster);
Expand Down Expand Up @@ -636,6 +635,7 @@ protected List<RegionPlan> balanceTable(TableName tableName,
currentCost / sumMultiplier, functionCost(), computedMaxSteps);

final String initFunctionTotalCosts = totalCostsPerFunc();
cluster.setStopRequestedAt(EnvironmentEdgeManager.currentTime() + maxRunningTime);
// Perform a stochastic walk to see if we can get a good fit.
long step;
boolean planImprovedConditionals = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -44,6 +45,7 @@
import org.apache.hadoop.hbase.Size;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.master.RackManager;
import org.apache.hadoop.hbase.master.RegionPlan;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
Expand Down Expand Up @@ -496,6 +498,42 @@ public void testCostAfterUndoAction() {
}
}

@Test
public void testSearchDeadlineIsSetAfterInitialization() throws Exception {
Configuration testConf = new Configuration(conf);
testConf.setInt(StochasticLoadBalancer.MAX_STEPS_KEY, 0);
boolean[] needsBalanceCalled = { false };
boolean[] deadlineSet = { false };
StochasticLoadBalancer balancer =
new StochasticLoadBalancer(new DummyMetricsStochasticBalancer()) {
@Override
protected BalancerClusterState createState(Map<ServerName, List<RegionInfo>> clusterState,
Map<String, Deque<BalancerRegionLoad>> loads, RegionHDFSBlockLocationFinder finder,
RackManager rackManager) {
return new BalancerClusterState(clusterState, loads, finder, rackManager) {
@Override
void setStopRequestedAt(long stopRequestedAt) {
deadlineSet[0] = true;
assertTrue(needsBalanceCalled[0]);
super.setStopRequestedAt(stopRequestedAt);
}
};
}

@Override
boolean needsBalance(TableName tableName, BalancerClusterState cluster) {
needsBalanceCalled[0] = true;
return true;
}
};
balancer.setClusterInfoProvider(new DummyClusterInfoProvider(testConf));
balancer.initialize();

balancer.balanceTable(HConstants.ENSEMBLE_TABLE_NAME, createServerMap(2, 2, 1, 1, 1));

assertTrue(deadlineSet[0]);
}

@Test
public void testTableSkewCost() {
Configuration conf = HBaseConfiguration.create();
Expand Down