diff options
author | Jason Carey <jcarey@argv.me> | 2017-11-02 15:06:54 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2017-11-09 18:35:00 -0500 |
commit | bf53cbe298bc6724b1f2b5bf16afbd9e3876c623 (patch) | |
tree | e09009ab740b9d3d15c48b1b9a3ec09c2086637b | |
parent | c3c736d3f2755e7e8b59638fd94cb000265abdf3 (diff) | |
download | mongo-bf53cbe298bc6724b1f2b5bf16afbd9e3876c623.tar.gz |
SERVER-31777 deactivate logical sessions for fcv34
For anything less than fully upgraded to 3.6:
* suppress logicalSessionTimeoutMinutes in isMaster
* fail any commands that passes lsid
9 files changed, 50 insertions, 21 deletions
diff --git a/jstests/concurrency/fsm_all_sharded_causal_consistency.js b/jstests/concurrency/fsm_all_sharded_causal_consistency.js index 1d2f8617d4c..8b5a8208592 100644 --- a/jstests/concurrency/fsm_all_sharded_causal_consistency.js +++ b/jstests/concurrency/fsm_all_sharded_causal_consistency.js @@ -85,6 +85,8 @@ var blacklist = [ 'rename_collection_dbname_droptarget.js', 'rename_collection_droptarget.js', + 'toggle_feature_compatibility.js', // Sets FCV to 3.4, which will cause session use to fail + 'update_simple_eval.js', // eval doesn't work with sharded collections 'update_simple_eval_nolock.js', // eval doesn't work with sharded collections 'update_upsert_multi.js', // our update queries lack shard keys diff --git a/jstests/concurrency/fsm_all_sharded_causal_consistency_and_balancer.js b/jstests/concurrency/fsm_all_sharded_causal_consistency_and_balancer.js index 7ee65f861bf..66a109e1c21 100644 --- a/jstests/concurrency/fsm_all_sharded_causal_consistency_and_balancer.js +++ b/jstests/concurrency/fsm_all_sharded_causal_consistency_and_balancer.js @@ -91,6 +91,8 @@ var blacklist = [ 'rename_collection_dbname_droptarget.js', 'rename_collection_droptarget.js', + 'toggle_feature_compatibility.js', // Sets FCV to 3.4, which will cause session use to fail + 'update_simple_eval.js', // eval doesn't work with sharded collections 'update_simple_eval_nolock.js', // eval doesn't work with sharded collections 'update_upsert_multi.js', // our update queries lack shard keys diff --git a/jstests/libs/override_methods/enable_sessions.js b/jstests/libs/override_methods/enable_sessions.js index 9e4954013a0..ebb78f703c3 100644 --- a/jstests/libs/override_methods/enable_sessions.js +++ b/jstests/libs/override_methods/enable_sessions.js @@ -43,6 +43,10 @@ // Override the runCommand to check for any command obj that does not contain a logical session // and throw an error. function runCommandWithLsidCheck(conn, dbName, cmdObj, func, funcArgs) { + if (jsTest.options().disableEnableSessions) { + return func.apply(conn, funcArgs); + } + const cmdName = Object.keys(cmdObj)[0]; // If the command is in a wrapped form, then we look for the actual command object @@ -77,6 +81,10 @@ // to cache the session for each connection instance so we can retrieve the same session on // subsequent calls to getDB. Mongo.prototype.getDB = function(dbName) { + if (jsTest.options().disableEnableSessions) { + return getDBOriginal.apply(this, arguments); + } + if (!sessionMap.has(this)) { const session = startSession(this); sessionMap.set(this, session); diff --git a/jstests/multiVersion/shell_retryable_writes_downgrade.js b/jstests/multiVersion/shell_retryable_writes_downgrade.js index 652d33c0ddc..854b468913e 100644 --- a/jstests/multiVersion/shell_retryable_writes_downgrade.js +++ b/jstests/multiVersion/shell_retryable_writes_downgrade.js @@ -78,12 +78,9 @@ assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: "3.4"})); - // The server continues to accept lsid and txnNumber while in featureCompatibilityVersion=3.4. - // - // TODO SERVER-31777: The server should return an error if an lsid or txnNumber is specified - // while in featureCompatibilityVersion=3.4. + // The server errors on lsid and txnNumber while in featureCompatibilityVersion=3.4. testCommandCanBeRetried(function() { - assert.writeOK(coll.insert({_id: "while fCV=3.4"})); + assert.writeError(coll.insert({_id: "while fCV=3.4"})); }); rst.restart(primary, {binVersion: "3.4"}); @@ -110,11 +107,9 @@ // When upgrading to MongoDB 3.6 but running as a stand-alone server, the mongo shell should // still assign a transaction number to its write requests (per the Driver's specification). - // - // TODO SERVER-31777: The server should return an error if an lsid or txnNumber is specified - // while in featureCompatibilityVersion=3.4. testCommandCanBeRetried(function() { - assert.writeOK(coll.insert({_id: "while binVersion=3.6 as stand-alone and reconnected"})); + assert.writeError( + coll.insert({_id: "while binVersion=3.6 as stand-alone and reconnected"})); }); db.getSession().endSession(); diff --git a/jstests/noPassthrough/logical_session_feature_compatibility.js b/jstests/noPassthrough/logical_session_feature_compatibility.js index 20ccfe483cf..e4384940f4b 100644 --- a/jstests/noPassthrough/logical_session_feature_compatibility.js +++ b/jstests/noPassthrough/logical_session_feature_compatibility.js @@ -51,6 +51,14 @@ " under featureCompatibilityVersion 3.4"); } } + + const isMasterResult = admin.runCommand({isMaster: 1}); + assert.commandWorked(isMasterResult); + assert.eq(!errorCode, + isMasterResult.hasOwnProperty("logicalSessionTimeoutMinutes"), + "failed test that we " + (errorCode ? "don't " : "") + + "have logicalSessionTimeoutMinutes under featureCompatibilityVersion " + + compatibilityVersion); }; // First verify the commands without auth, in feature compatibility version 3.6. @@ -90,18 +98,21 @@ assert.commandWorked(admin.adminCommand({setFeatureCompatibilityVersion: "3.6"})); for (var i = 0; i < 11; i++) { - admin.runCommand({"insert": "test", "documents": [{a: 1}], "lsid": {"id": UUID()}}); + assert.commandWorked( + admin.runCommand({"insert": "test", "documents": [{a: 1}], "lsid": {"id": UUID()}})); } - admin.adminCommand({setFeatureCompatibilityVersion: "3.4"}); + assert.commandWorked(admin.adminCommand({setFeatureCompatibilityVersion: "3.4"})); for (var i = 0; i < 13; i++) { - admin.runCommand({"insert": "test", "documents": [{a: 2}], "lsid": {"id": UUID()}}); + assert.commandFailedWithCode( + admin.runCommand({"insert": "test", "documents": [{a: 2}], "lsid": {"id": UUID()}}), + ErrorCodes.InvalidOptions); } - admin.adminCommand({setFeatureCompatibilityVersion: "3.6"}); + assert.commandWorked(admin.adminCommand({setFeatureCompatibilityVersion: "3.6"})); - admin.runCommand({refreshLogicalSessionCacheNow: 1}); + assert.commandWorked(admin.runCommand({refreshLogicalSessionCacheNow: 1})); assert.eq(config.system.sessions.find().count(), 11); diff --git a/src/mongo/db/initialize_operation_session_info.cpp b/src/mongo/db/initialize_operation_session_info.cpp index 87003e8cc80..8ed477c17a3 100644 --- a/src/mongo/db/initialize_operation_session_info.cpp +++ b/src/mongo/db/initialize_operation_session_info.cpp @@ -31,6 +31,7 @@ #include "mongo/db/initialize_operation_session_info.h" #include "mongo/db/auth/authorization_session.h" +#include "mongo/db/commands/feature_compatibility_version.h" #include "mongo/db/logical_session_cache.h" #include "mongo/db/logical_session_id_helpers.h" #include "mongo/db/operation_context.h" @@ -46,11 +47,6 @@ void initializeOperationSessionInfo(OperationContext* opCtx, return; } - if (serverGlobalParams.featureCompatibility.getVersion() != - ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36) { - return; - } - { // If we're using the localhost bypass, logical sessions are disabled AuthorizationSession* authSession = AuthorizationSession::get(opCtx->getClient()); @@ -62,6 +58,14 @@ void initializeOperationSessionInfo(OperationContext* opCtx, auto osi = OperationSessionInfoFromClient::parse("OperationSessionInfo"_sd, requestBody); if (osi.getSessionId()) { + uassert(ErrorCodes::InvalidOptions, + str::stream() << "cannot pass logical session id unless fully upgraded to " + "featureCompatibilityVersion 3.4. See " + << feature_compatibility_version::kDochubLink + << " .", + serverGlobalParams.featureCompatibility.getVersion() == + ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36); + stdx::lock_guard<Client> lk(*opCtx->getClient()); opCtx->setLogicalSessionId(makeLogicalSessionId(osi.getSessionId().get(), opCtx)); diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index 7729eaccda3..76388589f95 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -362,7 +362,10 @@ public: result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes); result.appendNumber("maxWriteBatchSize", write_ops::kMaxWriteBatchSize); result.appendDate("localTime", jsTime()); - result.append("logicalSessionTimeoutMinutes", localLogicalSessionTimeoutMinutes); + if (serverGlobalParams.featureCompatibility.getVersion() == + ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36) { + result.append("logicalSessionTimeoutMinutes", localLogicalSessionTimeoutMinutes); + } if (internalClientElement) { result.append("minWireVersion", diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp index c8180d2e539..fa4d556d922 100644 --- a/src/mongo/s/commands/cluster_is_master_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp @@ -112,7 +112,10 @@ public: result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes); result.appendNumber("maxWriteBatchSize", write_ops::kMaxWriteBatchSize); result.appendDate("localTime", jsTime()); - result.append("logicalSessionTimeoutMinutes", localLogicalSessionTimeoutMinutes); + if (serverGlobalParams.featureCompatibility.getVersion() == + ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36) { + result.append("logicalSessionTimeoutMinutes", localLogicalSessionTimeoutMinutes); + } // Mongos tries to keep exactly the same version range of the server for which // it is compiled. diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index 359a543075c..638580ebf3c 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -260,6 +260,7 @@ jsTestOptions = function() { excludedDBsFromDBHash: TestData.excludedDBsFromDBHash, alwaysInjectTransactionNumber: TestData.alwaysInjectTransactionNumber, skipGossipingClusterTime: TestData.skipGossipingClusterTime || false, + disableEnableSessions: TestData.disableEnableSessions, }); } return _jsTestOptions; |