summaryrefslogtreecommitdiff
path: root/src/mongo/s/hedge_options_util.cpp
diff options
context:
space:
mode:
authorCheahuychou Mao <cheahuychou.mao@mongodb.com>2020-03-10 11:12:35 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-10 19:34:41 +0000
commitdc895c373b8e48113ce7505595b05011dd02f6e4 (patch)
tree42d4bf5a0a70dfaf08bdc1d6f1ed40e44b31d8a3 /src/mongo/s/hedge_options_util.cpp
parent45eab9f82a18613b877598a951dc7b95f85f2059 (diff)
downloadmongo-dc895c373b8e48113ce7505595b05011dd02f6e4.tar.gz
SERVER-46646 Disallow hedging for commands that can potentially do writes
Diffstat (limited to 'src/mongo/s/hedge_options_util.cpp')
-rw-r--r--src/mongo/s/hedge_options_util.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/mongo/s/hedge_options_util.cpp b/src/mongo/s/hedge_options_util.cpp
index e1a77e4abf5..ce6e8ecc4b2 100644
--- a/src/mongo/s/hedge_options_util.cpp
+++ b/src/mongo/s/hedge_options_util.cpp
@@ -33,14 +33,33 @@
namespace mongo {
+namespace {
+// Only hedge commands that cannot trigger writes.
+const std::set<std::string> supportedCmds{"collStats",
+ "count",
+ "dataSize",
+ "dbStats",
+ "distinct",
+ "filemd5",
+ "find",
+ "listCollections",
+ "listIndexes",
+ "planCacheListFilters"};
+} // namespace
+
boost::optional<executor::RemoteCommandRequestOnAny::HedgeOptions> extractHedgeOptions(
- const ReadPreferenceSetting& readPref) {
- if (gReadHedgingMode.load() == ReadHedgingMode::kOn && readPref.hedgingMode &&
- readPref.hedgingMode->getEnabled()) {
+ const BSONObj& cmdObj, const ReadPreferenceSetting& readPref) {
+ if (!(gReadHedgingMode.load() == ReadHedgingMode::kOn && readPref.hedgingMode &&
+ readPref.hedgingMode->getEnabled())) {
+ return boost::none;
+ }
+
+ auto cmdName(cmdObj.firstElement().fieldNameStringData().toString());
+
+ if (supportedCmds.count(cmdName)) {
return executor::RemoteCommandRequestOnAny::HedgeOptions{1,
gMaxTimeMSForHedgedReads.load()};
}
-
return boost::none;
}