diff options
Diffstat (limited to 'jstests/multiVersion')
29 files changed, 1201 insertions, 1092 deletions
diff --git a/jstests/multiVersion/1_test_launching_replset.js b/jstests/multiVersion/1_test_launching_replset.js index af1bdf6b330..e9709b6dd2b 100644 --- a/jstests/multiVersion/1_test_launching_replset.js +++ b/jstests/multiVersion/1_test_launching_replset.js @@ -3,51 +3,50 @@ // // Check our latest versions -var versionsToCheck = [ "last-stable", - "latest" ]; +var versionsToCheck = ["last-stable", "latest"]; load('./jstests/multiVersion/libs/verify_versions.js'); -jsTest.log( "Testing legacy versions..." ); +jsTest.log("Testing legacy versions..."); -for( var i = 0; i < versionsToCheck.length; i++ ){ +for (var i = 0; i < versionsToCheck.length; i++) { + var version = versionsToCheck[i]; - var version = versionsToCheck[ i ]; - // Set up a replica set - - var rst = new ReplSetTest({ nodes : 2 }); - - rst.startSet({ binVersion : version }); - + + var rst = new ReplSetTest({nodes: 2}); + + rst.startSet({binVersion: version}); + var nodes = rst.nodes; - + // Make sure the started versions are actually the correct versions - for( var j = 0; j < nodes.length; j++ ) assert.binVersion(nodes[j], version); - + for (var j = 0; j < nodes.length; j++) + assert.binVersion(nodes[j], version); + rst.stopSet(); } -jsTest.log( "Testing mixed versions..." ); +jsTest.log("Testing mixed versions..."); // Set up a multi-version replica set -var rst = new ReplSetTest({ nodes : 2 }); +var rst = new ReplSetTest({nodes: 2}); -rst.startSet({ binVersion : versionsToCheck }); +rst.startSet({binVersion: versionsToCheck}); var nodes = rst.nodes; -//Make sure we have hosts of all the different versions +// Make sure we have hosts of all the different versions var versionsFound = []; -for( var j = 0; j < nodes.length; j++ ) +for (var j = 0; j < nodes.length; j++) versionsFound.push(nodes[j].getBinVersion()); assert.allBinVersions(versionsToCheck, versionsFound); rst.stopSet(); -jsTest.log( "Done!" ); +jsTest.log("Done!"); // // End diff --git a/jstests/multiVersion/2_test_launching_cluster.js b/jstests/multiVersion/2_test_launching_cluster.js index b8588ce530a..4ecc4431e8b 100644 --- a/jstests/multiVersion/2_test_launching_cluster.js +++ b/jstests/multiVersion/2_test_launching_cluster.js @@ -5,134 +5,140 @@ load('./jstests/multiVersion/libs/verify_versions.js'); (function() { -"use strict"; -// Check our latest versions -//var versionsToCheck = [ "last-stable", "latest" ]; -//var versionsToCheckMongos = [ "last-stable" ]; -// TODO put this back when SERVER-22761 is resolved - -var versionsToCheck = [ "latest" ]; -var versionsToCheckMongos = [ "latest" ]; - -jsTest.log( "Testing legacy versions..." ); - -for( var i = 0; i < versionsToCheck.length; i++ ){ - - var version = versionsToCheck[ i ]; - - // Set up a cluster - - var st = new ShardingTest({ shards : 2, - mongos : 2, - other : { - mongosOptions : { binVersion : version }, - configOptions : { binVersion : version }, - shardOptions : { binVersion : version } - } }); - - var shards = [ st.shard0, st.shard1 ]; - var mongoses = [ st.s0, st.s1 ]; - var configs = [ st.config0 ]; - - // Make sure the started versions are actually the correct versions - for( var j = 0; j < shards.length; j++ ) assert.binVersion( shards[j], version ); - for( j = 0; j < mongoses.length; j++ ) assert.binVersion( mongoses[j], version ); - for( j = 0; j < configs.length; j++ ) assert.binVersion( configs[j], version ); - + "use strict"; + // Check our latest versions + // var versionsToCheck = [ "last-stable", "latest" ]; + // var versionsToCheckMongos = [ "last-stable" ]; + // TODO put this back when SERVER-22761 is resolved + + var versionsToCheck = ["latest"]; + var versionsToCheckMongos = ["latest"]; + + jsTest.log("Testing legacy versions..."); + + for (var i = 0; i < versionsToCheck.length; i++) { + var version = versionsToCheck[i]; + + // Set up a cluster + + var st = new ShardingTest({ + shards: 2, + mongos: 2, + other: { + mongosOptions: {binVersion: version}, + configOptions: {binVersion: version}, + shardOptions: {binVersion: version} + } + }); + + var shards = [st.shard0, st.shard1]; + var mongoses = [st.s0, st.s1]; + var configs = [st.config0]; + + // Make sure the started versions are actually the correct versions + for (var j = 0; j < shards.length; j++) + assert.binVersion(shards[j], version); + for (j = 0; j < mongoses.length; j++) + assert.binVersion(mongoses[j], version); + for (j = 0; j < configs.length; j++) + assert.binVersion(configs[j], version); + + st.stop(); + } + + jsTest.log("Testing mixed versions..."); + + // Set up a multi-version cluster + + st = new ShardingTest({ + shards: 2, + mongos: 2, + other: { + mongosOptions: {binVersion: versionsToCheckMongos}, + configOptions: {binVersion: versionsToCheck}, + shardOptions: {binVersion: versionsToCheck} + + } + }); + + shards = [st.shard0, st.shard1]; + mongoses = [st.s0, st.s1]; + configs = [st.config0, st.config1, st.config2]; + + // Make sure we have hosts of all the different versions + var versionsFound = []; + for (j = 0; j < shards.length; j++) + versionsFound.push(shards[j].getBinVersion()); + + assert.allBinVersions(versionsToCheck, versionsFound); + + versionsFound = []; + for (j = 0; j < mongoses.length; j++) + versionsFound.push(mongoses[j].getBinVersion()); + + assert.allBinVersions(versionsToCheckMongos, versionsFound); + + versionsFound = []; + for (j = 0; j < configs.length; j++) + versionsFound.push(configs[j].getBinVersion()); + + assert.allBinVersions(versionsToCheck, versionsFound); + st.stop(); -} - -jsTest.log( "Testing mixed versions..." ); - -// Set up a multi-version cluster - -st = new ShardingTest({ shards : 2, - mongos : 2, - other : { - mongosOptions : { binVersion : versionsToCheckMongos }, - configOptions : { binVersion : versionsToCheck }, - shardOptions : { binVersion : versionsToCheck } - - } }); - -shards = [ st.shard0, st.shard1 ]; -mongoses = [ st.s0, st.s1 ]; -configs = [ st.config0, st.config1, st.config2 ]; - -// Make sure we have hosts of all the different versions -var versionsFound = []; -for ( j = 0; j < shards.length; j++ ) - versionsFound.push( shards[j].getBinVersion() ); - -assert.allBinVersions( versionsToCheck, versionsFound ); - -versionsFound = []; -for ( j = 0; j < mongoses.length; j++ ) - versionsFound.push( mongoses[j].getBinVersion() ); - -assert.allBinVersions( versionsToCheckMongos, versionsFound ); - -versionsFound = []; -for ( j = 0; j < configs.length; j++ ) - versionsFound.push( configs[j].getBinVersion() ); - -assert.allBinVersions( versionsToCheck, versionsFound ); - -st.stop(); - - -jsTest.log( "Testing mixed versions with replica sets..." ); - -// Set up a multi-version cluster w/ replica sets - -st = new ShardingTest({ shards : 2, - mongos : 2, - other : { - // Replica set shards - rs : true, - - mongosOptions : { binVersion : versionsToCheckMongos }, - configOptions : { binVersion : versionsToCheck }, - rsOptions : { binVersion : versionsToCheck, protocolVersion: 0 } - } }); - -var nodesA = st.rs0.nodes; -var nodesB = st.rs1.nodes; -mongoses = [ st.s0, st.s1 ]; -configs = [ st.config0, st.config1, st.config2 ]; - -var getVersion = function( mongo ){ - var result = mongo.getDB( "admin" ).runCommand({ serverStatus : 1 }); - return result.version; -}; - -// Make sure we have hosts of all the different versions -versionsFound = []; -for ( j = 0; j < nodesA.length; j++ ) - versionsFound.push( nodesA[j].getBinVersion() ); - -assert.allBinVersions( versionsToCheck, versionsFound ); - -versionsFound = []; -for ( j = 0; j < nodesB.length; j++ ) - versionsFound.push( nodesB[j].getBinVersion() ); - -assert.allBinVersions( versionsToCheck, versionsFound ); - -versionsFound = []; -for ( j = 0; j < mongoses.length; j++ ) - versionsFound.push( mongoses[j].getBinVersion() ); - -assert.allBinVersions( versionsToCheckMongos, versionsFound ); - -versionsFound = []; -for ( j = 0; j < configs.length; j++ ) - versionsFound.push( configs[j].getBinVersion() ); - -assert.allBinVersions( versionsToCheck, versionsFound ); - -jsTest.log("DONE!"); - -st.stop(); -})(); + jsTest.log("Testing mixed versions with replica sets..."); + + // Set up a multi-version cluster w/ replica sets + + st = new ShardingTest({ + shards: 2, + mongos: 2, + other: { + // Replica set shards + rs: true, + + mongosOptions: {binVersion: versionsToCheckMongos}, + configOptions: {binVersion: versionsToCheck}, + rsOptions: {binVersion: versionsToCheck, protocolVersion: 0} + } + }); + + var nodesA = st.rs0.nodes; + var nodesB = st.rs1.nodes; + mongoses = [st.s0, st.s1]; + configs = [st.config0, st.config1, st.config2]; + + var getVersion = function(mongo) { + var result = mongo.getDB("admin").runCommand({serverStatus: 1}); + return result.version; + }; + + // Make sure we have hosts of all the different versions + versionsFound = []; + for (j = 0; j < nodesA.length; j++) + versionsFound.push(nodesA[j].getBinVersion()); + + assert.allBinVersions(versionsToCheck, versionsFound); + + versionsFound = []; + for (j = 0; j < nodesB.length; j++) + versionsFound.push(nodesB[j].getBinVersion()); + + assert.allBinVersions(versionsToCheck, versionsFound); + + versionsFound = []; + for (j = 0; j < mongoses.length; j++) + versionsFound.push(mongoses[j].getBinVersion()); + + assert.allBinVersions(versionsToCheckMongos, versionsFound); + + versionsFound = []; + for (j = 0; j < configs.length; j++) + versionsFound.push(configs[j].getBinVersion()); + + assert.allBinVersions(versionsToCheck, versionsFound); + + jsTest.log("DONE!"); + + st.stop(); +})(); diff --git a/jstests/multiVersion/3_upgrade_replset.js b/jstests/multiVersion/3_upgrade_replset.js index d713a59bb43..45d3a7f4844 100644 --- a/jstests/multiVersion/3_upgrade_replset.js +++ b/jstests/multiVersion/3_upgrade_replset.js @@ -2,84 +2,77 @@ // Tests upgrading a replica set // -load( './jstests/multiVersion/libs/multi_rs.js' ); -load( './jstests/libs/test_background_ops.js' ); +load('./jstests/multiVersion/libs/multi_rs.js'); +load('./jstests/libs/test_background_ops.js'); var oldVersion = "last-stable"; -var nodes = { n1 : { binVersion : oldVersion }, - n2 : { binVersion : oldVersion }, - a3 : { binVersion : oldVersion } }; +var nodes = { + n1: {binVersion: oldVersion}, + n2: {binVersion: oldVersion}, + a3: {binVersion: oldVersion} +}; -var rst = new ReplSetTest({ nodes : nodes }); +var rst = new ReplSetTest({nodes: nodes}); rst.startSet(); rst.initiate(); // Wait for a primary node... var primary = rst.getPrimary(); -var otherOpConn = new Mongo( rst.getURL() ); +var otherOpConn = new Mongo(rst.getURL()); var insertNS = "test.foo"; +jsTest.log("Starting parallel operations during upgrade..."); -jsTest.log( "Starting parallel operations during upgrade..." ); - -function findAndInsert( rsURL, coll ){ - - var coll = new Mongo( rsURL ).getCollection( coll + "" ); +function findAndInsert(rsURL, coll) { + var coll = new Mongo(rsURL).getCollection(coll + ""); var count = 0; - - jsTest.log( "Starting finds and inserts..." ); - - while( ! isFinished() ){ - - try{ - - coll.insert({ _id : count, hello : "world" }); - assert.eq( null, coll.getDB().getLastError() ); - assert.neq( null, coll.findOne({ _id : count }) ); - } - catch( e ){ - printjson( e ); + + jsTest.log("Starting finds and inserts..."); + + while (!isFinished()) { + try { + coll.insert({_id: count, hello: "world"}); + assert.eq(null, coll.getDB().getLastError()); + assert.neq(null, coll.findOne({_id: count})); + } catch (e) { + printjson(e); } - + count++; } - - jsTest.log( "Finished finds and inserts..." ); + + jsTest.log("Finished finds and inserts..."); return count; } -var joinFindInsert = - startParallelOps( primary, // The connection where the test info is passed and stored - findAndInsert, - [ rst.getURL(), insertNS ] ); - +var joinFindInsert = + startParallelOps(primary, // The connection where the test info is passed and stored + findAndInsert, + [rst.getURL(), insertNS]); -jsTest.log( "Upgrading replica set..." ); +jsTest.log("Upgrading replica set..."); -rst.upgradeSet({ binVersion: "latest" }); +rst.upgradeSet({binVersion: "latest"}); -jsTest.log( "Replica set upgraded." ); +jsTest.log("Replica set upgraded."); // Wait for primary var primary = rst.getPrimary(); -printjson( rst.status() ); - +printjson(rst.status()); // Allow more valid writes to go through -sleep( 10 * 1000 ); - +sleep(10 * 1000); joinFindInsert(); -var totalInserts = primary.getCollection( insertNS ).find().sort({ _id : -1 }).next()._id + 1; -var dataFound = primary.getCollection( insertNS ).count(); +var totalInserts = primary.getCollection(insertNS).find().sort({_id: -1}).next()._id + 1; +var dataFound = primary.getCollection(insertNS).count(); -jsTest.log( "Found " + dataFound + " docs out of " + tojson( totalInserts ) + " inserted." ); +jsTest.log("Found " + dataFound + " docs out of " + tojson(totalInserts) + " inserted."); -assert.gt( dataFound / totalInserts, 0.5 ); +assert.gt(dataFound / totalInserts, 0.5); rst.stopSet(); - diff --git a/jstests/multiVersion/balancer_multiVersion_detect.js b/jstests/multiVersion/balancer_multiVersion_detect.js index c1db3036cfb..3ebf847829a 100644 --- a/jstests/multiVersion/balancer_multiVersion_detect.js +++ b/jstests/multiVersion/balancer_multiVersion_detect.js @@ -2,28 +2,28 @@ // Test checks whether the balancer correctly detects a mixed set of shards // -jsTest.log( "Starting cluster..." ); +jsTest.log("Starting cluster..."); var options = { - - mongosOptions : { verbose : 1, useLogFiles : true }, - configOptions : { }, - shardOptions : { binVersion : [ "latest", "last-stable" ] }, - sync : false, - enableBalancer : true + + mongosOptions: {verbose: 1, useLogFiles: true}, + configOptions: {}, + shardOptions: {binVersion: ["latest", "last-stable"]}, + sync: false, + enableBalancer: true }; -var st = new ShardingTest({ shards : 3, mongos : 1, other : options }); +var st = new ShardingTest({shards: 3, mongos: 1, other: options}); var mongos = st.s0; var admin = mongos.getDB("admin"); var coll = mongos.getCollection("foo.bar"); -printjson(admin.runCommand({ enableSharding : coll.getDB() + "" })); +printjson(admin.runCommand({enableSharding: coll.getDB() + ""})); st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001'); -printjson(admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } })); +printjson(admin.runCommand({shardCollection: coll + "", key: {_id: 1}})); -assert.soon( function() { +assert.soon(function() { var log = cat(mongos.fullOptions.logFile); return /multiVersion cluster detected/.test(log); }, "multiVersion warning not printed!", 30 * 16 * 60 * 1000, 5 * 1000); diff --git a/jstests/multiVersion/downgrade_replset.js b/jstests/multiVersion/downgrade_replset.js index 03c40114b0e..abffcf3875e 100644 --- a/jstests/multiVersion/downgrade_replset.js +++ b/jstests/multiVersion/downgrade_replset.js @@ -8,9 +8,11 @@ var newVersion = "latest"; var oldVersion = "last-stable"; var name = "replsetdowngrade"; -var nodes = {n1: {binVersion: newVersion}, - n2: {binVersion: newVersion}, - n3: {binVersion: newVersion}}; +var nodes = { + n1: {binVersion: newVersion}, + n2: {binVersion: newVersion}, + n3: {binVersion: newVersion} +}; var rst = new ReplSetTest({name: name, nodes: nodes, nodeOptions: {storageEngine: 'mmapv1'}}); rst.startSet(); @@ -22,7 +24,7 @@ var primary = rst.getPrimary(); var coll = "test.foo"; jsTest.log("Inserting documents into collection."); -for (var i=0; i<10; i++) { +for (var i = 0; i < 10; i++) { primary.getCollection(coll).insert({_id: i, str: "hello world"}); } @@ -39,7 +41,7 @@ jsTest.log("Starting parallel operations during downgrade.."); var joinFindInsert = startParallelOps(primary, insertDocuments, [rst.getURL(), coll]); jsTest.log("Downgrading replica set.."); -rst.upgradeSet({ binVersion: oldVersion }); +rst.upgradeSet({binVersion: oldVersion}); jsTest.log("Downgrade complete."); primary = rst.getPrimary(); diff --git a/jstests/multiVersion/dumprestore.js b/jstests/multiVersion/dumprestore.js index 07b7895c07f..8d692e4abb6 100644 --- a/jstests/multiVersion/dumprestore.js +++ b/jstests/multiVersion/dumprestore.js @@ -1,7 +1,6 @@ // dumprestore.js -load( './jstests/multiVersion/libs/dumprestore_helpers.js' ); - +load('./jstests/multiVersion/libs/dumprestore_helpers.js'); // The base name to use for various things in the test, including the dbpath and the database name var testBaseName = "jstests_tool_dumprestore"; @@ -12,14 +11,13 @@ var testDbpath = MongoRunner.dataPath + testBaseName + "_dbpath_external/"; // Start with basic multiversion tests just running against a single mongod var singleNodeTests = { - 'serverSourceVersion' : [ "latest", "last-stable" ], - 'serverDestVersion' :[ "latest", "last-stable" ], - 'mongoDumpVersion' :[ "latest", "last-stable" ], - 'mongoRestoreVersion' :[ "latest", "last-stable" ], - 'dumpDir' : [ dumpDir ], - 'testDbpath' : [ testDbpath ], - 'dumpType' : [ "mongod" ], - 'restoreType' : [ "mongod" ] + 'serverSourceVersion': ["latest", "last-stable"], + 'serverDestVersion': ["latest", "last-stable"], + 'mongoDumpVersion': ["latest", "last-stable"], + 'mongoRestoreVersion': ["latest", "last-stable"], + 'dumpDir': [dumpDir], + 'testDbpath': [testDbpath], + 'dumpType': ["mongod"], + 'restoreType': ["mongod"] }; runAllDumpRestoreTests(singleNodeTests); - diff --git a/jstests/multiVersion/dumprestore_sharded.js b/jstests/multiVersion/dumprestore_sharded.js index 5d4a603dd3f..dd916164b0c 100644 --- a/jstests/multiVersion/dumprestore_sharded.js +++ b/jstests/multiVersion/dumprestore_sharded.js @@ -1,7 +1,6 @@ // dumprestore_sharded.js -load( './jstests/multiVersion/libs/dumprestore_helpers.js' ); - +load('./jstests/multiVersion/libs/dumprestore_helpers.js'); // The base name to use for various things in the test, including the dbpath and the database name var testBaseName = "jstests_tool_dumprestore_sharded"; @@ -10,33 +9,28 @@ var testBaseName = "jstests_tool_dumprestore_sharded"; var dumpDir = MongoRunner.dataPath + testBaseName + "_dump_external/"; var testDbpath = MongoRunner.dataPath + testBaseName + "_dbpath_external/"; - - // Test dumping from a sharded cluster across versions var shardedDumpTests = { - 'serverSourceVersion' : [ "latest", "last-stable" ], - 'serverDestVersion' :[ "latest", "last-stable" ], - 'mongoDumpVersion' :[ "latest", "last-stable" ], - 'mongoRestoreVersion' :[ "latest", "last-stable" ], - 'dumpDir' : [ dumpDir ], - 'testDbpath' : [ testDbpath ], - 'dumpType' : [ "mongos" ], - 'restoreType' : [ "mongod" ] + 'serverSourceVersion': ["latest", "last-stable"], + 'serverDestVersion': ["latest", "last-stable"], + 'mongoDumpVersion': ["latest", "last-stable"], + 'mongoRestoreVersion': ["latest", "last-stable"], + 'dumpDir': [dumpDir], + 'testDbpath': [testDbpath], + 'dumpType': ["mongos"], + 'restoreType': ["mongod"] }; runAllDumpRestoreTests(shardedDumpTests); - - // Test restoring to a sharded cluster across versions var shardedRestoreTests = { - 'serverSourceVersion' : [ "latest", "last-stable" ], - 'serverDestVersion' :[ "latest", "last-stable" ], - 'mongoDumpVersion' :[ "latest", "last-stable" ], - 'mongoRestoreVersion' :[ "latest", "last-stable" ], - 'dumpDir' : [ dumpDir ], - 'testDbpath' : [ testDbpath ], - 'dumpType' : [ "mongod" ], - 'restoreType' : [ "mongos" ] + 'serverSourceVersion': ["latest", "last-stable"], + 'serverDestVersion': ["latest", "last-stable"], + 'mongoDumpVersion': ["latest", "last-stable"], + 'mongoRestoreVersion': ["latest", "last-stable"], + 'dumpDir': [dumpDir], + 'testDbpath': [testDbpath], + 'dumpType': ["mongod"], + 'restoreType': ["mongos"] }; runAllDumpRestoreTests(shardedRestoreTests); - diff --git a/jstests/multiVersion/geo_2dsphere_v2_to_v3.js b/jstests/multiVersion/geo_2dsphere_v2_to_v3.js index 3cd0e616c7b..9fa3773e2a8 100644 --- a/jstests/multiVersion/geo_2dsphere_v2_to_v3.js +++ b/jstests/multiVersion/geo_2dsphere_v2_to_v3.js @@ -4,10 +4,7 @@ function generatePoint() { var longitude = Math.random() * 10 - 5; var latitude = Math.random() * 10 - 5; var pt = { - geometry : { - type : "Point", - coordinates : [longitude, latitude] - } + geometry: {type: "Point", coordinates: [longitude, latitude]} }; return pt; } @@ -28,17 +25,12 @@ function generatePolygons(amount) { var numpoints = 4 + Math.floor(Math.random() * 10); var dist = Math.random() * 5 + .01; var coordinates = []; - for (var j = 0; j < numpoints-1; j++) { - var angle = (j/numpoints) * 2 * Math.PI; + for (var j = 0; j < numpoints - 1; j++) { + var angle = (j / numpoints) * 2 * Math.PI; coordinates.push([dist * Math.cos(angle), dist * Math.sin(angle)]); } coordinates.push(coordinates[0]); - polygons.push({ - geometry: { - type: "Polygon", - coordinates: [coordinates] - } - }); + polygons.push({geometry: {type: "Polygon", coordinates: [coordinates]}}); } return polygons; } @@ -58,14 +50,7 @@ function get2dsphereIndexVersion(coll) { } var nearQuery = { - geometry: { - $near : { - $geometry : { - type: "Point", - coordinates: [0,0] - } - } - } + geometry: {$near: {$geometry: {type: "Point", coordinates: [0, 0]}}} }; var mongod = MongoRunner.runMongod({binVersion: "3.0"}); diff --git a/jstests/multiVersion/initialize_from_old_node.js b/jstests/multiVersion/initialize_from_old_node.js index ad37397d50c..79aaafb6a4e 100644 --- a/jstests/multiVersion/initialize_from_old_node.js +++ b/jstests/multiVersion/initialize_from_old_node.js @@ -1,5 +1,5 @@ /* - * This is a regression test for SERVER-16189, to make sure a replica set with both current and + * This is a regression test for SERVER-16189, to make sure a replica set with both current and * prior version nodes can be initialized from the prior version node. */ diff --git a/jstests/multiVersion/initialsync.js b/jstests/multiVersion/initialsync.js index dac71ff24f4..bbc06c11490 100644 --- a/jstests/multiVersion/initialsync.js +++ b/jstests/multiVersion/initialsync.js @@ -8,8 +8,10 @@ var newVersion = "latest"; var name = "multiversioninitsync"; var multitest = function(replSetVersion, newNodeVersion) { - var nodes = {n1: {binVersion: replSetVersion}, - n2: {binVersion: replSetVersion}}; + var nodes = { + n1: {binVersion: replSetVersion}, + n2: {binVersion: replSetVersion} + }; print("Start up a two-node " + replSetVersion + " replica set."); var rst = new ReplSetTest({name: name, nodes: nodes}); @@ -25,13 +27,12 @@ var multitest = function(replSetVersion, newNodeVersion) { var primary = rst.getPrimary(); // Insert some data and wait for replication. - for (var i=0; i<25; i++) { + for (var i = 0; i < 25; i++) { primary.getDB("foo").foo.insert({_id: i}); } rst.awaitReplication(); - print("Bring up a new node with version " + newNodeVersion + - " and add to set."); + print("Bring up a new node with version " + newNodeVersion + " and add to set."); rst.add({binVersion: newNodeVersion}); rst.reInitiate(); diff --git a/jstests/multiVersion/invalid_key_pattern_upgrade.js b/jstests/multiVersion/invalid_key_pattern_upgrade.js index 27aa8590989..ce71333ef40 100644 --- a/jstests/multiVersion/invalid_key_pattern_upgrade.js +++ b/jstests/multiVersion/invalid_key_pattern_upgrade.js @@ -8,11 +8,7 @@ (function() { 'use strict'; - var testCases = [ - {a: 0}, - {a: NaN}, - {a: true}, - ]; + var testCases = [{a: 0}, {a: NaN}, {a: true}, ]; // The mongod should not start up when an index with an invalid key pattern exists. testCases.forEach(function(indexKeyPattern) { @@ -30,8 +26,8 @@ // Start the old version. var oldVersionOptions = Object.extend({binVersion: '3.2'}, defaultOptions); var conn = MongoRunner.runMongod(oldVersionOptions); - assert.neq(null, conn, 'mongod was unable to start up with options ' + - tojson(oldVersionOptions)); + assert.neq( + null, conn, 'mongod was unable to start up with options ' + tojson(oldVersionOptions)); // Use write commands in order to make assertions about the success of operations based on // the response from the server. @@ -42,8 +38,10 @@ // Start the newest version. conn = MongoRunner.runMongod(defaultOptions); - assert.eq(null, conn, 'mongod should not have been able to start up when an index with' + - ' an invalid key pattern' + tojson(indexKeyPattern) + ' exists'); + assert.eq(null, + conn, + 'mongod should not have been able to start up when an index with' + + ' an invalid key pattern' + tojson(indexKeyPattern) + ' exists'); }); // Create a replica set with a primary running 3.2 and a secondary running the latest version. @@ -51,10 +49,7 @@ // replicates. testCases.forEach(function(indexKeyPattern) { var replSetName = 'invalid_key_pattern_replset'; - var nodes = [ - {binVersion: '3.2'}, - {binVersion: 'latest'}, - ]; + var nodes = [{binVersion: '3.2'}, {binVersion: 'latest'}, ]; var rst = new ReplSetTest({name: replSetName, nodes: nodes}); @@ -80,15 +75,17 @@ // Verify that the secondary running the latest version terminates when the command to build // an index with an invalid key pattern replicates. - assert.soon(function() { - try { - secondaryLatest.getDB('test').runCommand({ping: 1}); - } catch (e) { - return true; - } - return false; - }, 'secondary should have terminated due to request to build an index with an invalid key' + - ' pattern ' + tojson(indexKeyPattern)); + assert.soon( + function() { + try { + secondaryLatest.getDB('test').runCommand({ping: 1}); + } catch (e) { + return true; + } + return false; + }, + 'secondary should have terminated due to request to build an index with an invalid key' + + ' pattern ' + tojson(indexKeyPattern)); rst.stopSet(undefined, undefined, {allowedExitCodes: [MongoRunner.EXIT_ABRUPT]}); }); diff --git a/jstests/multiVersion/libs/auth_helpers.js b/jstests/multiVersion/libs/auth_helpers.js index ecbf2047212..99c0a64b05b 100644 --- a/jstests/multiVersion/libs/auth_helpers.js +++ b/jstests/multiVersion/libs/auth_helpers.js @@ -1,15 +1,15 @@ // Helpers for auth upgrade tests. // Get a user document for username in db. -var getUserDoc = function(db, username){ - return db.runCommand({'usersInfo': {user: username, db: db._name}, - showCredentials: true}).users[0]; +var getUserDoc = function(db, username) { + return db.runCommand({'usersInfo': {user: username, db: db._name}, showCredentials: true}) + .users[0]; }; // Verify that the user document for username in db // has MONGODB-CR credentials (or not) and SCRAM-SHA-1 // credentials (or not). -var verifyUserDoc = function(db, username, hasCR, hasSCRAM, hasExternal = false){ +var verifyUserDoc = function(db, username, hasCR, hasSCRAM, hasExternal = false) { var userDoc = getUserDoc(db, username); assert.eq(hasCR, 'MONGODB-CR' in userDoc.credentials); assert.eq(hasSCRAM, 'SCRAM-SHA-1' in userDoc.credentials); @@ -18,10 +18,8 @@ var verifyUserDoc = function(db, username, hasCR, hasSCRAM, hasExternal = false) // Verify that that we can authenticate (or not) using MONGODB-CR // and SCRAM-SHA-1 to db using username and password. -var verifyAuth = function(db, username, password, passCR, passSCRAM){ - assert.eq(passCR, db.auth({mechanism: 'MONGODB-CR', - user: username, pwd: password})); - assert.eq(passSCRAM, db.auth({mechanism: 'SCRAM-SHA-1', - user: username, pwd: password})); +var verifyAuth = function(db, username, password, passCR, passSCRAM) { + assert.eq(passCR, db.auth({mechanism: 'MONGODB-CR', user: username, pwd: password})); + assert.eq(passSCRAM, db.auth({mechanism: 'SCRAM-SHA-1', user: username, pwd: password})); db.logout(); }; diff --git a/jstests/multiVersion/libs/data_generators.js b/jstests/multiVersion/libs/data_generators.js index 6f57e3e0060..c2af0638a5f 100644 --- a/jstests/multiVersion/libs/data_generators.js +++ b/jstests/multiVersion/libs/data_generators.js @@ -18,7 +18,6 @@ // } // function DataGenerator() { - var hexChars = "0123456789abcdefABCDEF"; var regexOptions = "igm"; var stringChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -26,52 +25,54 @@ function DataGenerator() { // Generator functions // BSON Type: -1 - function GenMinKey (seed) { + function GenMinKey(seed) { return MinKey(); } // BSON Type: 0 (EOO) // No Shell Equivalent // BSON Type: 1 - function GenNumberDouble (seed) { + function GenNumberDouble(seed) { var seed = seed || 0; return Number(seed); } // BSON Type: 2 - function GenString (seed) { + function GenString(seed) { var seed = seed || 0; var text = ""; - for (var i=0; i < (seed % 1000) + 1; i++) { + for (var i = 0; i < (seed % 1000) + 1; i++) { text += stringChars.charAt((seed + (i % 10)) % stringChars.length); } return text; } // Javascript Dates get stored as strings - function GenDate (seed) { + function GenDate(seed) { // The "Date" constructor without "new" ignores its arguments anyway, so don't bother // using the seed. return Date(); } // BSON Type: 3 - function GenObject (seed) { + function GenObject(seed) { var seed = seed || 0; - return { "object" : true }; + return { + "object": true + }; } // BSON Type: 4 - function GenArray (seed) { + function GenArray(seed) { var seed = seed || 0; - return [ "array", true ]; + return ["array", true]; } // BSON Type: 5 - function GenBinData (seed) { + function GenBinData(seed) { var seed = seed || 0; var text = ""; - for (var i=0; i < (seed % 1000) + 1; i++) { + for (var i = 0; i < (seed % 1000) + 1; i++) { text += base64Chars.charAt((seed + (i % 10)) % base64Chars.length); } @@ -82,29 +83,29 @@ function DataGenerator() { return BinData(seed % 6, text); } // BSON Type: 6 - function GenUndefined (seed) { + function GenUndefined(seed) { return undefined; } // BSON Type: 7 - function GenObjectId (seed) { + function GenObjectId(seed) { var seed = seed || 0; var hexString = ""; - for (var i=0; i < 24; i++) { + for (var i = 0; i < 24; i++) { hexString += hexChars.charAt((seed + (i % 10)) % hexChars.length); } return ObjectId(hexString); } // BSON Type: 8 - function GenBool (seed) { + function GenBool(seed) { var seed = seed || 0; return (seed % 2) === 0; } // BSON Type: 9 // Our ISODate constructor equals the Date BSON type - function GenISODate (seed) { + function GenISODate(seed) { var seed = seed || 0; var year = (seed % (2037 - 1970)) + 1970; @@ -116,7 +117,6 @@ function DataGenerator() { var millis = seed % 1000; function pad(number, length) { - var str = '' + number; while (str.length < length) { @@ -126,32 +126,32 @@ function DataGenerator() { return str; } - return ISODate(pad(year, 4) + "-" + pad(month, 2) + "-" + pad(day, 2) + "T" + - pad(hour, 2) + ":" + pad(minute, 2) + ":" + pad(second, 2) + "." + pad(millis, 3)); + return ISODate(pad(year, 4) + "-" + pad(month, 2) + "-" + pad(day, 2) + "T" + pad(hour, 2) + + ":" + pad(minute, 2) + ":" + pad(second, 2) + "." + pad(millis, 3)); } // BSON Type: 10 - function GenNull (seed) { + function GenNull(seed) { return null; } // BSON Type: 11 - function GenRegExp (seed) { + function GenRegExp(seed) { var seed = seed || 0; var options = ""; - for (var i=0; i < (seed % 3) + 1; i++) { + for (var i = 0; i < (seed % 3) + 1; i++) { options += regexOptions.charAt((seed + (i % 10)) % regexOptions.length); } return RegExp(GenString(seed), options); } - function GenRegExpLiteral (seed) { + function GenRegExpLiteral(seed) { // We can't pass variables to a regex literal, so we can't programmatically generate the // data. Instead we rely on the "RegExp" constructor. return /regexliteral/; } // BSON Type: 12 // The DBPointer type in the shell equals the DBRef BSON type - function GenDBPointer (seed) { + function GenDBPointer(seed) { var seed = seed || 0; return DBPointer(GenString(seed), GenObjectId(seed)); @@ -163,13 +163,13 @@ function DataGenerator() { // BSON Type: 15 (CodeWScope) // No Shell Equivalent // BSON Type: 16 - function GenNumberInt (seed) { + function GenNumberInt(seed) { var seed = seed || 0; return NumberInt(seed); } // BSON Type: 17 - function GenTimestamp (seed) { + function GenTimestamp(seed) { var seed = seed || 0; // Make sure our timestamp is not zero, because that doesn't round trip from 2.4 to latest. @@ -181,17 +181,17 @@ function DataGenerator() { return Timestamp(seed, (seed * 100000) / 99999); } // BSON Type: 18 - function GenNumberLong (seed) { + function GenNumberLong(seed) { var seed = seed || 0; return NumberLong(seed); } // BSON Type: 127 - function GenMaxKey (seed) { + function GenMaxKey(seed) { return MaxKey(); } // The DBRef type is not a BSON type but is treated specially in the shell: - function GenDBRef (seed) { + function GenDBRef(seed) { var seed = seed || 0; return DBRef(GenString(seed), GenObjectId(seed)); @@ -199,34 +199,34 @@ function DataGenerator() { function GenFlatObjectAllTypes(seed) { return { - "MinKey" : GenMinKey(seed), - "NumberDouble" : GenNumberDouble(seed), - "String" : GenString(seed), + "MinKey": GenMinKey(seed), + "NumberDouble": GenNumberDouble(seed), + "String": GenString(seed), // Javascript Dates get stored as strings - "Date" : GenDate(seed), + "Date": GenDate(seed), // BSON Type: 3 - "Object" : GenObject(seed), + "Object": GenObject(seed), // BSON Type: 4 - "Array" : GenArray(seed), + "Array": GenArray(seed), // BSON Type: 5 - "BinData" : GenBinData(seed), + "BinData": GenBinData(seed), // BSON Type: 6 - "Undefined" : undefined, + "Undefined": undefined, // BSON Type: 7 - "jstOID" : GenObjectId(seed), + "jstOID": GenObjectId(seed), // BSON Type: 8 - "Bool" : GenBool(seed), + "Bool": GenBool(seed), // BSON Type: 9 // Our ISODate constructor equals the Date BSON type - "ISODate" : GenISODate(seed), + "ISODate": GenISODate(seed), // BSON Type: 10 - "jstNULL" : GenNull(seed), + "jstNULL": GenNull(seed), // BSON Type: 11 - "RegExp" : GenRegExp(seed), - "RegExpLiteral" : GenRegExpLiteral(seed), + "RegExp": GenRegExp(seed), + "RegExpLiteral": GenRegExpLiteral(seed), // BSON Type: 12 // The DBPointer type in the shell equals the DBRef BSON type - "DBPointer" : GenDBPointer(seed), + "DBPointer": GenDBPointer(seed), // BSON Type: 13 (Code) // No Shell Equivalent // BSON Type: 14 (Symbol) @@ -234,54 +234,54 @@ function DataGenerator() { // BSON Type: 15 (CodeWScope) // No Shell Equivalent // BSON Type: 16 - "NumberInt" : GenNumberInt(seed), + "NumberInt": GenNumberInt(seed), // BSON Type: 17 - "Timestamp" : GenTimestamp(seed), + "Timestamp": GenTimestamp(seed), // BSON Type: 18 - "NumberLong" : GenNumberLong(seed), + "NumberLong": GenNumberLong(seed), // BSON Type: 127 - "MaxKey" : GenMaxKey(seed), + "MaxKey": GenMaxKey(seed), // The DBRef type is not a BSON type but is treated specially in the shell: - "DBRef" : GenDBRef(seed), + "DBRef": GenDBRef(seed), }; } function GenFlatObjectAllTypesHardCoded() { return { // BSON Type: -1 - "MinKey" : MinKey(), + "MinKey": MinKey(), // BSON Type: 0 (EOO) // No Shell Equivalent // BSON Type: 1 - "NumberDouble" : Number(4.0), + "NumberDouble": Number(4.0), // BSON Type: 2 - "String" : "string", + "String": "string", // Javascript Dates get stored as strings - "Date" : Date("2013-12-11T19:38:24.055Z"), - "Date2" : GenDate(10000), + "Date": Date("2013-12-11T19:38:24.055Z"), + "Date2": GenDate(10000), // BSON Type: 3 - "Object" : { "object" : true }, + "Object": {"object": true}, // BSON Type: 4 - "Array" : [ "array", true ], + "Array": ["array", true], // BSON Type: 5 - "BinData" : BinData(0, "aaaa"), + "BinData": BinData(0, "aaaa"), // BSON Type: 6 - "Undefined" : undefined, + "Undefined": undefined, // BSON Type: 7 - "jstOID" : ObjectId("aaaaaaaaaaaaaaaaaaaaaaaa"), + "jstOID": ObjectId("aaaaaaaaaaaaaaaaaaaaaaaa"), // BSON Type: 8 - "Bool" : true, + "Bool": true, // BSON Type: 9 // Our ISODate constructor equals the Date BSON type - "ISODate" : ISODate("2013-12-11T19:38:24.055Z"), + "ISODate": ISODate("2013-12-11T19:38:24.055Z"), // BSON Type: 10 - "jstNULL" : null, + "jstNULL": null, // BSON Type: 11 - "RegExp" : RegExp("a"), - "RegExpLiteral" : /a/, + "RegExp": RegExp("a"), + "RegExpLiteral": /a/, // BSON Type: 12 // The DBPointer type in the shell equals the DBRef BSON type - "DBPointer" : DBPointer("foo", ObjectId("bbbbbbbbbbbbbbbbbbbbbbbb")), + "DBPointer": DBPointer("foo", ObjectId("bbbbbbbbbbbbbbbbbbbbbbbb")), // BSON Type: 13 (Code) // No Shell Equivalent // BSON Type: 14 (Symbol) @@ -289,15 +289,15 @@ function DataGenerator() { // BSON Type: 15 (CodeWScope) // No Shell Equivalent // BSON Type: 16 - "NumberInt" : NumberInt(5), + "NumberInt": NumberInt(5), // BSON Type: 17 - "Timestamp" : Timestamp(1,2), + "Timestamp": Timestamp(1, 2), // BSON Type: 18 - "NumberLong" : NumberLong(6), + "NumberLong": NumberLong(6), // BSON Type: 127 - "MaxKey" : MaxKey(), + "MaxKey": MaxKey(), // The DBRef type is not a BSON type but is treated specially in the shell: - "DBRef" : DBRef("bar", 2) + "DBRef": DBRef("bar", 2) }; } @@ -317,10 +317,10 @@ function DataGenerator() { // Cursor interface var i = 0; return { - "hasNext" : function () { + "hasNext": function() { return i < testData.length; }, - "next" : function () { + "next": function() { if (i >= testData.length) { return undefined; } @@ -356,14 +356,15 @@ function DataGenerator() { // } // function IndexDataGenerator(options) { - // getNextUniqueKey() // // This function returns a new key each time it is called and is guaranteed to not return // duplicates. // - // The sequence of values returned is a-z then A-Z. When "Z" is reached, a new character is added - // and the first one wraps around, resulting in "aa". The process is repeated, so we get a sequence + // The sequence of values returned is a-z then A-Z. When "Z" is reached, a new character is + // added + // and the first one wraps around, resulting in "aa". The process is repeated, so we get a + // sequence // like this: // // "a" @@ -378,9 +379,8 @@ function IndexDataGenerator(options) { // ... var currentKey = ""; function getNextUniqueKey() { - function setCharAt(str, index, chr) { - if (index > str.length-1) { + if (index > str.length - 1) { return str; } return str.substr(0, index) + chr + str.substr(index + 1); @@ -401,8 +401,8 @@ function IndexDataGenerator(options) { // Find the character (index into keyChars) that we currently have at this position, set // this position to the next character in the keyChars sequence keyCharsIndex = keyChars.search(currentKey[currentKeyIndex]); - currentKey = setCharAt(currentKey, currentKeyIndex, - keyChars[(keyCharsIndex + 1) % keyChars.length]); + currentKey = setCharAt( + currentKey, currentKeyIndex, keyChars[(keyCharsIndex + 1) % keyChars.length]); currentKeyIndex = currentKeyIndex + 1; // Loop again if we advanced the character past the end of keyChars and wrapped around, @@ -486,11 +486,10 @@ function IndexDataGenerator(options) { } if (propertyType == 1) { attributes["sparse"] = true; - } - else { + } else { // TODO: We have to test this as a separate stage because we want to round trip // multiple documents - //attributes["unique"] = true; + // attributes["unique"] = true; } } return attributes; @@ -512,8 +511,7 @@ function IndexDataGenerator(options) { } if (propertyType == 2) { attributes["max"] = ((seed + i) * 10000) % 100 + 10; - } - else { + } else { } } // The region specified in a 2d index must be positive @@ -551,48 +549,48 @@ function IndexDataGenerator(options) { testIndexes = [ // Single Field Indexes - { "spec" : GenSingleFieldIndex(1), "options" : GenIndexOptions(0) }, - { "spec" : GenSingleFieldIndex(0), "options" : GenIndexOptions(1) }, + {"spec": GenSingleFieldIndex(1), "options": GenIndexOptions(0)}, + {"spec": GenSingleFieldIndex(0), "options": GenIndexOptions(1)}, // Compound Indexes - { "spec" : GenCompoundIndex(0), "options" : GenIndexOptions(2) }, - { "spec" : GenCompoundIndex(1), "options" : GenIndexOptions(3) }, - { "spec" : GenCompoundIndex(2), "options" : GenIndexOptions(4) }, - { "spec" : GenCompoundIndex(3), "options" : GenIndexOptions(5) }, - { "spec" : GenCompoundIndex(4), "options" : GenIndexOptions(6) }, - { "spec" : GenCompoundIndex(5), "options" : GenIndexOptions(7) }, - { "spec" : GenCompoundIndex(6), "options" : GenIndexOptions(8) }, + {"spec": GenCompoundIndex(0), "options": GenIndexOptions(2)}, + {"spec": GenCompoundIndex(1), "options": GenIndexOptions(3)}, + {"spec": GenCompoundIndex(2), "options": GenIndexOptions(4)}, + {"spec": GenCompoundIndex(3), "options": GenIndexOptions(5)}, + {"spec": GenCompoundIndex(4), "options": GenIndexOptions(6)}, + {"spec": GenCompoundIndex(5), "options": GenIndexOptions(7)}, + {"spec": GenCompoundIndex(6), "options": GenIndexOptions(8)}, // Multikey Indexes // (Same index spec as single field) // Nested Indexes - { "spec" : GenNestedIndex(0), "options" : GenIndexOptions(9) }, - { "spec" : GenNestedIndex(1), "options" : GenIndexOptions(10) }, - { "spec" : GenNestedIndex(2), "options" : GenIndexOptions(11) }, + {"spec": GenNestedIndex(0), "options": GenIndexOptions(9)}, + {"spec": GenNestedIndex(1), "options": GenIndexOptions(10)}, + {"spec": GenNestedIndex(2), "options": GenIndexOptions(11)}, // Geospatial Indexes // 2dsphere - { "spec" : Gen2dsphereIndex(7), "options" : Gen2dSphereIndexOptions(12) }, + {"spec": Gen2dsphereIndex(7), "options": Gen2dSphereIndexOptions(12)}, // 2d - { "spec" : Gen2dIndex(8), "options" : Gen2dIndexOptions(13) }, + {"spec": Gen2dIndex(8), "options": Gen2dIndexOptions(13)}, // Haystack - { "spec" : GenHaystackIndex(9), "options" : GenHaystackIndexOptions(13) }, + {"spec": GenHaystackIndex(9), "options": GenHaystackIndexOptions(13)}, // Text Indexes - { "spec" : GenTextIndex(10), "options" : GenTextIndexOptions(14) }, + {"spec": GenTextIndex(10), "options": GenTextIndexOptions(14)}, // Hashed Index - { "spec" : GenHashedIndex(10), "options" : GenIndexOptions(14) }, + {"spec": GenHashedIndex(10), "options": GenIndexOptions(14)}, ]; // Cursor interface var i = 0; return { - "hasNext" : function () { + "hasNext": function() { return i < testIndexes.length; }, - "next" : function () { + "next": function() { if (i >= testIndexes.length) { return undefined; } @@ -620,7 +618,6 @@ function IndexDataGenerator(options) { // var metadata = generator.get(); // function CollectionMetadataGenerator(options) { - var capped = true; var options = options || {}; @@ -628,32 +625,34 @@ function CollectionMetadataGenerator(options) { if (options.hasOwnProperty(option)) { if (option === 'capped') { if (typeof(options['capped']) !== 'boolean') { - throw Error("\"capped\" options must be boolean in CollectionMetadataGenerator"); + throw Error( + "\"capped\" options must be boolean in CollectionMetadataGenerator"); } capped = options['capped']; - } - else { - throw Error("Unsupported key in options passed to CollectionMetadataGenerator: " + option); + } else { + throw Error("Unsupported key in options passed to CollectionMetadataGenerator: " + + option); } } } // Collection metadata we are using as a source for testing - //db.createCollection(name, {capped: <Boolean>, autoIndexId: <Boolean>, size: <number>, max <number>} ) + // db.createCollection(name, {capped: <Boolean>, autoIndexId: <Boolean>, size: <number>, max + // <number>} ) var cappedCollectionMetadata = { - "capped" : true, - "size" : 100000, - "max" : 2000, - "usePowerOf2Sizes" : true, + "capped": true, + "size": 100000, + "max": 2000, + "usePowerOf2Sizes": true, //"autoIndexId" : false // XXX: this doesn't exist in 2.4 }; // We need to explicitly enable usePowerOf2Sizes, since it's the default in 2.6 but not in 2.4 var normalCollectionMetadata = { - "usePowerOf2Sizes" : true + "usePowerOf2Sizes": true }; return { - "get" : function () { + "get": function() { return capped ? cappedCollectionMetadata : normalCollectionMetadata; } }; @@ -664,8 +663,8 @@ function CollectionMetadataGenerator(options) { // function CollectionDataGenerator(options) { return { - "data" : new DataGenerator(), - "indexes" : new IndexDataGenerator(), - "collectionMetadata" : new CollectionMetadataGenerator(options) + "data": new DataGenerator(), + "indexes": new IndexDataGenerator(), + "collectionMetadata": new CollectionMetadataGenerator(options) }; } diff --git a/jstests/multiVersion/libs/dumprestore_helpers.js b/jstests/multiVersion/libs/dumprestore_helpers.js index 2f65a28190e..a2b7d22d20c 100644 --- a/jstests/multiVersion/libs/dumprestore_helpers.js +++ b/jstests/multiVersion/libs/dumprestore_helpers.js @@ -1,6 +1,6 @@ // dumprestore_helpers.js -load( './jstests/multiVersion/libs/verify_collection_data.js' ); +load('./jstests/multiVersion/libs/verify_collection_data.js'); // Given a "test spec" object, runs the specified test. // @@ -28,7 +28,6 @@ load( './jstests/multiVersion/libs/verify_collection_data.js' ); // - "mongos" - Do the dump or restore by connecting to a sharded cluster // function multiVersionDumpRestoreTest(configObj) { - // First sanity check the arguments in our configObj var requiredKeys = [ 'serverSourceVersion', @@ -52,25 +51,24 @@ function multiVersionDumpRestoreTest(configObj) { resetDbpath(configObj.testDbpath); if (configObj.dumpType === "mongos") { var shardingTestConfig = { - sync: true, // Mixed version clusters can't use replsets for config servers - name : testBaseName + "_sharded_source", - mongos : [{ binVersion : configObj.serverSourceVersion }], - shards : [{ binVersion : configObj.serverSourceVersion }], - config : [{ binVersion : configObj.serverSourceVersion }] + sync: true, // Mixed version clusters can't use replsets for config servers + name: testBaseName + "_sharded_source", + mongos: [{binVersion: configObj.serverSourceVersion}], + shards: [{binVersion: configObj.serverSourceVersion}], + config: [{binVersion: configObj.serverSourceVersion}] }; var shardingTest = new ShardingTest(shardingTestConfig); var serverSource = shardingTest.s; - } - else { - var serverSource = MongoRunner.runMongod({ binVersion : configObj.serverSourceVersion, - dbpath : configObj.testDbpath }); + } else { + var serverSource = MongoRunner.runMongod( + {binVersion: configObj.serverSourceVersion, dbpath: configObj.testDbpath}); } var sourceDB = serverSource.getDB(testBaseName); // Create generators to create collections with our seed data // Testing with both a capped collection and a normal collection - var cappedCollGen = new CollectionDataGenerator({ "capped" : true }); - var collGen = new CollectionDataGenerator({ "capped" : false }); + var cappedCollGen = new CollectionDataGenerator({"capped": true}); + var collGen = new CollectionDataGenerator({"capped": false}); // Create collections using the different generators var sourceCollCapped = createCollectionWithData(sourceDB, "cappedColl", cappedCollGen); @@ -84,43 +82,53 @@ function multiVersionDumpRestoreTest(configObj) { // Dump using the specified version of mongodump from the running mongod or mongos instance. if (configObj.dumpType === "mongod") { - MongoRunner.runMongoTool("mongodump", { out : configObj.dumpDir, - binVersion : configObj.mongoDumpVersion, - host : serverSource.host, - db : testBaseName }); + MongoRunner.runMongoTool("mongodump", + { + out: configObj.dumpDir, + binVersion: configObj.mongoDumpVersion, + host: serverSource.host, + db: testBaseName + }); MongoRunner.stopMongod(serverSource.port); - } - else { /* "mongos" */ - MongoRunner.runMongoTool("mongodump", { out : configObj.dumpDir, - binVersion : configObj.mongoDumpVersion, - host : serverSource.host, - db : testBaseName }); + } else { /* "mongos" */ + MongoRunner.runMongoTool("mongodump", + { + out: configObj.dumpDir, + binVersion: configObj.mongoDumpVersion, + host: serverSource.host, + db: testBaseName + }); shardingTest.stop(); } // Restore using the specified version of mongorestore if (configObj.restoreType === "mongod") { - var serverDest = MongoRunner.runMongod({ binVersion : configObj.serverDestVersion }); - - MongoRunner.runMongoTool("mongorestore", { dir : configObj.dumpDir + "/" + testBaseName, - binVersion : configObj.mongoRestoreVersion, - host : serverDest.host, - db : testBaseName }); - } - else { /* "mongos" */ + var serverDest = MongoRunner.runMongod({binVersion: configObj.serverDestVersion}); + + MongoRunner.runMongoTool("mongorestore", + { + dir: configObj.dumpDir + "/" + testBaseName, + binVersion: configObj.mongoRestoreVersion, + host: serverDest.host, + db: testBaseName + }); + } else { /* "mongos" */ var shardingTestConfig = { - sync: true, // Mixed version clusters can't use replsets for config servers - name : testBaseName + "_sharded_dest", - mongos : [{ binVersion : configObj.serverDestVersion }], - shards : [{ binVersion : configObj.serverDestVersion }], - config : [{ binVersion : configObj.serverDestVersion }] + sync: true, // Mixed version clusters can't use replsets for config servers + name: testBaseName + "_sharded_dest", + mongos: [{binVersion: configObj.serverDestVersion}], + shards: [{binVersion: configObj.serverDestVersion}], + config: [{binVersion: configObj.serverDestVersion}] }; var shardingTest = new ShardingTest(shardingTestConfig); serverDest = shardingTest.s; - MongoRunner.runMongoTool("mongorestore", { dir : configObj.dumpDir + "/" + testBaseName, - binVersion : configObj.mongoRestoreVersion, - host : serverDest.host, - db : testBaseName }); + MongoRunner.runMongoTool("mongorestore", + { + dir: configObj.dumpDir + "/" + testBaseName, + binVersion: configObj.mongoRestoreVersion, + host: serverDest.host, + db: testBaseName + }); } var destDB = serverDest.getDB(testBaseName); @@ -141,8 +149,7 @@ function multiVersionDumpRestoreTest(configObj) { if (configObj.restoreType === "mongos") { shardingTest.stop(); - } - else { + } else { MongoRunner.stopMongod(serverDest.port); } } @@ -164,9 +171,7 @@ function multiVersionDumpRestoreTest(configObj) { // { "a" : 0, "b" : 3 } // { "a" : 1, "b" : 3 } function getPermutationIterator(permsObj) { - function getAllPermutations(permsObj) { - // Split our permutations object into "first" and "rest" var gotFirst = false; var firstKey; @@ -176,8 +181,7 @@ function getPermutationIterator(permsObj) { if (permsObj.hasOwnProperty(key)) { if (gotFirst) { restObj[key] = permsObj[key]; - } - else { + } else { firstKey = key; firstValues = permsObj[key]; gotFirst = true; @@ -209,10 +213,10 @@ function getPermutationIterator(permsObj) { var currentPermutation = 0; return { - "next" : function () { + "next": function() { return allPermutations[currentPermutation++]; }, - "hasNext" : function () { + "hasNext": function() { return currentPermutation < allPermutations.length; } }; diff --git a/jstests/multiVersion/libs/multi_cluster.js b/jstests/multiVersion/libs/multi_cluster.js index cf60f531307..5d98f942546 100644 --- a/jstests/multiVersion/libs/multi_cluster.js +++ b/jstests/multiVersion/libs/multi_cluster.js @@ -15,11 +15,14 @@ * upgradeMongos: <bool>, // defaults to true * } */ -ShardingTest.prototype.upgradeCluster = function( binVersion, options ){ +ShardingTest.prototype.upgradeCluster = function(binVersion, options) { options = options || {}; - if (options.upgradeShards == undefined) options.upgradeShards = true; - if (options.upgradeConfigs == undefined) options.upgradeConfigs = true; - if (options.upgradeMongos == undefined) options.upgradeMongos = true; + if (options.upgradeShards == undefined) + options.upgradeShards = true; + if (options.upgradeConfigs == undefined) + options.upgradeConfigs = true; + if (options.upgradeMongos == undefined) + options.upgradeMongos = true; var upgradedSingleShards = []; @@ -32,12 +35,10 @@ ShardingTest.prototype.upgradeCluster = function( binVersion, options ){ if (configSvr.host in upgradedSingleShards) { configSvr = upgradedSingleShards[configSvr.host]; - } - else { + } else { MongoRunner.stopMongod(configSvr); - configSvr = MongoRunner.runMongod({ restart: configSvr, - binVersion: binVersion, - appendOptions: true }); + configSvr = MongoRunner.runMongod( + {restart: configSvr, binVersion: binVersion, appendOptions: true}); } this["config" + i] = this["c" + i] = this._configServers[i] = configSvr; @@ -49,18 +50,16 @@ ShardingTest.prototype.upgradeCluster = function( binVersion, options ){ // Upgrade shards for (var i = 0; i < numShards; i++) { - if( this._rs && this._rs[i] ){ + if (this._rs && this._rs[i]) { // Upgrade replica set var rst = this._rs[i].test; - rst.upgradeSet({ binVersion: binVersion }); - } - else { + rst.upgradeSet({binVersion: binVersion}); + } else { // Upgrade shard var shard = this._connections[i]; MongoRunner.stopMongod(shard); - shard = MongoRunner.runMongod({ restart: shard, - binVersion: binVersion, - appendOptions: true }); + shard = MongoRunner.runMongod( + {restart: shard, binVersion: binVersion, appendOptions: true}); upgradedSingleShards[shard.host] = shard; this["shard" + i] = this["d" + i] = this._connections[i] = shard; @@ -76,12 +75,12 @@ ShardingTest.prototype.upgradeCluster = function( binVersion, options ){ var mongos = this._mongos[i]; MongoRunner.stopMongos(mongos); - mongos = MongoRunner.runMongos({ restart : mongos, - binVersion : binVersion, - appendOptions : true }); + mongos = MongoRunner.runMongos( + {restart: mongos, binVersion: binVersion, appendOptions: true}); this["s" + i] = this._mongos[i] = mongos; - if (i == 0) this.s = mongos; + if (i == 0) + this.s = mongos; } this.config = this.s.getDB("config"); @@ -90,22 +89,22 @@ ShardingTest.prototype.upgradeCluster = function( binVersion, options ){ }; ShardingTest.prototype.restartMongoses = function() { - + var numMongoses = this._mongos.length; - + for (var i = 0; i < numMongoses; i++) { - var mongos = this._mongos[i]; - + MongoRunner.stopMongos(mongos); - mongos = MongoRunner.runMongos({ restart : mongos }); - - this[ "s" + i ] = this._mongos[i] = mongos; - if( i == 0 ) this.s = mongos; + mongos = MongoRunner.runMongos({restart: mongos}); + + this["s" + i] = this._mongos[i] = mongos; + if (i == 0) + this.s = mongos; } - - this.config = this.s.getDB( "config" ); - this.admin = this.s.getDB( "admin" ); + + this.config = this.s.getDB("config"); + this.admin = this.s.getDB("admin"); }; ShardingTest.prototype.getMongosAtVersion = function(binVersion) { @@ -116,8 +115,7 @@ ShardingTest.prototype.getMongosAtVersion = function(binVersion) { if (version.indexOf(binVersion) == 0) { return mongoses[i]; } - } - catch (e) { + } catch (e) { printjson(e); print(mongoses[i]); } diff --git a/jstests/multiVersion/libs/multi_rs.js b/jstests/multiVersion/libs/multi_rs.js index 4e943f39531..109db580453 100644 --- a/jstests/multiVersion/libs/multi_rs.js +++ b/jstests/multiVersion/libs/multi_rs.js @@ -22,14 +22,14 @@ ReplSetTest.prototype.upgradeSet = function(options, user, pwd) { var noDowntimePossible = this.nodes.length > 2; for (var i = 0; i < nodesToUpgrade.length; i++) { - var node = nodesToUpgrade[ i ]; + var node = nodesToUpgrade[i]; if (node == primary) { node = this.stepdown(node); primary = this.getPrimary(); } var prevPrimaryId = this.getNodeId(primary); - //merge new options into node settings... + // merge new options into node settings... for (var nodeName in this.nodeOptions) { this.nodeOptions[nodeName] = Object.merge(this.nodeOptions[nodeName], options); } @@ -46,7 +46,7 @@ ReplSetTest.prototype.upgradeNode = function(node, opts, user, pwd) { assert.eq(1, node.getDB("admin").auth(user, pwd)); } - var isMaster = node.getDB('admin').runCommand({ isMaster: 1 }); + var isMaster = node.getDB('admin').runCommand({isMaster: 1}); if (!isMaster.arbiterOnly) { assert.commandWorked(node.adminCommand("replSetMaintenance")); @@ -58,9 +58,8 @@ ReplSetTest.prototype.upgradeNode = function(node, opts, user, pwd) { newNode.getDB("admin").auth(user, pwd); } - var waitForStates = [ ReplSetTest.State.PRIMARY, - ReplSetTest.State.SECONDARY, - ReplSetTest.State.ARBITER ]; + var waitForStates = + [ReplSetTest.State.PRIMARY, ReplSetTest.State.SECONDARY, ReplSetTest.State.ARBITER]; this.waitForState(newNode, waitForStates); return newNode; @@ -72,10 +71,9 @@ ReplSetTest.prototype.stepdown = function(nodeId) { var node = this.nodes[nodeId]; try { - node.getDB("admin").runCommand({ replSetStepDown: 50, force: true }); + node.getDB("admin").runCommand({replSetStepDown: 50, force: true}); assert(false); - } - catch (ex) { + } catch (ex) { print('Caught exception after stepDown cmd: ' + tojson(ex)); } @@ -87,17 +85,18 @@ ReplSetTest.prototype.reconnect = function(node) { this.nodes[nodeId] = new Mongo(node.host); var except = {}; for (var i in node) { - if (typeof(node[i]) == "function") continue; + if (typeof(node[i]) == "function") + continue; this.nodes[nodeId][i] = node[i]; } return this.nodes[nodeId]; }; -ReplSetTest.prototype.conf = function () { +ReplSetTest.prototype.conf = function() { var admin = this.getPrimary().getDB('admin'); - var resp = admin.runCommand({replSetGetConfig:1}); + var resp = admin.runCommand({replSetGetConfig: 1}); if (resp.ok && !(resp.errmsg) && resp.config) return resp.config; @@ -107,4 +106,3 @@ ReplSetTest.prototype.conf = function () { throw new Error("Could not retrieve replica set config: " + tojson(resp)); }; - diff --git a/jstests/multiVersion/libs/verify_collection_data.js b/jstests/multiVersion/libs/verify_collection_data.js index 73e54f32f48..1b0437917ee 100644 --- a/jstests/multiVersion/libs/verify_collection_data.js +++ b/jstests/multiVersion/libs/verify_collection_data.js @@ -18,10 +18,10 @@ // 4. Do round trip or other testing // 5. Validate that collection has not changed using the CollectionDataValidator class -load( './jstests/multiVersion/libs/data_generators.js' ); +load('./jstests/multiVersion/libs/data_generators.js'); // Function to actually add the data generated by the given dataGenerator to a collection -createCollectionWithData = function (db, collectionName, dataGenerator) { +createCollectionWithData = function(db, collectionName, dataGenerator) { // Drop collection if exists // TODO: add ability to control this @@ -67,7 +67,6 @@ createCollectionWithData = function (db, collectionName, dataGenerator) { // Class to save the state of a collection and later compare the current state of a collection to // the saved state function CollectionDataValidator() { - var _initialized = false; var _collectionInfo = {}; var _indexData = []; @@ -81,25 +80,27 @@ function CollectionDataValidator() { }; // Saves the current state of the collection passed in - this.recordCollectionData = function (collection) { + this.recordCollectionData = function(collection) { // Save the metadata for this collection for later comparison. _collectionInfo = this.getCollectionInfo(collection); // Save the indexes for this collection for later comparison - _indexData = collection.getIndexes().sort(function(a,b) { - if (a.name > b.name) return 1; - else return -1; + _indexData = collection.getIndexes().sort(function(a, b) { + if (a.name > b.name) + return 1; + else + return -1; }); // Save the data for this collection for later comparison - _collectionData = collection.find().sort({"_id":1}).toArray(); + _collectionData = collection.find().sort({"_id": 1}).toArray(); _initialized = true; return collection; }; - this.validateCollectionData = function (collection) { + this.validateCollectionData = function(collection) { if (!_initialized) { throw Error("validateCollectionWithAllData called, but data is not initialized"); @@ -111,16 +112,18 @@ function CollectionDataValidator() { assert.docEq(_collectionInfo, newCollectionInfo, "collection metadata not equal"); // Get the indexes for this collection - var newIndexData = collection.getIndexes().sort(function(a,b) { - if (a.name > b.name) return 1; - else return -1; + var newIndexData = collection.getIndexes().sort(function(a, b) { + if (a.name > b.name) + return 1; + else + return -1; }); for (var i = 0; i < newIndexData.length; i++) { assert.docEq(_indexData[i], newIndexData[i], "indexes not equal"); } // Save the data for this collection for later comparison - var newCollectionData = collection.find().sort({"_id":1}).toArray(); + var newCollectionData = collection.find().sort({"_id": 1}).toArray(); for (var i = 0; i < newCollectionData.length; i++) { assert.docEq(_collectionData[i], newCollectionData[i], "data not equal"); } @@ -130,52 +133,59 @@ function CollectionDataValidator() { // Tests of the functions and classes in this file function collectionDataValidatorTests() { - // TODO: These tests are hackish and depend on implementation details, but they are good enough // for now to convince us that the CollectionDataValidator is actually checking something var myValidator; var myGenerator; var collection; - myGenerator = new CollectionDataGenerator({ "capped" : true }); + myGenerator = new CollectionDataGenerator({"capped": true}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); - db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { return key.a != null; })[0]); - assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection"); - - - myGenerator = new CollectionDataGenerator({ "capped" : true }); + db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { + return key.a != null; + })[0]); + assert.throws(myValidator.validateCollectionData, + [collection], + "Validation function should have thrown since we modified the collection"); + + myGenerator = new CollectionDataGenerator({"capped": true}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); - db.test.update({_id:0}, {dummy:1}); - assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection"); + db.test.update({_id: 0}, {dummy: 1}); + assert.throws(myValidator.validateCollectionData, + [collection], + "Validation function should have thrown since we modified the collection"); - - myGenerator = new CollectionDataGenerator({ "capped" : true }); + myGenerator = new CollectionDataGenerator({"capped": true}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); assert(myValidator.validateCollectionData(collection), "Validation function failed"); - myGenerator = new CollectionDataGenerator({ "capped" : false }); + myGenerator = new CollectionDataGenerator({"capped": false}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); - db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { return key.a != null; })[0]); - assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection"); - - - myGenerator = new CollectionDataGenerator({ "capped" : false }); + db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { + return key.a != null; + })[0]); + assert.throws(myValidator.validateCollectionData, + [collection], + "Validation function should have thrown since we modified the collection"); + + myGenerator = new CollectionDataGenerator({"capped": false}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); - db.test.update({_id:0}, {dummy:1}); - assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection"); - + db.test.update({_id: 0}, {dummy: 1}); + assert.throws(myValidator.validateCollectionData, + [collection], + "Validation function should have thrown since we modified the collection"); - myGenerator = new CollectionDataGenerator({ "capped" : false }); + myGenerator = new CollectionDataGenerator({"capped": false}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); diff --git a/jstests/multiVersion/libs/verify_versions.js b/jstests/multiVersion/libs/verify_versions.js index 89641b5c493..f34b28b9ee5 100644 --- a/jstests/multiVersion/libs/verify_versions.js +++ b/jstests/multiVersion/libs/verify_versions.js @@ -3,7 +3,7 @@ */ Mongo.prototype.getBinVersion = function() { - var result = this.getDB( "admin" ).runCommand({ serverStatus : 1 }); + var result = this.getDB("admin").runCommand({serverStatus: 1}); return result.version; }; @@ -12,28 +12,26 @@ assert.binVersion = function(mongo, version) { var currVersion = mongo.getBinVersion(); assert(MongoRunner.areBinVersionsTheSame(MongoRunner.getBinVersionFor(currVersion), MongoRunner.getBinVersionFor(version)), - "version " + version + " (" + MongoRunner.getBinVersionFor(version) + ")" + - " is not the same as " + currVersion); + "version " + version + " (" + MongoRunner.getBinVersionFor(version) + ")" + + " is not the same as " + currVersion); }; - // Compares an array of desired versions and an array of found versions, // looking for versions not found assert.allBinVersions = function(versionsWanted, versionsFound) { - + for (var i = 0; i < versionsWanted.length; i++) { var version = versionsWanted[i]; var found = false; for (var j = 0; j < versionsFound.length; j++) { - if (MongoRunner.areBinVersionsTheSame(version, - versionsFound[j])) { + if (MongoRunner.areBinVersionsTheSame(version, versionsFound[j])) { found = true; break; } } - assert(found, "could not find version " + - version + " (" + MongoRunner.getBinVersionFor(version) + ")" + - " in " + versionsFound); + assert(found, + "could not find version " + version + " (" + MongoRunner.getBinVersionFor(version) + + ")" + " in " + versionsFound); } }; diff --git a/jstests/multiVersion/migration_between_mixed_version_mongods.js b/jstests/multiVersion/migration_between_mixed_version_mongods.js index 9ffd9f65d38..12e9c6d2628 100644 --- a/jstests/multiVersion/migration_between_mixed_version_mongods.js +++ b/jstests/multiVersion/migration_between_mixed_version_mongods.js @@ -7,91 +7,99 @@ load("./jstests/multiVersion/libs/verify_versions.js"); (function() { -"use strict"; - -var options = {shards: [{binVersion : "last-stable"}, - {binVersion : "last-stable"}, - {binVersion : "latest"}, - {binVersion : "latest"}], - mongos: 1, - other: {mongosOptions: {binVersion : "last-stable"}} -}; - -var st = new ShardingTest(options); - -assert.binVersion(st.shard0, "last-stable"); -assert.binVersion(st.shard1, "last-stable"); -assert.binVersion(st.shard2, "latest"); -assert.binVersion(st.shard3, "latest"); -assert.binVersion(st.s0, "last-stable"); - -var mongos = st.s0, - admin = mongos.getDB('admin'), - shards = mongos.getCollection('config.shards').find().toArray(), - - fooDB = "fooTest", - fooNS = fooDB + ".foo", - fooColl = mongos.getCollection(fooNS), - fooDonor = st.shard0, - fooRecipient = st.shard2, - fooDonorColl = fooDonor.getCollection(fooNS), - fooRecipientColl = fooRecipient.getCollection(fooNS), - - barDB = "barTest", - barNS = barDB + ".foo", - barColl = mongos.getCollection(barNS), - barDonor = st.shard3, - barRecipient = st.shard1, - barDonorColl = barDonor.getCollection(barNS), - barRecipientColl = barRecipient.getCollection(barNS); - -assert.commandWorked(admin.runCommand({enableSharding: fooDB})); -assert.commandWorked(admin.runCommand({enableSharding: barDB})); -st.ensurePrimaryShard(fooDB, shards[0]._id); -st.ensurePrimaryShard(barDB, shards[3]._id); - -assert.commandWorked(admin.runCommand({shardCollection: fooNS, key: {a: 1}})); -assert.commandWorked(admin.runCommand({split: fooNS, middle: {a: 10}})); -assert.commandWorked(admin.runCommand({shardCollection: barNS, key: {a: 1}})); -assert.commandWorked(admin.runCommand({split: barNS, middle: {a: 10}})); - -fooColl.insert({a: 0}); -assert.eq(null, fooColl.getDB().getLastError()); -fooColl.insert({a: 10}); -assert.eq(null, fooColl.getDB().getLastError()); -assert.eq(0, fooRecipientColl.count()); -assert.eq(2, fooDonorColl.count()); -assert.eq(2, fooColl.count()); - -barColl.insert({a: 0}); -assert.eq(null, barColl.getDB().getLastError()); -barColl.insert({a: 10}); -assert.eq(null, barColl.getDB().getLastError()); -assert.eq(0, barRecipientColl.count()); -assert.eq(2, barDonorColl.count()); -assert.eq(2, barColl.count()); - -/** - * Perform two migrations: - * shard0 (last-stable) -> foo chunk -> shard2 (latest) - * shard3 (latest) -> bar chunk -> shard1 (last-stable) - */ - -assert.commandWorked(admin.runCommand({moveChunk: fooNS, find: {a: 10}, to: shards[2]._id})); -assert.commandWorked(admin.runCommand({moveChunk: barNS, find: {a: 10}, to: shards[1]._id})); -assert.eq(1, fooRecipientColl.count(), "Foo collection migration failed. " + - "Last-stable -> latest mongod version migration failure."); -assert.eq(1, fooDonorColl.count(), "Foo donor lost its document. " + - "Last-stable -> latest mongod version migration failure."); -assert.eq(2, fooColl.count(), "Incorrect number of documents in foo collection. " + - "Last-stable -> latest mongod version migration failure."); -assert.eq(1, barRecipientColl.count(), "Bar collection migration failed. " + - "Latest -> last-stable mongod version migration failure."); -assert.eq(1, barDonorColl.count(), "Bar donor lost its document. " + - "Latest -> last-stable mongod version migration failure."); -assert.eq(2, barColl.count(), "Incorrect number of documents in bar collection. " + - "Latest -> last-stable mongod version migration failure."); - -st.stop(); + "use strict"; + + var options = { + shards: [ + {binVersion: "last-stable"}, + {binVersion: "last-stable"}, + {binVersion: "latest"}, + {binVersion: "latest"} + ], + mongos: 1, + other: {mongosOptions: {binVersion: "last-stable"}} + }; + + var st = new ShardingTest(options); + + assert.binVersion(st.shard0, "last-stable"); + assert.binVersion(st.shard1, "last-stable"); + assert.binVersion(st.shard2, "latest"); + assert.binVersion(st.shard3, "latest"); + assert.binVersion(st.s0, "last-stable"); + + var mongos = st.s0, admin = mongos.getDB('admin'), + shards = mongos.getCollection('config.shards').find().toArray(), + + fooDB = "fooTest", fooNS = fooDB + ".foo", fooColl = mongos.getCollection(fooNS), + fooDonor = st.shard0, fooRecipient = st.shard2, + fooDonorColl = fooDonor.getCollection(fooNS), + fooRecipientColl = fooRecipient.getCollection(fooNS), + + barDB = "barTest", barNS = barDB + ".foo", barColl = mongos.getCollection(barNS), + barDonor = st.shard3, barRecipient = st.shard1, + barDonorColl = barDonor.getCollection(barNS), + barRecipientColl = barRecipient.getCollection(barNS); + + assert.commandWorked(admin.runCommand({enableSharding: fooDB})); + assert.commandWorked(admin.runCommand({enableSharding: barDB})); + st.ensurePrimaryShard(fooDB, shards[0]._id); + st.ensurePrimaryShard(barDB, shards[3]._id); + + assert.commandWorked(admin.runCommand({shardCollection: fooNS, key: {a: 1}})); + assert.commandWorked(admin.runCommand({split: fooNS, middle: {a: 10}})); + assert.commandWorked(admin.runCommand({shardCollection: barNS, key: {a: 1}})); + assert.commandWorked(admin.runCommand({split: barNS, middle: {a: 10}})); + + fooColl.insert({a: 0}); + assert.eq(null, fooColl.getDB().getLastError()); + fooColl.insert({a: 10}); + assert.eq(null, fooColl.getDB().getLastError()); + assert.eq(0, fooRecipientColl.count()); + assert.eq(2, fooDonorColl.count()); + assert.eq(2, fooColl.count()); + + barColl.insert({a: 0}); + assert.eq(null, barColl.getDB().getLastError()); + barColl.insert({a: 10}); + assert.eq(null, barColl.getDB().getLastError()); + assert.eq(0, barRecipientColl.count()); + assert.eq(2, barDonorColl.count()); + assert.eq(2, barColl.count()); + + /** + * Perform two migrations: + * shard0 (last-stable) -> foo chunk -> shard2 (latest) + * shard3 (latest) -> bar chunk -> shard1 (last-stable) + */ + + assert.commandWorked(admin.runCommand({moveChunk: fooNS, find: {a: 10}, to: shards[2]._id})); + assert.commandWorked(admin.runCommand({moveChunk: barNS, find: {a: 10}, to: shards[1]._id})); + assert.eq(1, + fooRecipientColl.count(), + "Foo collection migration failed. " + + "Last-stable -> latest mongod version migration failure."); + assert.eq(1, + fooDonorColl.count(), + "Foo donor lost its document. " + + "Last-stable -> latest mongod version migration failure."); + assert.eq(2, + fooColl.count(), + "Incorrect number of documents in foo collection. " + + "Last-stable -> latest mongod version migration failure."); + assert.eq(1, + barRecipientColl.count(), + "Bar collection migration failed. " + + "Latest -> last-stable mongod version migration failure."); + assert.eq(1, + barDonorColl.count(), + "Bar donor lost its document. " + + "Latest -> last-stable mongod version migration failure."); + assert.eq(2, + barColl.count(), + "Incorrect number of documents in bar collection. " + + "Latest -> last-stable mongod version migration failure."); + + st.stop(); })(); diff --git a/jstests/multiVersion/minor_version_downgrade_replset.js b/jstests/multiVersion/minor_version_downgrade_replset.js index e91c22250ac..e0cc1fe5812 100644 --- a/jstests/multiVersion/minor_version_downgrade_replset.js +++ b/jstests/multiVersion/minor_version_downgrade_replset.js @@ -9,9 +9,11 @@ var oldVersion = "3.2.1"; var newVersion = "latest"; var name = "replsetdowngrade"; -var nodes = {n1: {binVersion: newVersion}, - n2: {binVersion: newVersion}, - n3: {binVersion: newVersion}}; +var nodes = { + n1: {binVersion: newVersion}, + n2: {binVersion: newVersion}, + n3: {binVersion: newVersion} +}; var rst = new ReplSetTest({name: name, nodes: nodes, nodeOptions: {storageEngine: 'mmapv1'}}); rst.startSet(); @@ -23,7 +25,7 @@ var primary = rst.getPrimary(); var coll = "test.foo"; jsTest.log("Inserting documents into collection."); -for (var i=0; i<10; i++) { +for (var i = 0; i < 10; i++) { primary.getCollection(coll).insert({_id: i, str: "hello world"}); } @@ -40,7 +42,7 @@ jsTest.log("Starting parallel operations during downgrade.."); var joinFindInsert = startParallelOps(primary, insertDocuments, [rst.getURL(), coll]); jsTest.log("Downgrading replica set.."); -rst.upgradeSet({ binVersion: oldVersion }); +rst.upgradeSet({binVersion: oldVersion}); jsTest.log("Downgrade complete."); primary = rst.getPrimary(); diff --git a/jstests/multiVersion/minor_version_tags_new_old_new.js b/jstests/multiVersion/minor_version_tags_new_old_new.js index bddc283558a..f39b3da4c68 100644 --- a/jstests/multiVersion/minor_version_tags_new_old_new.js +++ b/jstests/multiVersion/minor_version_tags_new_old_new.js @@ -5,11 +5,13 @@ // 3.2.1 is the final version to use the old style replSetUpdatePosition command. var oldVersion = "3.2.1"; var newVersion = "latest"; - var nodes = { n1 : { binVersion : newVersion }, - n2 : { binVersion : oldVersion }, - n3 : { binVersion : newVersion }, - n4 : { binVersion : oldVersion }, - n5 : { binVersion : newVersion } }; + var nodes = { + n1: {binVersion: newVersion}, + n2: {binVersion: oldVersion}, + n3: {binVersion: newVersion}, + n4: {binVersion: oldVersion}, + n5: {binVersion: newVersion} + }; var host = getHostName(); var name = 'tags'; @@ -19,63 +21,62 @@ var port = replTest.ports; replTest.initiate({ _id: name, - members : [ + members: [ { - _id: 0, - host: nodes[0], - tags: { - server: '0', - dc: 'ny', - ny: '1', - rack: 'ny.rk1', - }, + _id: 0, + host: nodes[0], + tags: { + server: '0', + dc: 'ny', + ny: '1', + rack: 'ny.rk1', + }, }, { - _id: 1, - host: nodes[1], - priority: 2, - tags: { - server: '1', - dc: 'ny', - ny: '2', - rack: 'ny.rk1', - }, + _id: 1, + host: nodes[1], + priority: 2, + tags: { + server: '1', + dc: 'ny', + ny: '2', + rack: 'ny.rk1', + }, }, { - _id: 2, - host: nodes[2], - priority: 3, - tags: { - server: '2', - dc: 'ny', - ny: '3', - rack: 'ny.rk2', - 2: 'this', - }, + _id: 2, + host: nodes[2], + priority: 3, + tags: { + server: '2', + dc: 'ny', + ny: '3', + rack: 'ny.rk2', 2: 'this', + }, }, { - _id: 3, - host: nodes[3], - tags: { - server: '3', - dc: 'sf', - sf: '1', - rack: 'sf.rk1', - }, + _id: 3, + host: nodes[3], + tags: { + server: '3', + dc: 'sf', + sf: '1', + rack: 'sf.rk1', + }, }, { - _id: 4, - host: nodes[4], - tags: { - server: '4', - dc: 'sf', - sf: '2', - rack: 'sf.rk2', - }, + _id: 4, + host: nodes[4], + tags: { + server: '4', + dc: 'sf', + sf: '2', + rack: 'sf.rk2', + }, }, ], - settings : { - getLastErrorModes : { + settings: { + getLastErrorModes: { '2 dc and 3 server': { dc: 2, server: 3, @@ -108,7 +109,9 @@ replTest.waitForState(replTest.nodes[nodeId], ReplSetTest.State.PRIMARY, 60 * 1000); primary = replTest.getPrimary(); primary.forceWriteMode('commands'); - var writeConcern = {writeConcern: {w: expectedWritableNodes, wtimeout: 30 * 1000}}; + var writeConcern = { + writeConcern: {w: expectedWritableNodes, wtimeout: 30 * 1000} + }; assert.writeOK(primary.getDB('foo').bar.insert({x: 100}, writeConcern)); return primary; }; @@ -133,7 +136,9 @@ jsTestLog('partitions: nodes with each set of brackets [N1, N2, N3] form a complete network.'); jsTestLog('partitions: [0-1-2] [3] [4] (only nodes 0 and 1 can replicate from primary node 2'); - var doc = {x: 1}; + var doc = { + x: 1 + }; // This timeout should be shorter in duration than the server parameter maxSyncSourceLagSecs. // Some writes are expected to block for this 'timeout' duration before failing. @@ -146,15 +151,20 @@ primary = ensurePrimary(2, 3); jsTestLog('Non-existent write concern should be rejected.'); - options = {writeConcern: {w: 'blahblah', wtimeout: timeout}}; + options = { + writeConcern: {w: 'blahblah', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); var result = assert.writeError(primary.getDB('foo').bar.insert(doc, options)); assert.neq(null, result.getWriteConcernError()); - assert.eq(ErrorCodes.UnknownReplWriteConcern, result.getWriteConcernError().code, + assert.eq(ErrorCodes.UnknownReplWriteConcern, + result.getWriteConcernError().code, tojson(result.getWriteConcernError())); jsTestLog('Write concern "3 or 4" should fail - 3 and 4 are not connected to the primary.'); - var options = {writeConcern: {w: '3 or 4', wtimeout: timeout}}; + var options = { + writeConcern: {w: '3 or 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); result = primary.getDB('foo').bar.insert(doc, options); assert.neq(null, result.getWriteConcernError()); @@ -167,12 +177,16 @@ jsTestLog('Write concern "3 or 4" should work - 4 is now connected to the primary ' + primary.host + ' via node 1 ' + replTest.nodes[1].host); - options = {writeConcern: {w: '3 or 4', wtimeout: timeout}}; + options = { + writeConcern: {w: '3 or 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "3 and 4" should fail - 3 is not connected to the primary.'); - options = {writeConcern: {w: '3 and 4', wtimeout: timeout}}; + options = { + writeConcern: {w: '3 and 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); result = assert.writeError(primary.getDB('foo').bar.insert(doc, options)); assert.neq(null, result.getWriteConcernError()); @@ -187,23 +201,31 @@ jsTestLog('31003 should sync from 31004 (31024)'); jsTestLog('Write concern "3 and 4" should work - ' + 'nodes 3 and 4 are connected to primary via node 1.'); - options = {writeConcern: {w: '3 and 4', wtimeout: timeout}}; + options = { + writeConcern: {w: '3 and 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "2" - writes to primary only.'); - options = {writeConcern: {w: '2', wtimeout: 0}}; + options = { + writeConcern: {w: '2', wtimeout: 0} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "1 and 2"'); - options = {writeConcern: {w: '1 and 2', wtimeout: 0}}; + options = { + writeConcern: {w: '1 and 2', wtimeout: 0} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "2 dc and 3 server"'); primary = ensurePrimary(2, 5); - options = {writeConcern: {w: '2 dc and 3 server', wtimeout: timeout}}; + options = { + writeConcern: {w: '2 dc and 3 server', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); @@ -220,7 +242,7 @@ // Is this necessary when we partition node 2 off from the rest of the nodes? replTest.stop(2); jsTestLog('partitions: [0-1] [2] [1-3-4] ' + - '(all secondaries except down node 2 can replicate from new primary node 1)'); + '(all secondaries except down node 2 can replicate from new primary node 1)'); // Node 1 with slightly higher priority will take over. jsTestLog('1 must become primary here because otherwise the other members will take too ' + @@ -228,13 +250,17 @@ primary = ensurePrimary(1, 4); jsTestLog('Write concern "3 and 4" should still work with new primary node 1 ' + primary.host); - options = {writeConcern: {w: '3 and 4', wtimeout: timeout}}; + options = { + writeConcern: {w: '3 and 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "2" should fail because node 2 ' + replTest.nodes[2].host + ' is down.'); - options = {writeConcern: {w: '2', wtimeout: timeout}}; + options = { + writeConcern: {w: '2', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); result = assert.writeError(primary.getDB('foo').bar.insert(doc, options)); assert.neq(null, result.getWriteConcernError()); diff --git a/jstests/multiVersion/minor_version_tags_old_new_old.js b/jstests/multiVersion/minor_version_tags_old_new_old.js index d1de541acf2..056aab2972a 100644 --- a/jstests/multiVersion/minor_version_tags_old_new_old.js +++ b/jstests/multiVersion/minor_version_tags_old_new_old.js @@ -5,11 +5,13 @@ // 3.2.1 is the final version to use the old style replSetUpdatePosition command. var oldVersion = "3.2.1"; var newVersion = "latest"; - var nodes = { n1 : { binVersion : oldVersion }, - n2 : { binVersion : newVersion }, - n3 : { binVersion : oldVersion }, - n4 : { binVersion : newVersion }, - n5 : { binVersion : oldVersion } }; + var nodes = { + n1: {binVersion: oldVersion}, + n2: {binVersion: newVersion}, + n3: {binVersion: oldVersion}, + n4: {binVersion: newVersion}, + n5: {binVersion: oldVersion} + }; var host = getHostName(); var name = 'tags'; @@ -19,63 +21,62 @@ var port = replTest.ports; replTest.initiate({ _id: name, - members : [ + members: [ { - _id: 0, - host: nodes[0], - tags: { - server: '0', - dc: 'ny', - ny: '1', - rack: 'ny.rk1', - }, + _id: 0, + host: nodes[0], + tags: { + server: '0', + dc: 'ny', + ny: '1', + rack: 'ny.rk1', + }, }, { - _id: 1, - host: nodes[1], - priority: 2, - tags: { - server: '1', - dc: 'ny', - ny: '2', - rack: 'ny.rk1', - }, + _id: 1, + host: nodes[1], + priority: 2, + tags: { + server: '1', + dc: 'ny', + ny: '2', + rack: 'ny.rk1', + }, }, { - _id: 2, - host: nodes[2], - priority: 3, - tags: { - server: '2', - dc: 'ny', - ny: '3', - rack: 'ny.rk2', - 2: 'this', - }, + _id: 2, + host: nodes[2], + priority: 3, + tags: { + server: '2', + dc: 'ny', + ny: '3', + rack: 'ny.rk2', 2: 'this', + }, }, { - _id: 3, - host: nodes[3], - tags: { - server: '3', - dc: 'sf', - sf: '1', - rack: 'sf.rk1', - }, + _id: 3, + host: nodes[3], + tags: { + server: '3', + dc: 'sf', + sf: '1', + rack: 'sf.rk1', + }, }, { - _id: 4, - host: nodes[4], - tags: { - server: '4', - dc: 'sf', - sf: '2', - rack: 'sf.rk2', - }, + _id: 4, + host: nodes[4], + tags: { + server: '4', + dc: 'sf', + sf: '2', + rack: 'sf.rk2', + }, }, ], - settings : { - getLastErrorModes : { + settings: { + getLastErrorModes: { '2 dc and 3 server': { dc: 2, server: 3, @@ -108,7 +109,9 @@ replTest.waitForState(replTest.nodes[nodeId], ReplSetTest.State.PRIMARY, 60 * 1000); primary = replTest.getPrimary(); primary.forceWriteMode('commands'); - var writeConcern = {writeConcern: {w: expectedWritableNodes, wtimeout: 30 * 1000}}; + var writeConcern = { + writeConcern: {w: expectedWritableNodes, wtimeout: 30 * 1000} + }; assert.writeOK(primary.getDB('foo').bar.insert({x: 100}, writeConcern)); return primary; }; @@ -133,7 +136,9 @@ jsTestLog('partitions: nodes with each set of brackets [N1, N2, N3] form a complete network.'); jsTestLog('partitions: [0-1-2] [3] [4] (only nodes 0 and 1 can replicate from primary node 2'); - var doc = {x: 1}; + var doc = { + x: 1 + }; // This timeout should be shorter in duration than the server parameter maxSyncSourceLagSecs. // Some writes are expected to block for this 'timeout' duration before failing. @@ -146,15 +151,20 @@ primary = ensurePrimary(2, 3); jsTestLog('Non-existent write concern should be rejected.'); - options = {writeConcern: {w: 'blahblah', wtimeout: timeout}}; + options = { + writeConcern: {w: 'blahblah', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); var result = assert.writeError(primary.getDB('foo').bar.insert(doc, options)); assert.neq(null, result.getWriteConcernError()); - assert.eq(ErrorCodes.UnknownReplWriteConcern, result.getWriteConcernError().code, + assert.eq(ErrorCodes.UnknownReplWriteConcern, + result.getWriteConcernError().code, tojson(result.getWriteConcernError())); jsTestLog('Write concern "3 or 4" should fail - 3 and 4 are not connected to the primary.'); - var options = {writeConcern: {w: '3 or 4', wtimeout: timeout}}; + var options = { + writeConcern: {w: '3 or 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); result = primary.getDB('foo').bar.insert(doc, options); assert.neq(null, result.getWriteConcernError()); @@ -167,12 +177,16 @@ jsTestLog('Write concern "3 or 4" should work - 4 is now connected to the primary ' + primary.host + ' via node 1 ' + replTest.nodes[1].host); - options = {writeConcern: {w: '3 or 4', wtimeout: timeout}}; + options = { + writeConcern: {w: '3 or 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "3 and 4" should fail - 3 is not connected to the primary.'); - options = {writeConcern: {w: '3 and 4', wtimeout: timeout}}; + options = { + writeConcern: {w: '3 and 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); result = assert.writeError(primary.getDB('foo').bar.insert(doc, options)); assert.neq(null, result.getWriteConcernError()); @@ -187,23 +201,31 @@ jsTestLog('31003 should sync from 31004 (31024)'); jsTestLog('Write concern "3 and 4" should work - ' + 'nodes 3 and 4 are connected to primary via node 1.'); - options = {writeConcern: {w: '3 and 4', wtimeout: timeout}}; + options = { + writeConcern: {w: '3 and 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "2" - writes to primary only.'); - options = {writeConcern: {w: '2', wtimeout: 0}}; + options = { + writeConcern: {w: '2', wtimeout: 0} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "1 and 2"'); - options = {writeConcern: {w: '1 and 2', wtimeout: 0}}; + options = { + writeConcern: {w: '1 and 2', wtimeout: 0} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "2 dc and 3 server"'); primary = ensurePrimary(2, 5); - options = {writeConcern: {w: '2 dc and 3 server', wtimeout: timeout}}; + options = { + writeConcern: {w: '2 dc and 3 server', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); @@ -220,7 +242,7 @@ // Is this necessary when we partition node 2 off from the rest of the nodes? replTest.stop(2); jsTestLog('partitions: [0-1] [2] [1-3-4] ' + - '(all secondaries except down node 2 can replicate from new primary node 1)'); + '(all secondaries except down node 2 can replicate from new primary node 1)'); // Node 1 with slightly higher priority will take over. jsTestLog('1 must become primary here because otherwise the other members will take too ' + @@ -228,13 +250,17 @@ primary = ensurePrimary(1, 4); jsTestLog('Write concern "3 and 4" should still work with new primary node 1 ' + primary.host); - options = {writeConcern: {w: '3 and 4', wtimeout: timeout}}; + options = { + writeConcern: {w: '3 and 4', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); assert.writeOK(primary.getDB('foo').bar.insert(doc, options)); jsTestLog('Write concern "2" should fail because node 2 ' + replTest.nodes[2].host + ' is down.'); - options = {writeConcern: {w: '2', wtimeout: timeout}}; + options = { + writeConcern: {w: '2', wtimeout: timeout} + }; assert.writeOK(primary.getDB('foo').bar.insert(doc)); result = assert.writeError(primary.getDB('foo').bar.insert(doc, options)); assert.neq(null, result.getWriteConcernError()); diff --git a/jstests/multiVersion/minor_version_upgrade_replset.js b/jstests/multiVersion/minor_version_upgrade_replset.js index 1c153a1e675..7f784f5c100 100644 --- a/jstests/multiVersion/minor_version_upgrade_replset.js +++ b/jstests/multiVersion/minor_version_upgrade_replset.js @@ -2,85 +2,78 @@ // Tests upgrading a replica set // -load( './jstests/multiVersion/libs/multi_rs.js' ); -load( './jstests/libs/test_background_ops.js' ); +load('./jstests/multiVersion/libs/multi_rs.js'); +load('./jstests/libs/test_background_ops.js'); // 3.2.1 is the final version to use the old style replSetUpdatePosition command. var oldVersion = "3.2.1"; -var nodes = { n1 : { binVersion : oldVersion }, - n2 : { binVersion : oldVersion }, - a3 : { binVersion : oldVersion } }; +var nodes = { + n1: {binVersion: oldVersion}, + n2: {binVersion: oldVersion}, + a3: {binVersion: oldVersion} +}; -var rst = new ReplSetTest({ nodes : nodes }); +var rst = new ReplSetTest({nodes: nodes}); rst.startSet(); rst.initiate(); // Wait for a primary node... var primary = rst.getPrimary(); -var otherOpConn = new Mongo( rst.getURL() ); +var otherOpConn = new Mongo(rst.getURL()); var insertNS = "test.foo"; +jsTest.log("Starting parallel operations during upgrade..."); -jsTest.log( "Starting parallel operations during upgrade..." ); - -function findAndInsert( rsURL, coll ){ - - var coll = new Mongo( rsURL ).getCollection( coll + "" ); +function findAndInsert(rsURL, coll) { + var coll = new Mongo(rsURL).getCollection(coll + ""); var count = 0; - - jsTest.log( "Starting finds and inserts..." ); - - while( ! isFinished() ){ - - try{ - - coll.insert({ _id : count, hello : "world" }); - assert.eq( null, coll.getDB().getLastError() ); - assert.neq( null, coll.findOne({ _id : count }) ); - } - catch( e ){ - printjson( e ); + + jsTest.log("Starting finds and inserts..."); + + while (!isFinished()) { + try { + coll.insert({_id: count, hello: "world"}); + assert.eq(null, coll.getDB().getLastError()); + assert.neq(null, coll.findOne({_id: count})); + } catch (e) { + printjson(e); } - + count++; } - - jsTest.log( "Finished finds and inserts..." ); + + jsTest.log("Finished finds and inserts..."); return count; } -var joinFindInsert = - startParallelOps( primary, // The connection where the test info is passed and stored - findAndInsert, - [ rst.getURL(), insertNS ] ); - +var joinFindInsert = + startParallelOps(primary, // The connection where the test info is passed and stored + findAndInsert, + [rst.getURL(), insertNS]); -jsTest.log( "Upgrading replica set..." ); +jsTest.log("Upgrading replica set..."); -rst.upgradeSet({ binVersion: "latest" }); +rst.upgradeSet({binVersion: "latest"}); -jsTest.log( "Replica set upgraded." ); +jsTest.log("Replica set upgraded."); // Wait for primary var primary = rst.getPrimary(); -printjson( rst.status() ); - +printjson(rst.status()); // Allow more valid writes to go through -sleep( 10 * 1000 ); - +sleep(10 * 1000); joinFindInsert(); -var totalInserts = primary.getCollection( insertNS ).find().sort({ _id : -1 }).next()._id + 1; -var dataFound = primary.getCollection( insertNS ).count(); +var totalInserts = primary.getCollection(insertNS).find().sort({_id: -1}).next()._id + 1; +var dataFound = primary.getCollection(insertNS).count(); -jsTest.log( "Found " + dataFound + " docs out of " + tojson( totalInserts ) + " inserted." ); +jsTest.log("Found " + dataFound + " docs out of " + tojson(totalInserts) + " inserted."); -assert.gt( dataFound / totalInserts, 0.5 ); +assert.gt(dataFound / totalInserts, 0.5); rst.stopSet(); - diff --git a/jstests/multiVersion/mixed_storage_version_replication.js b/jstests/multiVersion/mixed_storage_version_replication.js index 89da0c5bcd6..34338765ed4 100644 --- a/jstests/multiVersion/mixed_storage_version_replication.js +++ b/jstests/multiVersion/mixed_storage_version_replication.js @@ -18,9 +18,20 @@ var RandomOps = { verbose: false, // 'Random' documents will have various combinations of these names mapping to these values fieldNames: ["a", "b", "c", "longerName", "numbered10", "dashed-name"], - fieldValues: [ true, false, 0, 44, -123, "", "String", [], [false, "x"], - ["array", 1, {doc: true}, new Date().getTime()], {}, - {embedded: "document", weird: ["values", 0, false]}, new Date().getTime() + fieldValues: [ + true, + false, + 0, + 44, + -123, + "", + "String", + [], + [false, "x"], + ["array", 1, {doc: true}, new Date().getTime()], + {}, + {embedded: "document", weird: ["values", 0, false]}, + new Date().getTime() ], /* @@ -35,7 +46,7 @@ var RandomOps = { while (x === 1.0) { // Would be out of bounds x = Random.rand(); } - var i = Math.floor(x*a.length); + var i = Math.floor(x * a.length); return a[i]; }, @@ -45,7 +56,7 @@ var RandomOps = { */ randomNewDoc: function() { var doc = {}; - for (var i = 0; i < Random.randInt(0,this.fieldNames.length); i++) { + for (var i = 0; i < Random.randInt(0, this.fieldNames.length); i++) { doc[this.randomChoice(this.fieldNames)] = this.randomChoice(this.fieldValues); } return doc; @@ -72,7 +83,9 @@ var RandomOps = { */ getRandomExistingCollection: function(conn) { var dbs = this.getCreatedDatabases(conn); - if (dbs.length === 0) { return null; } + if (dbs.length === 0) { + return null; + } var dbName = this.randomChoice(dbs); var db = conn.getDB(dbName); if (db.getCollectionNames().length <= 1) { @@ -89,7 +102,7 @@ var RandomOps = { try { var randIndex = Random.randInt(0, collection.find().count()); return collection.find().sort({$natural: 1}).skip(randIndex).limit(1)[0]; - } catch(e) { + } catch (e) { return undefined; } }, @@ -111,7 +124,9 @@ var RandomOps = { } } } - if (matched.length === 0) { return null; } + if (matched.length === 0) { + return null; + } return this.randomChoice(matched); }, @@ -140,11 +155,12 @@ var RandomOps = { printjson(doc); print("With write concern: " + writeConcern + " and journal: " + journal); } - var result = conn.getDB(db)[coll].insert(doc, - {writeConcern: {w: writeConcern}, - journal: journal}); + var result = + conn.getDB(db)[coll].insert(doc, {writeConcern: {w: writeConcern}, journal: journal}); assert.eq(result.ok, 1); - if (this.verbose) { print("done."); } + if (this.verbose) { + print("done."); + } }, /* @@ -168,10 +184,14 @@ var RandomOps = { } try { coll.remove(doc); - } catch(e) { - if (this.verbose) { print("Caught exception in remove: " + e); } + } catch (e) { + if (this.verbose) { + print("Caught exception in remove: " + e); + } + } + if (this.verbose) { + print("done."); } - if (this.verbose) { print("done."); } }, /* @@ -191,7 +211,9 @@ var RandomOps = { } var field = this.randomChoice(this.fieldNames); - var updateDoc = {$set: {}}; + var updateDoc = { + $set: {} + }; updateDoc.$set[field] = this.randomChoice(this.fieldValues); if (this.verbose) { print("Updating:"); @@ -202,10 +224,14 @@ var RandomOps = { // If multithreaded, doc might not exist anymore. try { coll.update(doc, updateDoc); - } catch(e) { - if (this.verbose) { print("Caught exception in update: " + e); } + } catch (e) { + if (this.verbose) { + print("Caught exception in update: " + e); + } + } + if (this.verbose) { + print("done."); } - if (this.verbose) { print("done."); } }, ////////////////////////////////////////////////////////////////////////////////// @@ -217,15 +243,18 @@ var RandomOps = { */ renameCollection: function(conn) { var coll = this.getRandomExistingCollection(conn); - if (coll === null) { return null; } + if (coll === null) { + return null; + } var newName = coll.getDB() + "." + new ObjectId().str; if (this.verbose) { print("renaming collection " + coll.getFullName() + " to " + newName); } assert.commandWorked( - conn.getDB("admin").runCommand({renameCollection: coll.getFullName(), to: newName}) - ); - if (this.verbose) { print("done."); } + conn.getDB("admin").runCommand({renameCollection: coll.getFullName(), to: newName})); + if (this.verbose) { + print("done."); + } }, /* @@ -233,15 +262,17 @@ var RandomOps = { */ dropDatabase: function(conn) { var dbs = this.getCreatedDatabases(conn); - if (dbs.length === 0) { return null; } + if (dbs.length === 0) { + return null; + } var dbName = this.randomChoice(dbs); if (this.verbose) { print("Dropping database " + dbName); } - assert.commandWorked( - conn.getDB(dbName).runCommand({dropDatabase: 1}) - ); - if (this.verbose) { print("done."); } + assert.commandWorked(conn.getDB(dbName).runCommand({dropDatabase: 1})); + if (this.verbose) { + print("done."); + } }, /* @@ -249,14 +280,16 @@ var RandomOps = { */ dropCollection: function(conn) { var coll = this.getRandomExistingCollection(conn); - if (coll === null) { return null; } + if (coll === null) { + return null; + } if (this.verbose) { print("Dropping collection " + coll.getFullName()); } - assert.commandWorked( - conn.getDB(coll.getDB()).runCommand({drop: coll.getName()}) - ); - if (this.verbose) { print("done."); } + assert.commandWorked(conn.getDB(coll.getDB()).runCommand({drop: coll.getName()})); + if (this.verbose) { + print("done."); + } }, /* @@ -264,14 +297,18 @@ var RandomOps = { */ createIndex: function(conn) { var coll = this.getRandomExistingCollection(conn); - if (coll === null) { return null; } + if (coll === null) { + return null; + } var index = {}; index[this.randomChoice(this.fieldNames)] = this.randomChoice([-1, 1]); if (this.verbose) { print("Adding index " + tojsononeline(index) + " to " + coll.getFullName()); } coll.ensureIndex(index); - if (this.verbose) { print("done."); } + if (this.verbose) { + print("done."); + } }, /* @@ -279,7 +316,9 @@ var RandomOps = { */ dropIndex: function(conn) { var coll = this.getRandomExistingCollection(conn); - if (coll === null) { return null; } + if (coll === null) { + return null; + } var index = this.randomChoice(coll.getIndices()); if (index.name === "_id_") { return null; // Don't drop that one. @@ -287,10 +326,10 @@ var RandomOps = { if (this.verbose) { print("Dropping index " + tojsononeline(index.key) + " from " + coll.getFullName()); } - assert.commandWorked( - coll.dropIndex(index.name) - ); - if (this.verbose) { print("done."); } + assert.commandWorked(coll.dropIndex(index.name)); + if (this.verbose) { + print("done."); + } }, /* @@ -298,14 +337,18 @@ var RandomOps = { */ collMod: function(conn) { var coll = this.getRandomExistingCollection(conn); - if (coll === null) { return null; } + if (coll === null) { + return null; + } var toggle = !coll.stats().userFlags; if (this.verbose) { print("Modifying usePowerOf2Sizes to " + toggle + " on collection " + coll.getFullName()); } conn.getDB(coll.getDB()).runCommand({collMod: coll.getName(), usePowerOf2Sizes: toggle}); - if (this.verbose) { print("done."); } + if (this.verbose) { + print("done."); + } }, /* @@ -316,14 +359,16 @@ var RandomOps = { return conn.getDB(dbName)[coll].isCapped(); }; var coll = this.getRandomCollectionWFilter(conn, isCapped); - if (coll === null) { return null; } + if (coll === null) { + return null; + } if (this.verbose) { print("Emptying capped collection: " + coll.getFullName()); } - assert.commandWorked( - conn.getDB(coll.getDB()).runCommand({emptycapped: coll.getName()}) - ); - if (this.verbose) { print("done."); } + assert.commandWorked(conn.getDB(coll.getDB()).runCommand({emptycapped: coll.getName()})); + if (this.verbose) { + print("done."); + } }, /* @@ -331,7 +376,9 @@ var RandomOps = { */ applyOps: function(conn) { // Check if there are any valid collections to choose from. - if (this.getRandomExistingCollection(conn) === null) { return null; } + if (this.getRandomExistingCollection(conn) === null) { + return null; + } var ops = []; // Insert between 1 and 10 things. for (var i = 0; i < Random.randInt(1, 10); i++) { @@ -346,10 +393,10 @@ var RandomOps = { print("Applying the following ops: "); printjson(ops); } - assert.commandWorked( - conn.getDB("admin").runCommand({applyOps: ops}) - ); - if (this.verbose) { print("done."); } + assert.commandWorked(conn.getDB("admin").runCommand({applyOps: ops})); + if (this.verbose) { + print("done."); + } }, /* @@ -357,16 +404,18 @@ var RandomOps = { */ createCollection: function(conn) { var dbs = this.getCreatedDatabases(conn); - if (dbs.length === 0) { return null; } + if (dbs.length === 0) { + return null; + } var dbName = this.randomChoice(dbs); var newName = new ObjectId().str; if (this.verbose) { print("Creating new collection: " + "dbName" + "." + newName); } - assert.commandWorked( - conn.getDB(dbName).runCommand({create: newName}) - ); - if (this.verbose) { print("done."); } + assert.commandWorked(conn.getDB(dbName).runCommand({create: newName})); + if (this.verbose) { + print("done."); + } }, /* @@ -377,14 +426,18 @@ var RandomOps = { return conn.getDB(dbName)[coll].isCapped(); }; var coll = this.getRandomCollectionWFilter(conn, isNotCapped); - if (coll === null) { return null; } + if (coll === null) { + return null; + } if (this.verbose) { print("Converting " + coll.getFullName() + " to a capped collection."); } assert.commandWorked( - conn.getDB(coll.getDB()).runCommand({convertToCapped: coll.getName(), size: 1024*1024}) - ); - if (this.verbose) { print("done."); } + conn.getDB(coll.getDB()) + .runCommand({convertToCapped: coll.getName(), size: 1024 * 1024})); + if (this.verbose) { + print("done."); + } }, appendOplogNote: function(conn) { @@ -393,9 +446,10 @@ var RandomOps = { print("Appending oplog note: " + note); } assert.commandWorked( - conn.getDB("admin").runCommand({appendOplogNote: note, data: {some: 'doc'}}) - ); - if (this.verbose) { print("done."); } + conn.getDB("admin").runCommand({appendOplogNote: note, data: {some: 'doc'}})); + if (this.verbose) { + print("done."); + } }, /* @@ -483,33 +537,32 @@ function assertDBsEq(db1, db2) { // We don't expect the entire local collection to be the same, not even the oplog, since // it's a capped collection. return; - } - else if (hash1.md5 != hash2.md5) { + } else if (hash1.md5 != hash2.md5) { for (var i = 0; i < Math.min(collNames1.length, collNames2.length); i++) { var collName = collNames1[i]; if (hash1.collections[collName] !== hash2.collections[collName]) { if (db1[collName].stats().capped) { if (!db2[collName].stats().capped) { success = false; - diffText += "\n" + collName + " is capped on " + host1 + " but not on " + - host2; - } - else { + diffText += + "\n" + collName + " is capped on " + host1 + " but not on " + host2; + } else { // Skip capped collections. They are not expected to be the same from host // to host. continue; } - } - else { + } else { success = false; - diffText += "\n" + collName + " differs: " + - getCollectionDiff(db1, db2, collName); + diffText += + "\n" + collName + " differs: " + getCollectionDiff(db1, db2, collName); } } } } - assert.eq(success, true, "Database " + db1.getName() + " differs on " + host1 + " and " + - host2 + "\nCollections: " + collNames1 + " vs. " + collNames2 + "\n" + diffText); + assert.eq(success, + true, + "Database " + db1.getName() + " differs on " + host1 + " and " + host2 + + "\nCollections: " + collNames1 + " vs. " + collNames2 + "\n" + diffText); } /* @@ -535,9 +588,20 @@ function assertSameData(primary, conns) { */ function startCmds(randomOps, host) { var ops = [ - "insert", "remove", "update", "renameCollection", "dropDatabase", - "dropCollection", "createIndex", "dropIndex", "collMod", "emptyCapped", "applyOps", - "createCollection", "convertToCapped", "appendOplogNote" + "insert", + "remove", + "update", + "renameCollection", + "dropDatabase", + "dropCollection", + "createIndex", + "dropIndex", + "collMod", + "emptyCapped", + "applyOps", + "createCollection", + "convertToCapped", + "appendOplogNote" ]; var m = new Mongo(host); var numOps = 200; @@ -593,9 +657,10 @@ function doMultiThreadedWork(primary, numThreads) { // Create a replica set with 2 nodes of each of the types below, plus one arbiter. var oldVersion = "last-stable"; var newVersion = "latest"; - var setups = [{binVersion: newVersion, storageEngine: 'mmapv1'}, - {binVersion: newVersion, storageEngine: 'wiredTiger'}, - {binVersion: oldVersion} + var setups = [ + {binVersion: newVersion, storageEngine: 'mmapv1'}, + {binVersion: newVersion, storageEngine: 'wiredTiger'}, + {binVersion: oldVersion} ]; var nodes = {}; var node = 0; @@ -606,14 +671,18 @@ function doMultiThreadedWork(primary, numThreads) { nodes["n" + node] = setups[i]; node++; } - nodes["n" + 2 * setups.length] = {arbiter: true}; + nodes["n" + 2 * setups.length] = { + arbiter: true + }; var replTest = new ReplSetTest({nodes: nodes, name: name}); var conns = replTest.startSet(); var config = replTest.getReplSetConfig(); // Make sure everyone is syncing from the primary, to ensure we have all combinations of // primary/secondary syncing. - config.settings = {chainingAllowed: false}; + config.settings = { + chainingAllowed: false + }; config.protocolVersion = 0; replTest.initiate(config); // Ensure all are synced. @@ -624,32 +693,31 @@ function doMultiThreadedWork(primary, numThreads) { // Keep track of the indices of different types of primaries. // We'll rotate to get a primary of each type. - var possiblePrimaries = [0,2,4]; + var possiblePrimaries = [0, 2, 4]; var highestPriority = 2; while (possiblePrimaries.length > 0) { config = primary.getDB("local").system.replset.findOne(); var primaryIndex = RandomOps.randomChoice(possiblePrimaries); - print("TRANSITIONING to " + tojsononeline(setups[primaryIndex/2]) + " as primary"); + print("TRANSITIONING to " + tojsononeline(setups[primaryIndex / 2]) + " as primary"); // Remove chosen type from future choices. removeFromArray(primaryIndex, possiblePrimaries); config.members[primaryIndex].priority = highestPriority; if (config.version === undefined) { config.version = 2; - } - else { + } else { config.version++; } highestPriority++; printjson(config); try { primary.getDB("admin").runCommand({replSetReconfig: config}); - } - catch(e) { + } catch (e) { // Expected to fail, as we'll have to reconnect. } - replTest.awaitReplication(60000); // 2 times the election period. + replTest.awaitReplication(60000); // 2 times the election period. assert.soon(primaryChanged(conns, replTest, primaryIndex), - "waiting for higher priority primary to be elected", 100000); + "waiting for higher priority primary to be elected", + 100000); print("New primary elected, doing a bunch of work"); primary = replTest.getPrimary(); doMultiThreadedWork(primary, 10); diff --git a/jstests/multiVersion/mmapv1_overrides_default_storage_engine.js b/jstests/multiVersion/mmapv1_overrides_default_storage_engine.js index 9cad40c23bd..7e6d61e9f1d 100644 --- a/jstests/multiVersion/mmapv1_overrides_default_storage_engine.js +++ b/jstests/multiVersion/mmapv1_overrides_default_storage_engine.js @@ -7,18 +7,18 @@ var testCases = [ { - binVersion: '2.6', + binVersion: '2.6', }, { - binVersion: '2.6', - directoryperdb: '', + binVersion: '2.6', + directoryperdb: '', }, { - binVersion: '3.0', + binVersion: '3.0', }, { - binVersion: '3.0', - directoryperdb: '', + binVersion: '3.0', + directoryperdb: '', }, ]; @@ -26,11 +26,11 @@ // --storageEngine=mmapv1 is explicitly specified. testCases.forEach(function(testCase) { [null, 'mmapv1'].forEach(function(storageEngine) { - jsTest.log('Upgrading from a ' + testCase.binVersion + ' instance with options=' - + tojson(testCase) + ' to the latest version. This should succeed when the' - + ' latest version ' - + (storageEngine ? ('explicitly specifies --storageEngine=' + storageEngine) - : 'omits the --storageEngine flag')); + jsTest.log('Upgrading from a ' + testCase.binVersion + ' instance with options=' + + tojson(testCase) + ' to the latest version. This should succeed when the' + + ' latest version ' + + (storageEngine ? ('explicitly specifies --storageEngine=' + storageEngine) + : 'omits the --storageEngine flag')); var dbpath = MongoRunner.dataPath + 'mmapv1_overrides_default_storage_engine'; resetDbpath(dbpath); @@ -43,8 +43,8 @@ // Start the old version. var mongodOptions = Object.merge(defaultOptions, testCase); var conn = MongoRunner.runMongod(mongodOptions); - assert.neq(null, conn, - 'mongod was unable to start up with options ' + tojson(mongodOptions)); + assert.neq( + null, conn, 'mongod was unable to start up with options ' + tojson(mongodOptions)); assert.commandWorked(conn.getDB('test').runCommand({ping: 1})); MongoRunner.stopMongod(conn); @@ -57,8 +57,8 @@ mongodOptions.directoryperdb = testCase.directoryperdb; } conn = MongoRunner.runMongod(mongodOptions); - assert.neq(null, conn, - 'mongod was unable to start up with options ' + tojson(mongodOptions)); + assert.neq( + null, conn, 'mongod was unable to start up with options ' + tojson(mongodOptions)); assert.commandWorked(conn.getDB('test').runCommand({ping: 1})); MongoRunner.stopMongod(conn); }); @@ -66,9 +66,9 @@ // The mongod should not start up when --storageEngine=wiredTiger is specified. testCases.forEach(function(testCase) { - jsTest.log('Upgrading from a ' + testCase.binVersion + ' instance with options=' - + tojson(testCase) + ' to the latest version. This should fail when the latest' - + ' version specifies --storageEngine=wiredTiger'); + jsTest.log('Upgrading from a ' + testCase.binVersion + ' instance with options=' + + tojson(testCase) + ' to the latest version. This should fail when the latest' + + ' version specifies --storageEngine=wiredTiger'); var dbpath = MongoRunner.dataPath + 'mmapv1_overrides_default_storage_engine'; resetDbpath(dbpath); @@ -81,16 +81,17 @@ // Start the old version. var mongodOptions = Object.merge(defaultOptions, testCase); var conn = MongoRunner.runMongod(mongodOptions); - assert.neq(null, conn, - 'mongod was unable to start up with options ' + tojson(mongodOptions)); + assert.neq( + null, conn, 'mongod was unable to start up with options ' + tojson(mongodOptions)); assert.commandWorked(conn.getDB('test').runCommand({ping: 1})); MongoRunner.stopMongod(conn); // Start the newest version. mongodOptions = Object.extend({storageEngine: 'wiredTiger'}, defaultOptions); conn = MongoRunner.runMongod(mongodOptions); - assert.eq(null, conn, - 'mongod should not have been able to start up with options ' - + tojson(mongodOptions)); + assert.eq( + null, + conn, + 'mongod should not have been able to start up with options ' + tojson(mongodOptions)); }); }()); diff --git a/jstests/multiVersion/partial_index_upgrade.js b/jstests/multiVersion/partial_index_upgrade.js index 938db4759c5..474252b4dc8 100644 --- a/jstests/multiVersion/partial_index_upgrade.js +++ b/jstests/multiVersion/partial_index_upgrade.js @@ -9,14 +9,14 @@ var testCases = [ { - partialFilterExpression: 'not an object', + partialFilterExpression: 'not an object', }, { - partialFilterExpression: {field: {$regex: 'not a supported operator'}}, + partialFilterExpression: {field: {$regex: 'not a supported operator'}}, }, { - partialFilterExpression: {field: 'cannot be combined with sparse=true'}, - sparse: true, + partialFilterExpression: {field: 'cannot be combined with sparse=true'}, + sparse: true, }, ]; @@ -36,8 +36,8 @@ // Start the old version. var oldVersionOptions = Object.extend({binVersion: '3.0'}, defaultOptions); var conn = MongoRunner.runMongod(oldVersionOptions); - assert.neq(null, conn, 'mongod was unable to start up with options ' + - tojson(oldVersionOptions)); + assert.neq( + null, conn, 'mongod was unable to start up with options ' + tojson(oldVersionOptions)); // Use write commands in order to make assertions about the success of operations based on // the response from the server. @@ -48,18 +48,17 @@ // Start the newest version. conn = MongoRunner.runMongod(defaultOptions); - assert.eq(null, conn, 'mongod should not have been able to start up when an index with' + - ' options ' + tojson(indexOptions) + ' exists'); + assert.eq(null, + conn, + 'mongod should not have been able to start up when an index with' + + ' options ' + tojson(indexOptions) + ' exists'); }); // Create a replica set with a primary running 3.0 and a secondary running the latest version. // The secondary should terminate when the command to build an invalid partial index replicates. testCases.forEach(function(indexOptions) { var replSetName = 'partial_index_replset'; - var nodes = [ - {binVersion: '3.0'}, - {binVersion: 'latest'}, - ]; + var nodes = [{binVersion: '3.0'}, {binVersion: 'latest'}, ]; var rst = new ReplSetTest({name: replSetName, nodes: nodes}); @@ -85,16 +84,18 @@ // Verify that the secondary running the latest version terminates when the command to build // an invalid partial index replicates. - assert.soon(function() { - try { - secondaryLatest.getDB('test').runCommand({ping: 1}); - } catch (e) { - return true; - } - return false; - }, 'secondary should have terminated due to request to build an invalid partial index' + - ' with options ' + tojson(indexOptions)); - - rst.stopSet(undefined, undefined, { allowedExitCodes: [ MongoRunner.EXIT_ABRUPT ] }); + assert.soon( + function() { + try { + secondaryLatest.getDB('test').runCommand({ping: 1}); + } catch (e) { + return true; + } + return false; + }, + 'secondary should have terminated due to request to build an invalid partial index' + + ' with options ' + tojson(indexOptions)); + + rst.stopSet(undefined, undefined, {allowedExitCodes: [MongoRunner.EXIT_ABRUPT]}); }); })(); diff --git a/jstests/multiVersion/transitioning_to_and_from_WT.js b/jstests/multiVersion/transitioning_to_and_from_WT.js index 5c56e96919d..97ac9b7af74 100644 --- a/jstests/multiVersion/transitioning_to_and_from_WT.js +++ b/jstests/multiVersion/transitioning_to_and_from_WT.js @@ -7,10 +7,11 @@ jsTestLog("Setting up initial data set with the last stable version of mongod"); - var toolTest = new ToolTest('transitioning_to_and_from_WT', { - binVersion: MongoRunner.getBinVersionFor("last-stable"), - storageEngine: "mmapv1", - }); + var toolTest = new ToolTest('transitioning_to_and_from_WT', + { + binVersion: MongoRunner.getBinVersionFor("last-stable"), + storageEngine: "mmapv1", + }); toolTest.dbpath = toolTest.root + "/original/"; resetDbpath(toolTest.dbpath); @@ -54,62 +55,62 @@ var modes = [ // to the latest version with wiredTiger { - binVersion: "latest", - storageEngine: "wiredTiger", + binVersion: "latest", + storageEngine: "wiredTiger", }, // back to the last stable version with mmapv1 { - binVersion: "last-stable", - storageEngine: "mmapv1", + binVersion: "last-stable", + storageEngine: "mmapv1", }, // to the latest version with mmapv1 { - binVersion: "latest", - storageEngine: "mmapv1", + binVersion: "latest", + storageEngine: "mmapv1", }, // to latest version with wiredTiger { - binVersion: "latest", - storageEngine: "wiredTiger", + binVersion: "latest", + storageEngine: "wiredTiger", }, // back to the latest version with mmapv1 { - binVersion: "latest", - storageEngine: "mmapv1", + binVersion: "latest", + storageEngine: "mmapv1", }, // to the last stable version with mmapv1 and directory per db { - binVersion: "last-stable", - storageEngine: "mmapv1", - directoryperdb: "", + binVersion: "last-stable", + storageEngine: "mmapv1", + directoryperdb: "", }, // to the latest version with wiredTiger { - binVersion: "latest", - storageEngine: "wiredTiger", + binVersion: "latest", + storageEngine: "wiredTiger", }, // back to the last stable version with mmapv1 and directory per db { - binVersion: "last-stable", - storageEngine: "mmapv1", - directoryperdb: "", + binVersion: "last-stable", + storageEngine: "mmapv1", + directoryperdb: "", }, // to latest version with mmapv1 and directory per db { - binVersion: "latest", - storageEngine: "mmapv1", - directoryperdb: "", + binVersion: "latest", + storageEngine: "mmapv1", + directoryperdb: "", }, // to the latest with wiredTiger { - binVersion: "latest", - storageEngine: "wiredTiger", + binVersion: "latest", + storageEngine: "wiredTiger", }, // back to latest version with mmapv1 and directory per db { - binVersion: "latest", - storageEngine: "mmapv1", - directoryperdb: "", + binVersion: "latest", + storageEngine: "mmapv1", + directoryperdb: "", }, ]; @@ -129,8 +130,8 @@ // set up new node configuration info toolTest.options.binVersion = MongoRunner.getBinVersionFor(entry.binVersion); - toolTest.dbpath = toolTest.root + "/" + idx + "-" + entry.binVersion + "-" - + entry.storageEngine + "/"; + toolTest.dbpath = + toolTest.root + "/" + idx + "-" + entry.binVersion + "-" + entry.storageEngine + "/"; if (entry.hasOwnProperty("storageEngine")) { toolTest.options.storageEngine = entry.storageEngine; diff --git a/jstests/multiVersion/upgrade_cluster.js b/jstests/multiVersion/upgrade_cluster.js index 8049e716217..09a8c86d3d8 100644 --- a/jstests/multiVersion/upgrade_cluster.js +++ b/jstests/multiVersion/upgrade_cluster.js @@ -7,88 +7,86 @@ load('./jstests/multiVersion/libs/multi_cluster.js'); (function() { -/** - * @param isRSCluster {bool} use replica set shards. - */ -var runTest = function(isRSCluster) { -"use strict"; - -jsTest.log( "Starting" + ( isRSCluster ? " (replica set)" : "" ) + " cluster" + "..." ); - -var options = { - mongosOptions : { binVersion : "last-stable" }, - configOptions : { binVersion : "last-stable" }, - shardOptions : { binVersion : "last-stable" }, - - rsOptions : { binVersion : "last-stable" }, - rs : isRSCluster -}; - -var testCRUD = function(mongos) { - assert.commandWorked(mongos.getDB('test').runCommand({ dropDatabase: 1 })); - assert.commandWorked(mongos.getDB('unsharded').runCommand({ dropDatabase: 1 })); - - var unshardedDB = mongos.getDB('unshareded'); - assert.commandWorked(unshardedDB.runCommand({ insert: 'foo', documents: [{ x: 1 }]})); - assert.commandWorked(unshardedDB.runCommand({ update: 'foo', - updates: [{ q: { x: 1 }, - u: { $set: { y: 1 }}}]})); - var doc = unshardedDB.foo.findOne({ x: 1 }); - assert.eq(1, doc.y); - assert.commandWorked(unshardedDB.runCommand({ delete: 'foo', deletes: [{ q: { x: 1 }, - limit: 1 }]})); - doc = unshardedDB.foo.findOne(); - assert.eq(null, doc); - - assert.commandWorked(mongos.adminCommand({ enableSharding: 'test' })); - assert.commandWorked(mongos.adminCommand({ shardCollection: 'test.user', key: { x: 1 }})); - - var shardedDB = mongos.getDB('shareded'); - assert.commandWorked(shardedDB.runCommand({ insert: 'foo', documents: [{ x: 1 }]})); - assert.commandWorked(shardedDB.runCommand({ update: 'foo', - updates: [{ q: { x: 1 }, - u: { $set: { y: 1 }}}]})); - doc = shardedDB.foo.findOne({ x: 1 }); - assert.eq(1, doc.y); - assert.commandWorked(shardedDB.runCommand({ delete: 'foo', deletes: [{ q: { x: 1 }, - limit: 1 }]})); - doc = shardedDB.foo.findOne(); - assert.eq(null, doc); -}; - -var st = new ShardingTest({ shards: 2, mongos: 1, other: options }); - -var version = st.s.getCollection('config.version').findOne(); - -assert.eq(version.minCompatibleVersion, 5); -assert.eq(version.currentVersion, 6); -var clusterID = version.clusterId; -assert.neq(null, clusterID); -assert.eq(version.excluding, undefined); - -// upgrade everything except for mongos -st.upgradeCluster("latest", { upgradeMongos: false }); -st.restartMongoses(); - -testCRUD(st.s); - -// upgrade mongos -st.upgradeCluster("latest", { upgradeConfigs: false, upgradeShards: false }); -st.restartMongoses(); - -// Check that version document is unmodified. -version = st.s.getCollection('config.version').findOne(); -assert.eq(version.minCompatibleVersion, 5); -assert.eq(version.currentVersion, 6); -assert.neq(clusterID, version.clusterId); -assert.eq(version.excluding, undefined); - -testCRUD(st.s); - -st.stop(); -}; - -runTest(false); -runTest(true); + /** + * @param isRSCluster {bool} use replica set shards. + */ + var runTest = function(isRSCluster) { + "use strict"; + + jsTest.log("Starting" + (isRSCluster ? " (replica set)" : "") + " cluster" + "..."); + + var options = { + mongosOptions: {binVersion: "last-stable"}, + configOptions: {binVersion: "last-stable"}, + shardOptions: {binVersion: "last-stable"}, + + rsOptions: {binVersion: "last-stable"}, + rs: isRSCluster + }; + + var testCRUD = function(mongos) { + assert.commandWorked(mongos.getDB('test').runCommand({dropDatabase: 1})); + assert.commandWorked(mongos.getDB('unsharded').runCommand({dropDatabase: 1})); + + var unshardedDB = mongos.getDB('unshareded'); + assert.commandWorked(unshardedDB.runCommand({insert: 'foo', documents: [{x: 1}]})); + assert.commandWorked(unshardedDB.runCommand( + {update: 'foo', updates: [{q: {x: 1}, u: {$set: {y: 1}}}]})); + var doc = unshardedDB.foo.findOne({x: 1}); + assert.eq(1, doc.y); + assert.commandWorked( + unshardedDB.runCommand({delete: 'foo', deletes: [{q: {x: 1}, limit: 1}]})); + doc = unshardedDB.foo.findOne(); + assert.eq(null, doc); + + assert.commandWorked(mongos.adminCommand({enableSharding: 'test'})); + assert.commandWorked(mongos.adminCommand({shardCollection: 'test.user', key: {x: 1}})); + + var shardedDB = mongos.getDB('shareded'); + assert.commandWorked(shardedDB.runCommand({insert: 'foo', documents: [{x: 1}]})); + assert.commandWorked( + shardedDB.runCommand({update: 'foo', updates: [{q: {x: 1}, u: {$set: {y: 1}}}]})); + doc = shardedDB.foo.findOne({x: 1}); + assert.eq(1, doc.y); + assert.commandWorked( + shardedDB.runCommand({delete: 'foo', deletes: [{q: {x: 1}, limit: 1}]})); + doc = shardedDB.foo.findOne(); + assert.eq(null, doc); + }; + + var st = new ShardingTest({shards: 2, mongos: 1, other: options}); + + var version = st.s.getCollection('config.version').findOne(); + + assert.eq(version.minCompatibleVersion, 5); + assert.eq(version.currentVersion, 6); + var clusterID = version.clusterId; + assert.neq(null, clusterID); + assert.eq(version.excluding, undefined); + + // upgrade everything except for mongos + st.upgradeCluster("latest", {upgradeMongos: false}); + st.restartMongoses(); + + testCRUD(st.s); + + // upgrade mongos + st.upgradeCluster("latest", {upgradeConfigs: false, upgradeShards: false}); + st.restartMongoses(); + + // Check that version document is unmodified. + version = st.s.getCollection('config.version').findOne(); + assert.eq(version.minCompatibleVersion, 5); + assert.eq(version.currentVersion, 6); + assert.neq(clusterID, version.clusterId); + assert.eq(version.excluding, undefined); + + testCRUD(st.s); + + st.stop(); + }; + + runTest(false); + runTest(true); })(); diff --git a/jstests/multiVersion/wt_index_option_defaults_replset.js b/jstests/multiVersion/wt_index_option_defaults_replset.js index 451c56f807c..9156d0b06ae 100644 --- a/jstests/multiVersion/wt_index_option_defaults_replset.js +++ b/jstests/multiVersion/wt_index_option_defaults_replset.js @@ -32,21 +32,23 @@ var secondary30 = conns[1].getDB('test'); // Create a collection with "indexOptionDefaults" specified. - var indexOptions = {storageEngine: {wiredTiger: {configString: 'prefix_compression=false'}}}; + var indexOptions = { + storageEngine: {wiredTiger: {configString: 'prefix_compression=false'}} + }; assert.commandWorked(primary32.runCommand({create: 'coll', indexOptionDefaults: indexOptions})); // Verify that the "indexOptionDefaults" field is present in the corresponding oplog entry. - var entry = primary32.getSiblingDB('local').oplog.rs.find() - .sort({$natural: -1}) - .limit(1) - .next(); - assert.docEq(indexOptions, entry.o.indexOptionDefaults, + var entry = + primary32.getSiblingDB('local').oplog.rs.find().sort({$natural: -1}).limit(1).next(); + assert.docEq(indexOptions, + entry.o.indexOptionDefaults, 'indexOptionDefaults were not replicated: ' + tojson(entry)); rst.awaitReplication(); var collectionInfos = secondary30.getCollectionInfos({name: 'coll'}); - assert.eq(1, collectionInfos.length, + assert.eq(1, + collectionInfos.length, 'collection "coll" was not created on the secondary: ' + tojson(collectionInfos)); assert(!collectionInfos[0].options.hasOwnProperty('indexOptionDefaults'), @@ -88,24 +90,27 @@ var secondary32 = conns[1].getDB('test'); // Create a collection with "indexOptionDefaults" specified. - var indexOptions = {storageEngine: {wiredTiger: {configString: 'prefix_compression=false'}}}; + var indexOptions = { + storageEngine: {wiredTiger: {configString: 'prefix_compression=false'}} + }; assert.commandWorked(primary30.runCommand({create: 'coll', indexOptionDefaults: indexOptions})); // Verify that the "indexOptionDefaults" field is present in the corresponding oplog entry. - var entry = primary30.getSiblingDB('local').oplog.rs.find() - .sort({$natural: -1}) - .limit(1) - .next(); - assert.docEq(indexOptions, entry.o.indexOptionDefaults, + var entry = + primary30.getSiblingDB('local').oplog.rs.find().sort({$natural: -1}).limit(1).next(); + assert.docEq(indexOptions, + entry.o.indexOptionDefaults, 'indexOptionDefaults were not replicated: ' + tojson(entry)); rst.awaitReplication(); var collectionInfos = secondary32.getCollectionInfos({name: 'coll'}); - assert.eq(1, collectionInfos.length, + assert.eq(1, + collectionInfos.length, 'collection "coll" was not created on the secondary: ' + tojson(collectionInfos)); - assert.docEq(indexOptions, collectionInfos[0].options.indexOptionDefaults, + assert.docEq(indexOptions, + collectionInfos[0].options.indexOptionDefaults, 'indexOptionDefaults were not applied: ' + tojson(collectionInfos)); rst.stopSet(); |