From b9d8a47872050ca5fe6c1b95fcb0534e6e0ebc3d Mon Sep 17 00:00:00 2001 From: Mindaugas Malinauskas Date: Tue, 4 Apr 2023 18:27:25 +0000 Subject: SERVER-66715 Add tenant lock --- src/mongo/db/commands/run_aggregate.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/mongo/db/commands/run_aggregate.cpp') diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index c2f2701cd42..e08e6b09e30 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -795,19 +795,15 @@ Status runAggregate(OperationContext* opCtx, nss = NamespaceString::kRsOplogNamespace; // In case of serverless the change stream will be opened on the change collection. - if (change_stream_serverless_helpers::isChangeCollectionsModeActive()) { + const bool changeCollectionsMode = + change_stream_serverless_helpers::isChangeCollectionsModeActive(); + if (changeCollectionsMode) { const auto tenantId = change_stream_serverless_helpers::resolveTenantId(origNss.tenantId()); uassert(ErrorCodes::BadValue, "Change streams cannot be used without tenant id", tenantId); - - uassert(ErrorCodes::ChangeStreamNotEnabled, - "Change streams must be enabled before being used.", - change_stream_serverless_helpers::isChangeStreamEnabled(opCtx, *tenantId)); - - nss = NamespaceString::makeChangeCollectionNSS(tenantId); } @@ -846,6 +842,11 @@ Status runAggregate(OperationContext* opCtx, // Obtain collection locks on the execution namespace; that is, the oplog. initContext(auto_get_collection::ViewMode::kViewsForbidden); registerTelemetry(); + uassert(ErrorCodes::ChangeStreamNotEnabled, + "Change streams must be enabled before being used", + !changeCollectionsMode || + change_stream_serverless_helpers::isChangeStreamEnabled(opCtx, + *nss.tenantId())); } else if (nss.isCollectionlessAggregateNS() && pipelineInvolvedNamespaces.empty()) { uassert(4928901, str::stream() << AggregateCommandRequest::kCollectionUUIDFieldName -- cgit v1.2.1