summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/commands/cluster_explain_cmd.cpp7
-rw-r--r--src/mongo/s/commands/strategy.cpp11
-rw-r--r--src/mongo/s/query/cluster_find.cpp6
3 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/s/commands/cluster_explain_cmd.cpp b/src/mongo/s/commands/cluster_explain_cmd.cpp
index 09882eeb642..3736947d113 100644
--- a/src/mongo/s/commands/cluster_explain_cmd.cpp
+++ b/src/mongo/s/commands/cluster_explain_cmd.cpp
@@ -176,6 +176,13 @@ std::unique_ptr<CommandInvocation> ClusterExplainCmd::parse(OperationContext* op
// arguments into the inner command since it is what is passed to the virtual
// CommandInvocation::explain() method.
const BSONObj explainedObj = makeExplainedObj(cmdObj, dbName);
+
+ // Extract 'comment' field from the 'explainedObj' only if there is no top-level comment.
+ auto commentField = explainedObj["comment"];
+ if (!opCtx->getComment() && commentField) {
+ opCtx->setComment(commentField.wrap());
+ }
+
const std::string cmdName = explainedObj.firstElementFieldName();
auto explainedCommand = CommandHelpers::findCommand(cmdName);
uassert(ErrorCodes::CommandNotFound,
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp
index 5949128fe88..802a1d69ab2 100644
--- a/src/mongo/s/commands/strategy.cpp
+++ b/src/mongo/s/commands/strategy.cpp
@@ -365,6 +365,11 @@ void runCommand(OperationContext* opCtx,
}
opCtx->checkForInterrupt(); // May trigger maxTimeAlwaysTimeOut fail point.
+ // If the command includes a 'comment' field, set it on the current OpCtx.
+ if (auto commentField = request.body["comment"]) {
+ opCtx->setComment(commentField.wrap());
+ }
+
auto invocation = command->parse(opCtx, request);
// Set the logical optype, command object and namespace as soon as we identify the command. If
@@ -634,6 +639,12 @@ DbResponse Strategy::queryOp(OperationContext* opCtx, const NamespaceString& nss
Client* const client = opCtx->getClient();
AuthorizationSession* const authSession = AuthorizationSession::get(client);
+ // The legacy '$comment' operator gets converted to 'comment' by upconvertQueryEntry(). We
+ // set the comment in 'opCtx' so that it can be passed on to the respective shards.
+ if (auto commentField = upconvertedQuery["comment"]) {
+ opCtx->setComment(commentField.wrap());
+ }
+
Status status = authSession->checkAuthForFind(nss, false);
audit::logQueryAuthzCheck(client, nss, q.query, status.code());
uassertStatusOK(status);
diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp
index e697d32f150..69fe465d4cb 100644
--- a/src/mongo/s/query/cluster_find.cpp
+++ b/src/mongo/s/query/cluster_find.cpp
@@ -371,6 +371,12 @@ Status setUpOperationContextStateForGetMore(OperationContext* opCtx,
ReadPreferenceSetting::get(opCtx) = *readPref;
}
+ // If the originating command had a 'comment' field, we extract it and set it on opCtx. Note
+ // that if the 'getMore' command itself has a 'comment' field, we give precedence to it.
+ auto comment = cursor->getOriginatingCommand()["comment"];
+ if (!opCtx->getComment() && comment) {
+ opCtx->setComment(comment.wrap());
+ }
if (cursor->isTailableAndAwaitData()) {
// For tailable + awaitData cursors, the request may have indicated a maximum amount of time
// to wait for new data. If not, default it to 1 second. We track the deadline instead via