diff --git a/fdbserver/DDTeamCollection.actor.cpp b/fdbserver/DDTeamCollection.actor.cpp index 46eea173b5..7ad73f17ff 100644 --- a/fdbserver/DDTeamCollection.actor.cpp +++ b/fdbserver/DDTeamCollection.actor.cpp @@ -5667,21 +5667,20 @@ public: state int teamSize = 1; state std::unique_ptr collection = testTeamCollection(teamSize, policy, processSize); - - int64_t capacity = 1000 * 1024 * 1024, available = 800*1024*1024; + int64_t capacity = 1000 * 1024 * 1024, available = 800 * 1024 * 1024; std::vector read_bandwidths{ - 100 * 1024 * 1024, 300 * 1024 * 1024, 500 * 1024 * 1024, 700 * 1024 * 1024, 900 * 1024 * 1024 + 300 * 1024 * 1024, 100 * 1024 * 1024, 500 * 1024 * 1024, 100 * 1024 * 1024, 900 * 1024 * 1024 }; std::vector load_bytes{ - 50 * 1024 * 1024, 200 * 1024 * 1024, 400 * 1024 * 1024, 600 * 1024 * 1024, 800 * 1024 * 1024 + 50 * 1024 * 1024, 600 * 1024 * 1024, 800 * 1024 * 1024, 200 * 1024 * 1024, 100 * 1024 * 1024 }; GetStorageMetricsReply metrics[5]; for (int i = 0; i < 5; ++i) { metrics[i].capacity.bytes = capacity; metrics[i].available.bytes = available; metrics[i].load.bytesReadPerKSecond = read_bandwidths[i]; - metrics[i].load.bytes = deterministicRandom()->randomChoice(load_bytes); - collection->addTeam(std::set({ UID(i + 1, 0) }), true); + metrics[i].load.bytes = load_bytes[i]; + collection->addTeam(std::set({ UID(i + 1, 0) }), IsInitialTeam::True); collection->server_info[UID(i + 1, 0)]->setMetrics(metrics[i]); } @@ -5697,16 +5696,19 @@ public: state GetTeamRequest req(wantsNewServers, wantsTrueBest, preferLowerUtilization, teamMustHaveShards); req.completeSources = completeSources; req.teamSorter = [](Reference a, Reference b) { - return a->getLoadReadBandwidth() > b->getLoadReadBandwidth(); + auto r1 = a->getLoadReadBandwidth(), r2 = b->getLoadReadBandwidth(); + return r1 == r2 ? 0 : (r1 > r2 ? -1 : 1); }; wait(collection->getTeam(req)); std::pair>, bool> resTeam = req.reply.getFuture().get(); - std::set expectedServers{ UID(1, 0) }; + std::set expectedServers{ UID(4, 0) }; ASSERT(resTeam.first.present()); auto servers = resTeam.first.get()->getServerIDs(); const std::set selectedServers(servers.begin(), servers.end()); + // for (auto id : selectedServers) + // std::cout << id.toString() << std::endl; ASSERT(expectedServers == selectedServers); return Void(); @@ -5824,7 +5826,7 @@ TEST_CASE("/DataDistribution/GetTeam/ServerUtilizationNearCutoff") { return Void(); } TEST_CASE("/DataDistribution/GetTeam/TrueBestLeastReadBandwidth") { - Optional res = wait(timeout(recurringFuture(DDTeamCollectionUnitTest::GetTeam_TrueBestLeastReadBandwidth(), 0.1), 10)); + wait(DDTeamCollectionUnitTest::GetTeam_TrueBestLeastReadBandwidth()); return Void(); } diff --git a/fdbserver/DataDistribution.actor.h b/fdbserver/DataDistribution.actor.h index 0c7ddc972f..fed968c9b1 100644 --- a/fdbserver/DataDistribution.actor.h +++ b/fdbserver/DataDistribution.actor.h @@ -93,8 +93,8 @@ struct GetTeamRequest { // optional typedef Reference TeamRef; std::function hardConstraint; - std::function - teamSorter; // => true if a.score < b.score, the reply will choose the largest one + std::function + teamSorter; // => -1 if a.score < b.score, 0 if equal, 1 if larger, the reply will choose the largest one GetTeamRequest() {} GetTeamRequest(bool wantsNewServers, @@ -107,10 +107,11 @@ struct GetTeamRequest { // return true if a.score < b.score [[nodiscard]] bool lessCompare(TeamRef a, TeamRef b, int64_t aLoadBytes, int64_t bLoadBytes) const { + int res = 0; if (teamSorter) { - return teamSorter(a, b); + res = teamSorter(a, b); } - return lessCompareByLoad(aLoadBytes, bLoadBytes); + return res == 0 ? lessCompareByLoad(aLoadBytes, bLoadBytes) : res < 0; } // return true if preferHigherUtil && aLoadBytes <= bLoadBytes (higher load bytes has larger score) diff --git a/fdbserver/DataDistributionQueue.actor.cpp b/fdbserver/DataDistributionQueue.actor.cpp index 7f19a12786..3105e6d303 100644 --- a/fdbserver/DataDistributionQueue.actor.cpp +++ b/fdbserver/DataDistributionQueue.actor.cpp @@ -1035,14 +1035,16 @@ struct DDQueueData { } }; -// return true if a.readload > b.readload -bool greaterReadLoad(Reference a, Reference b) { - return a->getLoadReadBandwidth() > b->getLoadReadBandwidth(); +// return -1 if a.readload > b.readload +int greaterReadLoad(Reference a, Reference b) { + auto r1 = a->getLoadReadBandwidth(), r2 = b->getLoadReadBandwidth(); + return r1 == r2 ? 0 : (r1 > r2 ? -1 : 1); } -// return true if a.readload < b.readload -bool lessReadLoad(Reference a, Reference b) { - return a->getLoadReadBandwidth() < b->getLoadReadBandwidth(); +// return -1 if a.readload < b.readload +int lessReadLoad(Reference a, Reference b) { + auto r1 = a->getLoadReadBandwidth(), r2 = b->getLoadReadBandwidth(); + return r1 == r2 ? 0 : (r1 < r2 ? -1 : 1); } static std::string destServersString(std::vector, bool>> const& bestTeams) { diff --git a/flow/genericactors.actor.h b/flow/genericactors.actor.h index 33199f1753..f4772eec7e 100644 --- a/flow/genericactors.actor.h +++ b/flow/genericactors.actor.h @@ -229,7 +229,9 @@ Future recurring(Func what, double interval, TaskPriority taskID = TaskPri } // run what every interval sec -ACTOR Future recurringFuture(Future what, double interval, TaskPriority taskID = TaskPriority::DefaultDelay); +ACTOR Future recurringFuture(Future what, + double interval, + TaskPriority taskID = TaskPriority::DefaultDelay); ACTOR template Future trigger(Func what, Future signal) {