From de919c7f051405676f09f0d2632afa4ea39a43a3 Mon Sep 17 00:00:00 2001 From: David Hall Date: Mon, 18 Sep 2017 12:45:41 -0500 Subject: [PATCH] MCOL-786 Redistribute: Round robin target dbroots --- .../we_redistributecontrolthread.cpp | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/writeengine/redistribute/we_redistributecontrolthread.cpp b/writeengine/redistribute/we_redistributecontrolthread.cpp index 652b48565..afefac369 100644 --- a/writeengine/redistribute/we_redistributecontrolthread.cpp +++ b/writeengine/redistribute/we_redistributecontrolthread.cpp @@ -393,6 +393,14 @@ int RedistributeControlThread::makeRedistributePlan() // It's possible that a source that is "removed" on the command line is not empty. // This can happen if a partition exists on all dbroots. + // WCOL-786: use nextDbroot to start the loop looking for a suitible target + // where we left off with the previous partition. This gives each target + // an opportunity to get some of the data. In the case of dbroot removal, + // there is often the same number of partitions on each remaining dbroot. + // This logic tends to roundrobin which dbroot gets the next batch. + set::iterator nextDbroot = targetDbroots.begin(); + set::iterator targetDbroot; + int targetCnt = (int)targetDbroots.size(); // Loop through the sources, looking for dbroots that are not targets that also still contain partitions for (set::iterator sourceDbroot = sourceDbroots.begin(); sourceDbroot != sourceDbroots.end(); @@ -416,15 +424,22 @@ int RedistributeControlThread::makeRedistributePlan() // the partition. uint64_t partCount = std::numeric_limits::max(); int tdbroot = 0; - for (set::iterator targetDbroot = targetDbroots.begin(); - targetDbroot != targetDbroots.end(); - ++targetDbroot) + targetDbroot = nextDbroot; + // MCOL-786. Start at targetDbroot and loop around back to the same spot. + for (int tbd=0; tbd < targetCnt; ++tbd) { + if (targetDbroot == targetDbroots.end()) + { + targetDbroot == targetDbroots.begin(); + } if (dbPartVec[*targetDbroot].size() < partCount) { tdbroot = *targetDbroot; partCount = dbPartVec[*targetDbroot].size(); + nextDbroot = targetDbroot; + ++nextDbroot; } + ++targetDbroot; } if (tdbroot == 0) {