diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2019-05-24 16:28:51 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2019-05-24 18:38:29 -0400 |
commit | c237f4c53b6a4ff04762c6aeabf56cd26552d8e8 (patch) | |
tree | 7dfa70102a66c8af9697cb2bc0a8901025c6bbc1 | |
parent | 0855ca379139f59a73276c0d2b24e9c47147b897 (diff) | |
download | mongo-c237f4c53b6a4ff04762c6aeabf56cd26552d8e8.tar.gz |
SERVER-41312 Ban internalReadAtClusterTime in transactions
-rw-r--r-- | jstests/replsets/read_at_cluster_time_outside_transactions.js | 25 | ||||
-rw-r--r-- | src/mongo/db/commands/find_cmd.cpp | 6 |
2 files changed, 30 insertions, 1 deletions
diff --git a/jstests/replsets/read_at_cluster_time_outside_transactions.js b/jstests/replsets/read_at_cluster_time_outside_transactions.js index 1d507962dc6..af0bbf9cf4f 100644 --- a/jstests/replsets/read_at_cluster_time_outside_transactions.js +++ b/jstests/replsets/read_at_cluster_time_outside_transactions.js @@ -2,7 +2,7 @@ * Tests that the "find" and "dbHash" commands support reading at a Timestamp by using the * $_internalReadAtClusterTime option. * - * @tags: [requires_document_locking] + * @tags: [requires_document_locking, uses_transactions] */ (function() { "use strict"; @@ -111,6 +111,29 @@ }), ErrorCodes.InvalidOptions); + // $_internalReadAtClusterTime is not supported in transactions. + const session = primary.startSession(); + const sessionDB = session.getDatabase("test"); + const sessionColl = sessionDB[collName]; + + session.startTransaction(); + assert.commandFailedWithCode(sessionColl.runCommand("find", { + batchSize: 2, + sort: {_id: 1}, + $_internalReadAtClusterTime: clusterTime, + }), + ErrorCodes.OperationNotSupportedInTransaction); + assert.commandFailedWithCode(session.abortTransaction_forTesting(), + ErrorCodes.NoSuchTransaction); + + // dbHash is not supported in transactions at all. + session.startTransaction(); + assert.commandFailedWithCode( + sessionDB.runCommand({dbHash: 1, $_internalReadAtClusterTime: clusterTime}), + ErrorCodes.OperationNotSupportedInTransaction); + assert.commandFailedWithCode(session.abortTransaction_forTesting(), + ErrorCodes.NoSuchTransaction); + // Create a new collection to move the minimum visible snapshot to that operation time. Then // read at a cluster time behind the minimum visible snapshot which should fail. let newCollName = "newColl"; diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index 7e386af97c3..90ded58d209 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -286,6 +286,12 @@ public: " commands are enabled", !qr->getReadAtClusterTime() || getTestCommandsEnabled()); + uassert( + ErrorCodes::OperationNotSupportedInTransaction, + "The '$_internalReadAtClusterTime' option is not supported within a transaction.", + !txnParticipant || !txnParticipant.inActiveOrKilledMultiDocumentTransaction() || + !qr->getReadAtClusterTime()); + uassert(ErrorCodes::InvalidOptions, "The '$_internalReadAtClusterTime' option is only supported when replication is" " enabled", |