diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2018-05-18 17:34:06 -0400 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2018-06-13 11:43:45 -0400 |
commit | 8817328f87564a29e9be2ed1a746cf40e89587eb (patch) | |
tree | 1cae922e5cc0faf5b82cf914d2432e93e246ef55 /src/mongo/shell/mongo.js | |
parent | 9a7b88779fd519bd955daa106d5d19244fe4072d (diff) | |
download | mongo-8817328f87564a29e9be2ed1a746cf40e89587eb.tar.gz |
SERVER-32064 Requests from the shell should use an implicit session by default
Diffstat (limited to 'src/mongo/shell/mongo.js')
-rw-r--r-- | src/mongo/shell/mongo.js | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js index bfb1e04f7cf..0a78e9db761 100644 --- a/src/mongo/shell/mongo.js +++ b/src/mongo/shell/mongo.js @@ -58,7 +58,9 @@ Mongo.prototype.getDB = function(name) { Mongo.prototype.getDBs = function(driverSession = this._getDefaultSession()) { var cmdObj = {listDatabases: 1}; - cmdObj = driverSession._serverSession.injectSessionId(cmdObj); + if (driverSession._isExplicit || !jsTest.options().disableImplicitSessions) { + cmdObj = driverSession._serverSession.injectSessionId(cmdObj); + } var res = this.adminCommand(cmdObj); if (!res.ok) @@ -75,7 +77,9 @@ Mongo.prototype.adminCommand = function(cmd) { */ Mongo.prototype.getLogComponents = function(driverSession = this._getDefaultSession()) { var cmdObj = {getParameter: 1, logComponentVerbosity: 1}; - cmdObj = driverSession._serverSession.injectSessionId(cmdObj); + if (driverSession._isExplicit || !jsTest.options().disableImplicitSessions) { + cmdObj = driverSession._serverSession.injectSessionId(cmdObj); + } var res = this.adminCommand(cmdObj); if (!res.ok) @@ -106,7 +110,9 @@ Mongo.prototype.setLogLevel = function( } var cmdObj = {setParameter: 1, logComponentVerbosity: vDoc}; - cmdObj = driverSession._serverSession.injectSessionId(cmdObj); + if (driverSession._isExplicit || !jsTest.options().disableImplicitSessions) { + cmdObj = driverSession._serverSession.injectSessionId(cmdObj); + } var res = this.adminCommand(cmdObj); if (!res.ok) @@ -426,11 +432,14 @@ Mongo.prototype.startSession = function startSession(options = {}) { }; Mongo.prototype._getDefaultSession = function getDefaultSession() { - // We implicitly associate a Mongo connection object with a DriverSession so that tests which - // call DB.prototype.getMongo() and then Mongo.prototype.getDB() to get a different DB instance - // are still causally consistent. + // We implicitly associate a Mongo connection object with a real session so all requests include + // a logical session id. These implicit sessions are intentionally not causally consistent. If + // implicit sessions have been globally disabled, a dummy session is used instead of a real one. if (!this.hasOwnProperty("_defaultSession")) { - this._defaultSession = new _DummyDriverSession(this); + this._defaultSession = _shouldUseImplicitSessions() + ? this.startSession({causalConsistency: false}) + : new _DummyDriverSession(this); + this._defaultSession._isExplicit = false; } return this._defaultSession; }; |