From d7356df2aa547518bced0b23db493101092b7f5f Mon Sep 17 00:00:00 2001 From: Jay J Wylie Date: Mon, 24 Jun 2013 08:47:07 -0700 Subject: [PATCH] Tweak new rebalance scheduler Randomized the order of rebalance tasks in each stealer's list. This will avoid biasing the rebalance based on the order tasks were generated. --- .../client/rebalance/RebalanceController.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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) {