summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
authorHugh Tong <hugh.tong@mongodb.com>2023-05-12 00:12:49 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-12 02:20:31 +0000
commit7a494b24bf306a620794069d3b3ea3d794209978 (patch)
tree461257e637de6aedabedd75e9afed41bdb69be35 /src/mongo/db/commands
parent91d9967910ed5d2257074dfe3362b0b317a26cff (diff)
downloadmongo-7a494b24bf306a620794069d3b3ea3d794209978.tar.gz
SERVER-76582 Pass correct SerializationContext objs into command replies
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/current_op.cpp6
-rw-r--r--src/mongo/db/commands/dbcommands.cpp15
-rw-r--r--src/mongo/db/commands/find_cmd.cpp8
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp11
-rw-r--r--src/mongo/db/commands/list_collections.cpp27
-rw-r--r--src/mongo/db/commands/list_databases.cpp4
-rw-r--r--src/mongo/db/commands/list_indexes.cpp21
-rw-r--r--src/mongo/db/commands/pipeline_command.cpp3
8 files changed, 73 insertions, 22 deletions
diff --git a/src/mongo/db/commands/current_op.cpp b/src/mongo/db/commands/current_op.cpp
index 8ba08e6c37b..dd888b36db8 100644
--- a/src/mongo/db/commands/current_op.cpp
+++ b/src/mongo/db/commands/current_op.cpp
@@ -96,8 +96,12 @@ public:
CommandHelpers::appendSimpleCommandStatus(bodyBuilder, true);
bodyBuilder.doneFast();
+ // We need to copy the serialization context from the request to the reply object
return CursorResponse::parseFromBSON(
- replyBuilder.releaseBody(), nullptr, request.getNamespace().tenantId());
+ replyBuilder.releaseBody(),
+ nullptr,
+ request.getNamespace().tenantId(),
+ SerializationContext::stateCommandReply(request.getSerializationContext()));
}
virtual void appendToResponse(BSONObjBuilder* result) const final {
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index 147df508a9c..ba74cea6106 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -220,7 +220,9 @@ public:
!storageEngine->supportsRecoveryTimestamp());
}
- Reply reply;
+ // We need to copy the serialization context from the request to the reply object
+ Reply reply(
+ SerializationContext::stateCommandReply(request().getSerializationContext()));
uassertStatusOK(
dropCollection(opCtx,
request().getNamespace(),
@@ -457,7 +459,13 @@ public:
uassert(ErrorCodes::OperationFailed, "No collection name specified", !nss.coll().empty());
- result.append("ns", NamespaceStringUtil::serialize(nss));
+ // We need to use the serialization context from the request when calling
+ // NamespaceStringUtil to build the reply
+ result.append(
+ "ns",
+ NamespaceStringUtil::serialize(
+ nss, SerializationContext::stateCommandReply(cmd.getSerializationContext())));
+
auto spec = StorageStatsSpec::parse(IDLParserContext("collStats"), cmdObj);
Status status = appendCollectionStorageStats(opCtx, nss, spec, &result);
if (!status.isOK() && (status.code() != ErrorCodes::NamespaceNotFound)) {
@@ -640,7 +648,8 @@ public:
AutoGetDb autoDb(opCtx, dbname, MODE_IS);
Database* db = autoDb.getDb();
- Reply reply;
+ // We need to copy the serialization context from the request to the reply object
+ Reply reply(SerializationContext::stateCommandReply(cmd.getSerializationContext()));
reply.setDB(dbname.db());
if (!db) {
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index 2b6d5cb9dc8..2c261b751b2 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -571,6 +571,10 @@ public:
}
}
+ // We need to copy the serialization context from the request to the reply object before
+ // the request object goes out of scope
+ const auto serializationContext = cq->getFindCommandRequest().getSerializationContext();
+
// Get the execution plan for the query.
bool permitYield = true;
auto exec =
@@ -726,8 +730,8 @@ public:
// documents.
auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx);
metricsCollector.incrementDocUnitsReturned(nss.ns(), docUnitsReturned);
- query_request_helper::validateCursorResponse(result->getBodyBuilder().asTempObj(),
- nss.tenantId());
+ query_request_helper::validateCursorResponse(
+ result->getBodyBuilder().asTempObj(), nss.tenantId(), serializationContext);
}
void appendMirrorableRequest(BSONObjBuilder* bob) const override {
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index 28a3d8fb43b..8f91862d002 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -797,9 +797,14 @@ public:
void validateResult(rpc::ReplyBuilderInterface* reply, boost::optional<TenantId> tenantId) {
auto ret = reply->getBodyBuilder().asTempObj();
- CursorGetMoreReply::parse(
- IDLParserContext{"CursorGetMoreReply", false /* apiStrict */, tenantId},
- ret.removeField("ok"));
+
+ // We need to copy the serialization context from the request to the reply object
+ CursorGetMoreReply::parse(IDLParserContext("CursorGetMoreReply",
+ false /* apiStrict */,
+ tenantId,
+ SerializationContext::stateCommandReply(
+ _cmd.getSerializationContext())),
+ ret.removeField("ok"));
}
const GetMoreCommandRequest _cmd;
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index 571c3156786..f332d975201 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -255,9 +255,14 @@ BSONObj buildCollectionBson(OperationContext* opCtx,
ListCollectionsReply createListCollectionsCursorReply(
CursorId cursorId,
const NamespaceString& cursorNss,
+ const SerializationContext& serializationContext,
std::vector<mongo::ListCollectionsReplyItem>&& firstBatch) {
return ListCollectionsReply(
- ListCollectionsReplyCursor(cursorId, cursorNss, std::move(firstBatch)));
+ ListCollectionsReplyCursor(cursorId,
+ cursorNss,
+ std::move(firstBatch),
+ SerializationContext::stateCommandReply(serializationContext)),
+ SerializationContext::stateCommandReply(serializationContext));
}
class CmdListCollections : public ListCollectionsCmdVersion1Gen<CmdListCollections> {
@@ -316,6 +321,9 @@ public:
const bool nameOnly = listCollRequest.getNameOnly();
const bool authorizedCollections = listCollRequest.getAuthorizedCollections();
+ // We need to copy the serialization context from the request to the reply object
+ const auto serializationContext = listCollRequest.getSerializationContext();
+
// The collator is null because collection objects are compared using binary comparison.
auto expCtx = make_intrusive<ExpressionContext>(
opCtx, std::unique_ptr<CollatorInterface>(nullptr), ns());
@@ -520,10 +528,11 @@ public:
try {
firstBatch.push_back(ListCollectionsReplyItem::parse(
- IDLParserContext("ListCollectionsReplyItem",
- false /* apiStrict*/,
- cursorNss.tenantId(),
- SerializationContext::stateCommandReply()),
+ IDLParserContext(
+ "ListCollectionsReplyItem",
+ false /* apiStrict*/,
+ cursorNss.tenantId(),
+ SerializationContext::stateCommandReply(serializationContext)),
nextDoc));
} catch (const DBException& exc) {
LOGV2_ERROR(
@@ -537,7 +546,7 @@ public:
}
if (exec->isEOF()) {
return createListCollectionsCursorReply(
- 0 /* cursorId */, cursorNss, std::move(firstBatch));
+ 0 /* cursorId */, cursorNss, serializationContext, std::move(firstBatch));
}
exec->saveState();
exec->detachFromOperationContext();
@@ -560,8 +569,10 @@ public:
pinnedCursor->incNBatches();
pinnedCursor->incNReturnedSoFar(firstBatch.size());
- return createListCollectionsCursorReply(
- pinnedCursor.getCursor()->cursorid(), cursorNss, std::move(firstBatch));
+ return createListCollectionsCursorReply(pinnedCursor.getCursor()->cursorid(),
+ cursorNss,
+ serializationContext,
+ std::move(firstBatch));
}
};
} cmdListCollections;
diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp
index 3ad19b1d236..2f07229b1cd 100644
--- a/src/mongo/db/commands/list_databases.cpp
+++ b/src/mongo/db/commands/list_databases.cpp
@@ -135,7 +135,9 @@ public:
false /* setTenantId */,
authorizedDatabases);
- ListDatabasesReply reply(items);
+ // We need to copy the serialization context from the request to the reply object
+ ListDatabasesReply reply(
+ items, SerializationContext::stateCommandReply(cmd.getSerializationContext()));
if (!nameOnly) {
reply.setTotalSize(totalSize);
reply.setTotalSizeMb(totalSize / (1024 * 1024));
diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp
index 951d1f6e4a4..848fbb896c8 100644
--- a/src/mongo/db/commands/list_indexes.cpp
+++ b/src/mongo/db/commands/list_indexes.cpp
@@ -285,6 +285,9 @@ public:
const NamespaceString& nss) {
auto& cmd = request();
+ // We need to copy the serialization context from the request to the reply object
+ const auto serializationContext = cmd.getSerializationContext();
+
long long batchSize = std::numeric_limits<long long>::max();
if (cmd.getCursor() && cmd.getCursor()->getBatchSize()) {
batchSize = *cmd.getCursor()->getBatchSize();
@@ -335,7 +338,12 @@ public:
try {
firstBatch.push_back(ListIndexesReplyItem::parse(
- IDLParserContext("ListIndexesReplyItem"), nextDoc));
+ IDLParserContext(
+ "ListIndexesReplyItem",
+ false /* apiStrict */,
+ nss.tenantId(),
+ SerializationContext::stateCommandReply(serializationContext)),
+ nextDoc));
} catch (const DBException& exc) {
LOGV2_ERROR(5254500,
"Could not parse catalog entry while replying to listIndexes",
@@ -351,7 +359,11 @@ public:
}
if (exec->isEOF()) {
- return ListIndexesReplyCursor(0 /* cursorId */, nss, std::move(firstBatch));
+ return ListIndexesReplyCursor(
+ 0 /* cursorId */,
+ nss,
+ std::move(firstBatch),
+ SerializationContext::stateCommandReply(serializationContext));
}
exec->saveState();
@@ -374,7 +386,10 @@ public:
pinnedCursor->incNReturnedSoFar(firstBatch.size());
return ListIndexesReplyCursor(
- pinnedCursor.getCursor()->cursorid(), nss, std::move(firstBatch));
+ pinnedCursor.getCursor()->cursorid(),
+ nss,
+ std::move(firstBatch),
+ SerializationContext::stateCommandReply(serializationContext));
}
};
} cmdListIndexes;
diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp
index 337c3e5b067..20eab15b603 100644
--- a/src/mongo/db/commands/pipeline_command.cpp
+++ b/src/mongo/db/commands/pipeline_command.cpp
@@ -230,7 +230,8 @@ public:
if (!_aggregationRequest.getExplain() && !_aggregationRequest.getExchange()) {
query_request_helper::validateCursorResponse(
reply->getBodyBuilder().asTempObj(),
- _aggregationRequest.getNamespace().tenantId());
+ _aggregationRequest.getNamespace().tenantId(),
+ _aggregationRequest.getSerializationContext());
}
}