-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
Fully Compatible
-
ALL
-
Service Arch 2022-10-03
During the extensive code review for SERVER-66260, an opportunity on how to improve Sharding's extractHedgeOptions was identified. The suggestion looks theoretically sound, what is left to this ticket is to assess its correctness through the various test suites and its performance impact.
Here's billy.donahue@mongodb.com 's suggestion
namespace { // Only do hedging for commands that cannot trigger writes. // Keep this list sorted. static constexpr std::array hedgeCommands{ "collStats"_sd, "count"_sd, "dataSize"_sd, "dbStats"_sd, "distinct"_sd, "filemd5"_sd, "find"_sd, "listCollections"_sd, "listIndexes"_sd, "planCacheListFilters"_sd, }; static const bool verifySortOrderOnStartup = [] { invariant(std::is_sorted(hedgeCommands.begin(), hedgeCommands.end())); return true; }(); bool commandCanHedge(StringData command) { return std::binary_search(hedgeCommands.begin(), hedgeCommands.end(), command); } } // namespace void extractHedgeOptions(const BSONObj& cmdObj, const ReadPreferenceSetting& readPref, executor::RemoteCommandRequestOnAny::Options& options) { const bool canHedge = [&] { if (gReadHedgingMode.load() != ReadHedgingMode::kOn) return false; // Hedging is globally disabled. auto&& mode = readPref.hedgingMode; if (!mode || !mode->getEnabled()) return false; // The read preference didn't enable hedging. auto cmdName = cmdObj.firstElement().fieldNameStringData(); if (!commandCanHedge(cmdName)) return false; // This is not a command that can hedge. return true; }(); options.isHedgeEnabled = canHedge; options.hedgeCount = canHedge ? 1 : 0; options.maxTimeMSForHedgedReads = canHedge ? gMaxTimeMSForHedgedReads.load() : 0; }
- depends on
-
SERVER-66764 Polyfill C++20 constexpr isSorted
- Closed