summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@10gen.com>2018-05-29 13:11:59 -0400
committerMatthew Russotto <matthew.russotto@10gen.com>2018-05-31 17:21:11 -0400
commit5a7d11513368a65014eaf387afdf76d4f48aa4ac (patch)
tree3b424fc94f8e86eb495be71955b23b2681f24507 /src
parent630487d850427ee41994128d41aaa19abd84cb12 (diff)
downloadmongo-5a7d11513368a65014eaf387afdf76d4f48aa4ac.tar.gz
SERVER-34170 Ensure transactions fail when run against a 3.6 node through the shell.
(cherry picked from commit 718bb7807cb371749160d216e454ef653f8e2112)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/shell/session.js31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/mongo/shell/session.js b/src/mongo/shell/session.js
index 1bb02347e70..dd7b09c0c97 100644
--- a/src/mongo/shell/session.js
+++ b/src/mongo/shell/session.js
@@ -83,11 +83,12 @@ var {
};
}
- function SessionAwareClient(client) {
- const kWireVersionSupportingCausalConsistency = 6;
- const kWireVersionSupportingLogicalSession = 6;
- const kWireVersionSupportingRetryableWrites = 6;
+ const kWireVersionSupportingCausalConsistency = 6;
+ const kWireVersionSupportingLogicalSession = 6;
+ const kWireVersionSupportingRetryableWrites = 6;
+ const kWireVersionSupportingMultiDocumentTransactions = 7;
+ function SessionAwareClient(client) {
this.getReadPreference = function getReadPreference(driverSession) {
const sessionOptions = driverSession.getOptions();
if (sessionOptions.getReadPreference() !== undefined) {
@@ -269,8 +270,14 @@ var {
}
// If startTransaction was called on the session, attach txn number and readConcern.
- // TODO: SERVER-34170 guard this code with a wire version check.
if (driverSession._serverSession.isInActiveTransaction()) {
+ // If we reconnect to a 3.6 server in the middle of a transaction, we
+ // catch it here.
+ if (!serverSupports(kWireVersionSupportingMultiDocumentTransactions)) {
+ driverSession._serverSession._abortTransactionOnClientOnly();
+ throw new Error(
+ "Transactions are only supported on server versions 4.0 and greater.");
+ }
cmdObj = driverSession._serverSession.assignTxnInfo(cmdObj);
}
@@ -706,6 +713,14 @@ var {
if (this.isInActiveTransaction()) {
throw new Error("Transaction already in progress on this session.");
}
+ function serverSupports(wireVersion) {
+ return client.getMinWireVersion() <= wireVersion &&
+ wireVersion <= client.getMaxWireVersion();
+ }
+ if (!serverSupports(kWireVersionSupportingMultiDocumentTransactions)) {
+ throw new Error(
+ "Transactions are only supported on server versions 4.0 and greater.");
+ }
_txnOptions = new TransactionOptions(txnOptsObj);
_txnState = ServerSession.TransactionStates.kActive;
_nextStatementId = 0;
@@ -730,6 +745,12 @@ var {
return endTransaction("abortTransaction", driverSession);
};
+ // This is used to abort transactions if we've reconnected to a non-transaction-supporting
+ // server.
+ this._abortTransactionOnClientOnly = function _abortTransactionOnClientOnly() {
+ _txnState = ServerSession.TransactionStates.kInactive;
+ };
+
const endTransaction = (commandName, driverSession) => {
// If commitTransaction or abortTransaction is the first statement in a
// transaction, it should not send a command to the server and should mark the