diff options
author | Blake Oler <blake.oler@mongodb.com> | 2018-03-29 15:01:57 -0400 |
---|---|---|
committer | Blake Oler <blake.oler@mongodb.com> | 2018-04-02 15:13:45 -0400 |
commit | 04008276cc81cd234f042f25b3a65bca76a033ce (patch) | |
tree | cc4211455bc4f51b04aeabeb416eb49cb6e89e24 /jstests/noPassthroughWithMongod/moveprimary-replset.js | |
parent | 9055e4ea0230952af52e8cd396c63a8b407fdbf9 (diff) | |
download | mongo-04008276cc81cd234f042f25b3a65bca76a033ce.tar.gz |
SERVER-33769 Implement a commitMovePrimary command on the config server
Diffstat (limited to 'jstests/noPassthroughWithMongod/moveprimary-replset.js')
-rw-r--r-- | jstests/noPassthroughWithMongod/moveprimary-replset.js | 103 |
1 files changed, 45 insertions, 58 deletions
diff --git a/jstests/noPassthroughWithMongod/moveprimary-replset.js b/jstests/noPassthroughWithMongod/moveprimary-replset.js index 933a77720fd..64bf88c329d 100644 --- a/jstests/noPassthroughWithMongod/moveprimary-replset.js +++ b/jstests/noPassthroughWithMongod/moveprimary-replset.js @@ -5,73 +5,60 @@ (function() { "use strict"; + function movePrimaryReplset(useFCV40) { + var numDocs = 10000; + var baseName = "moveprimary-replset"; + var testDBName = baseName; + var testCollName = 'coll'; - var numDocs = 10000; - var baseName = "moveprimary-replset"; - var testDBName = baseName; - var testCollName = 'coll'; + var shardingTestConfig = { + name: baseName, + mongos: 1, + shards: 2, + config: 3, + rs: {nodes: 3}, + other: {manualAddShard: true} + }; + var shardingTest = new ShardingTest(shardingTestConfig); - jsTest.log("Spinning up a sharded cluster, but not adding the shards"); - var shardingTestConfig = { - name: baseName, - mongos: 1, - shards: 2, - config: 3, - rs: {nodes: 3}, - other: {manualAddShard: true} - }; - var shardingTest = new ShardingTest(shardingTestConfig); + var replSet1 = shardingTest.rs0; + var replSet2 = shardingTest.rs1; - jsTest.log("Geting connections to the individual shards"); - var replSet1 = shardingTest.rs0; - var replSet2 = shardingTest.rs1; + var repset1DB = replSet1.getPrimary().getDB(testDBName); + for (var i = 1; i <= numDocs; i++) { + repset1DB[testCollName].insert({x: i}); + } + replSet1.awaitReplication(); - jsTest.log("Adding data to our first replica set"); - var repset1DB = replSet1.getPrimary().getDB(testDBName); - for (var i = 1; i <= numDocs; i++) { - repset1DB[testCollName].insert({x: i}); - } - replSet1.awaitReplication(); - - jsTest.log("Geting connection to mongos for the cluster"); - var mongosConn = shardingTest.s; - var testDB = mongosConn.getDB(testDBName); - - jsTest.log("Adding replSet1 as only shard"); - mongosConn.adminCommand({addshard: replSet1.getURL()}); + var mongosConn = shardingTest.s; + var testDB = mongosConn.getDB(testDBName); - jsTest.log( - "Updating the data via mongos and making sure all documents are updated and present"); - testDB[testCollName].update({}, {$set: {y: 'hello'}}, false /*upsert*/, true /*multi*/); - assert.eq(testDB[testCollName].count({y: 'hello'}), - numDocs, - 'updating and counting docs via mongos failed'); + mongosConn.adminCommand({addshard: replSet1.getURL()}); - jsTest.log("Adding replSet2 as second shard"); - mongosConn.adminCommand({addshard: replSet2.getURL()}); + testDB[testCollName].update({}, {$set: {y: 'hello'}}, false /*upsert*/, true /*multi*/); + assert.eq(testDB[testCollName].count({y: 'hello'}), + numDocs, + 'updating and counting docs via mongos failed'); - mongosConn.getDB('admin').printShardingStatus(); - printjson(replSet2.getPrimary().getDBs()); + mongosConn.adminCommand({addshard: replSet2.getURL()}); - jsTest.log("Moving test db from replSet1 to replSet2"); - assert.commandWorked( - mongosConn.getDB('admin').runCommand({moveprimary: testDBName, to: replSet2.getURL()})); - mongosConn.getDB('admin').printShardingStatus(); - printjson(replSet2.getPrimary().getDBs()); - assert.eq(testDB.getSiblingDB("config").databases.findOne({"_id": testDBName}).primary, - replSet2.name, - "Failed to change primary shard for unsharded database."); + assert.commandWorked(mongosConn.getDB('admin').runCommand( + {moveprimary: testDBName, to: replSet2.getURL(), forTest: useFCV40})); + mongosConn.getDB('admin').printShardingStatus(); + let primaryName = testDB.getSiblingDB("config") + .databases.findOne({"_id": testDBName}) + .primary.split('/')[0]; + assert.eq( + primaryName, replSet2.name, "Failed to change primary shard for unsharded database."); - jsTest.log( - "Updating the data via mongos and making sure all documents are updated and present"); - testDB[testCollName].update({}, {$set: {z: 'world'}}, false /*upsert*/, true /*multi*/); - assert.eq(testDB[testCollName].count({z: 'world'}), - numDocs, - 'updating and counting docs via mongos failed'); + testDB[testCollName].update({}, {$set: {z: 'world'}}, false /*upsert*/, true /*multi*/); + assert.eq(testDB[testCollName].count({z: 'world'}), + numDocs, + 'updating and counting docs via mongos failed'); - jsTest.log("Shutting down cluster"); - shardingTest.stop(); - - print('moveprimary-replset.js SUCCESS'); + shardingTest.stop(); + } + movePrimaryReplset(false); + movePrimaryReplset(true); })(); |