diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2016-11-09 09:03:44 -0500 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2016-11-09 09:03:44 -0500 |
commit | 6359f80037d38c3d342543822550d7350aa91ee7 (patch) | |
tree | df2fa59e925a3deec8c3e285ea1e59091aeaade5 | |
parent | 30cc39f613de9b025ba950ae59fc446bd3c978e1 (diff) | |
download | mongo-6359f80037d38c3d342543822550d7350aa91ee7.tar.gz |
SERVER-26261 Expose current() and advance() methods on version iterator.
-rw-r--r-- | buildscripts/resmokeconfig/suites/multiversion.yml | 3 | ||||
-rw-r--r-- | src/mongo/shell/servers.js | 44 | ||||
-rw-r--r-- | src/mongo/shell/shardingtest.js | 76 |
3 files changed, 77 insertions, 46 deletions
diff --git a/buildscripts/resmokeconfig/suites/multiversion.yml b/buildscripts/resmokeconfig/suites/multiversion.yml index c97b6fc8d98..95c81adcc12 100644 --- a/buildscripts/resmokeconfig/suites/multiversion.yml +++ b/buildscripts/resmokeconfig/suites/multiversion.yml @@ -8,9 +8,6 @@ selector: - jstests/multiVersion/transitioning_to_and_from_WT.js # TODO: SERVER-21578 - jstests/multiVersion/balancer_multiVersion_detect.js - # TODO: SERVER-26261 - - jstests/multiVersion/2_test_launching_cluster.js - - jstests/multiVersion/dumprestore_sharded.js # Multiversion tests start their own mongod's. executor: diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js index 7b7ee8dbbdf..078f63fb56e 100644 --- a/src/mongo/shell/servers.js +++ b/src/mongo/shell/servers.js @@ -118,10 +118,8 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro ]; MongoRunner.getBinVersionFor = function(version) { - - // If this is a version iterator, iterate the version via toString() if (version instanceof MongoRunner.versionIterator.iterator) { - version = version.toString(); + version = version.current(); } if (version == null) @@ -227,11 +225,11 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro MongoRunner.toRealFile = MongoRunner.toRealDir; /** - * Returns an iterator object which yields successive versions on toString(), starting from a - * random initial position, from an array of versions. + * Returns an iterator object which yields successive versions on calls to advance(), starting + * from a random initial position, from an array of versions. * * If passed a single version string or an already-existing version iterator, just returns the - * object itself, since it will yield correctly on toString() + * object itself, since it will yield correctly on calls to advance(). * * @param {Array.<String>}|{String}|{versionIterator} */ @@ -253,12 +251,21 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro }; MongoRunner.versionIterator.iterator = function(i, arr) { + if (!Array.isArray(arr)) { + throw new Error("Expected an array for the second argument, but got: " + tojson(arr)); + } + + this.current = function current() { + return arr[i]; + }; - this.toString = function() { - i = i % arr.length; - print("Returning next version : " + i + " (" + arr[i] + ") from " + tojson(arr) + - "..."); - return arr[i++]; + // We define the toString() method as an alias for current() so that concatenating a version + // iterator with a string returns the next version in the list without introducing any + // side-effects. + this.toString = this.current; + + this.advance = function advance() { + i = (i + 1) % arr.length; }; this.isVersionIterator = true; @@ -428,6 +435,13 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro // Normalize and get the binary version to use if (opts.hasOwnProperty('binVersion')) { + if (opts.binVersion instanceof MongoRunner.versionIterator.iterator) { + // Advance the version iterator so that subsequent calls to + // MongoRunner.mongoOptions() use the next version in the list. + const iterator = opts.binVersion; + opts.binVersion = iterator.current(); + iterator.advance(); + } opts.binVersion = MongoRunner.getBinVersionFor(opts.binVersion); } @@ -874,7 +888,15 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro MongoRunner.runMongoTool = function(binaryName, opts, ...positionalArgs) { var opts = opts || {}; + // Normalize and get the binary version to use + if (opts.binVersion instanceof MongoRunner.versionIterator.iterator) { + // Advance the version iterator so that subsequent calls to MongoRunner.runMongoTool() + // use the next version in the list. + const iterator = opts.binVersion; + opts.binVersion = iterator.current(); + iterator.advance(); + } opts.binVersion = MongoRunner.getBinVersionFor(opts.binVersion); // Recent versions of the mongo tools support a --dialTimeout flag to set for how diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js index c9314aea8b8..ec1f60eb869 100644 --- a/src/mongo/shell/shardingtest.js +++ b/src/mongo/shell/shardingtest.js @@ -781,9 +781,6 @@ var ShardingTest = function(params) { // If the mongos is being restarted with a newer version, make sure we remove any // options that no longer exist in the newer version. - // Note: If a jstest specifies the mongos binVersion as an array, calling - // MongoRunner.areBinVersionsTheSame() will advance the binVersion iterator over that - // array (SERVER-26261). if (MongoRunner.areBinVersionsTheSame('latest', opts.binVersion)) { delete opts.noAutoSplit; } @@ -1240,6 +1237,40 @@ var ShardingTest = function(params) { // Wait for master to be elected before starting mongos var csrsPrimary = this.configRS.getPrimary(); + // If 'otherParams.mongosOptions.binVersion' is an array value, then we'll end up constructing a + // version iterator. We initialize the options for the mongos processes before checking whether + // we need to run {setFeatureCompatibilityVersion: "3.2"} on the CSRS primary so we know + // definitively what binVersions will be used for the mongos processes. + const mongosOptions = []; + for (var i = 0; i < numMongos; ++i) { + let options = { + useHostname: otherParams.useHostname, + pathOpts: Object.merge(pathOpts, {mongos: i}), + verbose: mongosVerboseLevel, + keyFile: keyFile, + }; + + if (otherParams.mongosOptions && otherParams.mongosOptions.binVersion) { + otherParams.mongosOptions.binVersion = + MongoRunner.versionIterator(otherParams.mongosOptions.binVersion); + } + + options = Object.merge(options, otherParams.mongosOptions); + options = Object.merge(options, otherParams["s" + i]); + + options.port = options.port || allocatePort(); + + // TODO(esha): remove after v3.4 ships. + // Legacy mongoses use a command line option to disable autosplit instead of reading the + // config.settings collection. + if (options.binVersion && MongoRunner.areBinVersionsTheSame('3.2', options.binVersion) && + !otherParams.enableAutoSplit) { + options.noAutoSplit = ""; + } + + mongosOptions.push(options); + } + /** * Helper method to check whether we should set featureCompatibilityVersion to 3.2 on the CSRS. * We do this if we have a 3.2 shard or a 3.2 mongos and a 3.4 CSRS because older versions of @@ -1285,7 +1316,14 @@ var ShardingTest = function(params) { const configRS = this.configRS; if (shouldSetFeatureCompatibilityVersion32()) { function setFeatureCompatibilityVersion() { - assert.commandWorked(csrsPrimary.adminCommand({setFeatureCompatibilityVersion: '3.2'})); + const res = csrsPrimary.adminCommand({setFeatureCompatibilityVersion: '3.2'}); + if (res.ok === 0) { + // The "setFeatureCompatibilityVersion" command is unrecognized by versions of + // MongoDB earlier than 3.4. + assert.commandFailedWithCode(res, ErrorCodes.CommandNotFound); + return; + } + assert.commandWorked(res); // We wait for setting the featureCompatibilityVersion to "3.2" to propagate to all // nodes in the CSRS to ensure that older versions of mongos can successfully connect. @@ -1335,34 +1373,8 @@ var ShardingTest = function(params) { // Start the MongoS servers for (var i = 0; i < numMongos; i++) { - options = { - useHostname: otherParams.useHostname, - pathOpts: Object.merge(pathOpts, {mongos: i}), - configdb: this._configDB, - verbose: mongosVerboseLevel, - keyFile: keyFile, - }; - - if (otherParams.mongosOptions && otherParams.mongosOptions.binVersion) { - otherParams.mongosOptions.binVersion = - MongoRunner.versionIterator(otherParams.mongosOptions.binVersion); - } - - options = Object.merge(options, otherParams.mongosOptions); - options = Object.merge(options, otherParams["s" + i]); - - options.port = options.port || allocatePort(); - - // TODO(esha): remove after v3.4 ships. - // Legacy mongoses use a command line option to disable autosplit instead of reading the - // config.settings collection. - // Note: If a jstest specifies the mongos binVersion as an array, calling - // MongoRunner.areBinVersionsTheSame() will advance the binVersion iterator over that array - // (SERVER-26261). - if (options.binVersion && MongoRunner.areBinVersionsTheSame('3.2', options.binVersion) && - !otherParams.enableAutoSplit) { - options.noAutoSplit = ""; - } + const options = mongosOptions[i]; + options.configdb = this._configDB; if (otherParams.useBridge) { var bridgeOptions = |