diff --git a/src/java/voldemort/client/rebalance/RebalanceController.java b/src/java/voldemort/client/rebalance/RebalanceController.java index 7c781e57c9..983ae9b66a 100644 --- a/src/java/voldemort/client/rebalance/RebalanceController.java +++ b/src/java/voldemort/client/rebalance/RebalanceController.java @@ -696,7 +696,7 @@ public class Scheduler { } public void run(List sbTaskList) { - // Setup for this run. + // Setup mapping of stealers to work for this run. this.tasksByStealer = new HashMap>(); for(StealerBasedRebalanceTask task: sbTaskList) { if(task.getStealInfos().size() != 1) { @@ -715,6 +715,14 @@ public void run(List sbTaskList) { return; } + // Shuffle order of each stealer's work list. This randomization + // helps to get rid of any "patterns" in how rebalancing tasks were + // added to the task list passed in. + for(List taskList: tasksByStealer.values()) { + Collections.shuffle(taskList); + } + + // Prepare to execute the rebalance this.numTasksExecuting = 0; this.nodeIdsWithWork = new HashSet(); doneSignal = new CountDownLatch(sbTaskList.size()); @@ -747,11 +755,9 @@ private synchronized StealerBasedRebalanceTask scheduleNextTask() { return null; } - // Should probably round-robin among stealerIds. But, its easier to - // randomly shuffle list of stealer IDs each time a new task to - // schedule needs to be found. In theory, either round-robin'ing or - // shuffling will avoid prioritizing one specific stealers work - // ahead of all others. + // Shuffle list of stealer IDs each time a new task to schedule + // needs to be found. Randomizing the order should avoid + // prioritizing one specific stealer's work ahead of all others. List stealerIds = new ArrayList(tasksByStealer.keySet()); Collections.shuffle(stealerIds); for(int stealerId: stealerIds) {