summaryrefslogtreecommitdiff
path: root/src/mongo/executor/hedged_async_rpc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/executor/hedged_async_rpc.h')
-rw-r--r--src/mongo/executor/hedged_async_rpc.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/executor/hedged_async_rpc.h b/src/mongo/executor/hedged_async_rpc.h
index 6ab98cb9b59..15868c390db 100644
--- a/src/mongo/executor/hedged_async_rpc.h
+++ b/src/mongo/executor/hedged_async_rpc.h
@@ -226,6 +226,7 @@ SemiFuture<AsyncRPCResponse<typename CommandType::Reply>> sendHedgedCommand(
});
}
+ const auto globalMaxTimeMSForHedgedReads = gMaxTimeMSForHedgedReads.load();
for (size_t i = 0; i < hostsToTarget; i++) {
std::unique_ptr<Targeter> t = std::make_unique<FixedTargeter>(targets[i]);
// We explicitly pass "NeverRetryPolicy" here because the retry mechanism
@@ -237,6 +238,22 @@ SemiFuture<AsyncRPCResponse<typename CommandType::Reply>> sendHedgedCommand(
hedgeCancellationToken.token(),
std::make_shared<NeverRetryPolicy>(),
genericArgs);
+
+ // If the request is a hedged request, set maxTimeMSOpOnly to the smaller of
+ // the server parameter maxTimeMSForHedgedReads or remaining max time from the
+ // opCtx.
+ if (opts.isHedgeEnabled && i != 0) {
+ auto maxTimeMSOpOnly = globalMaxTimeMSForHedgedReads;
+ if (opCtx->hasDeadline()) {
+ if (auto remainingMaxTime = opCtx->getRemainingMaxTimeMillis().count();
+ remainingMaxTime < maxTimeMSOpOnly) {
+ maxTimeMSOpOnly = remainingMaxTime;
+ }
+ }
+
+ options->genericArgs.unstable.setMaxTimeMSOpOnly(maxTimeMSOpOnly);
+ }
+
options->baton = baton;
requests.push_back(
sendCommand(options, opCtx, std::move(t)).thenRunOn(proxyExec));