diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2019-05-01 17:17:35 -0400 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2019-05-20 11:34:23 -0400 |
commit | 1c9d985ab77b53a5cdaa755515b0bd0fb24fa1e0 (patch) | |
tree | 2704d31ba07a112bd66b5d113b989180b0f7a511 /src/mongo/db/commands/distinct.cpp | |
parent | 90dd9f8983183cb3cb6f7b4a9dfc16ce972655fe (diff) | |
download | mongo-1c9d985ab77b53a5cdaa755515b0bd0fb24fa1e0.tar.gz |
SERVER-40026 Don't allow distinct on sharded collections in multi document transactions
Diffstat (limited to 'src/mongo/db/commands/distinct.cpp')
-rw-r--r-- | src/mongo/db/commands/distinct.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp index 1679ea78656..59d86a5acf6 100644 --- a/src/mongo/db/commands/distinct.cpp +++ b/src/mongo/db/commands/distinct.cpp @@ -53,6 +53,8 @@ #include "mongo/db/query/plan_summary_stats.h" #include "mongo/db/query/query_planner_common.h" #include "mongo/db/query/view_response_formatter.h" +#include "mongo/db/s/collection_sharding_state.h" +#include "mongo/db/transaction_participant.h" #include "mongo/db/views/resolved_view.h" #include "mongo/stdx/memory.h" #include "mongo/util/log.h" @@ -180,6 +182,14 @@ public: AutoGetCollection::ViewMode::kViewsPermitted); const auto& nss = ctx->getNss(); + // Distinct doesn't filter orphan documents so it is not allowed to run on sharded + // collections in multi-document transactions. + auto txnParticipant = TransactionParticipant::get(opCtx); + uassert(ErrorCodes::OperationNotSupportedInTransaction, + "Cannot run 'distinct' on a sharded collection in a multi-document transaction.", + !txnParticipant || !txnParticipant.inMultiDocumentTransaction() || + !CollectionShardingState::get(opCtx, nss)->getCurrentMetadata()->isSharded()); + const ExtensionsCallbackReal extensionsCallback(opCtx, &nss); auto defaultCollation = ctx->getCollection() ? ctx->getCollection()->getDefaultCollator() : nullptr; |