From ca7c12950c02b623373ad8fa9a2a3c666285d062 Mon Sep 17 00:00:00 2001 From: Tommaso Tocci Date: Tue, 14 Apr 2020 14:23:59 +0200 Subject: [PATCH] SERVER-47522 Distinct command: Convert usage of getCollectionDescription_DEPRECATED to getCollectionDescription --- jstests/core/txns/view_reads_in_transaction.js | 14 +++++--------- src/mongo/db/commands/distinct.cpp | 15 +++++++-------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/jstests/core/txns/view_reads_in_transaction.js b/jstests/core/txns/view_reads_in_transaction.js index 5a1a08761b8..a132de35ff6 100644 --- a/jstests/core/txns/view_reads_in_transaction.js +++ b/jstests/core/txns/view_reads_in_transaction.js @@ -21,18 +21,14 @@ assert.commandWorked(coll.insert(testDoc, {writeConcern: {w: "majority"}})); assert.commandWorked(view.runCommand( "create", {viewOn: coll.getName(), pipeline: [], writeConcern: {w: "majority"}})); -const isMongos = assert.commandWorked(db.runCommand("ismaster")).msg === "isdbgrid"; -if (isMongos) { - // Refresh the router's and shard's database versions so the distinct run below can succeed. - // This is necessary because shards always abort their local transaction on stale version - // errors and mongos is not allowed to retry on these errors in a transaction if the stale - // shard has completed at least one earlier statement. - assert.eq(view.distinct("_id"), ["kyle"]); -} - // Run a dummy find to start the transaction. jsTestLog("Starting transaction."); session.startTransaction({readConcern: {level: "snapshot"}}); +// Refresh the router's and shard's database versions so the distinct run below can succeed. +// This is necessary because shards always abort their local transaction on stale version +// errors and mongos is not allowed to retry on these errors in a transaction if the stale +// shard has completed at least one earlier statement. +assert.eq(view.distinct("_id"), ["kyle"]); let cursor = coll.find(); cursor.next(); diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp index b299482cf47..b18b56c2ec1 100644 --- a/src/mongo/db/commands/distinct.cpp +++ b/src/mongo/db/commands/distinct.cpp @@ -191,14 +191,13 @@ public: // Distinct doesn't filter orphan documents so it is not allowed to run on sharded // collections in multi-document transactions. - uassert(ErrorCodes::OperationNotSupportedInTransaction, - "Cannot run 'distinct' on a sharded collection in a multi-document transaction. " - "Please see http://dochub.mongodb.org/core/transaction-distinct for a recommended " - "alternative.", - !opCtx->inMultiDocumentTransaction() || - !CollectionShardingState::get(opCtx, nss) - ->getCollectionDescription_DEPRECATED() - .isSharded()); + uassert( + ErrorCodes::OperationNotSupportedInTransaction, + "Cannot run 'distinct' on a sharded collection in a multi-document transaction. " + "Please see http://dochub.mongodb.org/core/transaction-distinct for a recommended " + "alternative.", + !opCtx->inMultiDocumentTransaction() || + !CollectionShardingState::get(opCtx, nss)->getCollectionDescription().isSharded()); const ExtensionsCallbackReal extensionsCallback(opCtx, &nss); auto defaultCollation =