diff options
Diffstat (limited to 'jstests/sharding/convert_to_and_from_sharded.js')
-rw-r--r-- | jstests/sharding/convert_to_and_from_sharded.js | 174 |
1 files changed, 87 insertions, 87 deletions
diff --git a/jstests/sharding/convert_to_and_from_sharded.js b/jstests/sharding/convert_to_and_from_sharded.js index 96ee9d19a6d..15da2e0cc73 100644 --- a/jstests/sharding/convert_to_and_from_sharded.js +++ b/jstests/sharding/convert_to_and_from_sharded.js @@ -4,126 +4,126 @@ * @tags: [requires_persistence] */ (function() { - "use strict"; +"use strict"; - load("jstests/libs/feature_compatibility_version.js"); +load("jstests/libs/feature_compatibility_version.js"); - var NUM_NODES = 3; +var NUM_NODES = 3; - /** - * Checks that basic CRUD operations work as expected. Expects the collection to have a - * { _id: 'marker' } document. - */ - var checkBasicCRUD = function(coll) { - var doc = coll.findOne({_id: 'marker', y: {$exists: false}}); - assert.neq(null, doc); +/** + * Checks that basic CRUD operations work as expected. Expects the collection to have a + * { _id: 'marker' } document. + */ +var checkBasicCRUD = function(coll) { + var doc = coll.findOne({_id: 'marker', y: {$exists: false}}); + assert.neq(null, doc); - assert.writeOK(coll.update({_id: 'marker'}, {$set: {y: 2}})); - assert.eq(2, coll.findOne({_id: 'marker'}).y); + assert.writeOK(coll.update({_id: 'marker'}, {$set: {y: 2}})); + assert.eq(2, coll.findOne({_id: 'marker'}).y); - assert.writeOK(coll.remove({_id: 'marker'})); - assert.eq(null, coll.findOne({_id: 'marker'})); + assert.writeOK(coll.remove({_id: 'marker'})); + assert.eq(null, coll.findOne({_id: 'marker'})); - assert.writeOK(coll.insert({_id: 'marker'}, {writeConcern: {w: NUM_NODES}})); - assert.eq('marker', coll.findOne({_id: 'marker'})._id); - }; + assert.writeOK(coll.insert({_id: 'marker'}, {writeConcern: {w: NUM_NODES}})); + assert.eq('marker', coll.findOne({_id: 'marker'})._id); +}; - var st = new ShardingTest({shards: {}}); +var st = new ShardingTest({shards: {}}); - var replShard = new ReplSetTest({nodes: NUM_NODES}); - replShard.startSet({verbose: 1}); - replShard.initiate(); +var replShard = new ReplSetTest({nodes: NUM_NODES}); +replShard.startSet({verbose: 1}); +replShard.initiate(); - var priConn = replShard.getPrimary(); +var priConn = replShard.getPrimary(); - // Starting a brand new replica set without '--shardsvr' will cause the FCV to be written as the - // latest available for that binary. This poses a problem when this test is run in the mixed - // version suite because mongos will be 'last-stable' and if this node is of the latest binary, - // it will report itself as the 'latest' FCV, which would cause mongos to refuse to connect to - // it and shutdown. - // - // In order to work around this, in the mixed version suite, be pessimistic and always set this - // node to the 'last-stable' FCV - if (jsTestOptions().shardMixedBinVersions) { - assert.commandWorked(priConn.adminCommand({setFeatureCompatibilityVersion: lastStableFCV})); - replShard.awaitReplication(); - } +// Starting a brand new replica set without '--shardsvr' will cause the FCV to be written as the +// latest available for that binary. This poses a problem when this test is run in the mixed +// version suite because mongos will be 'last-stable' and if this node is of the latest binary, +// it will report itself as the 'latest' FCV, which would cause mongos to refuse to connect to +// it and shutdown. +// +// In order to work around this, in the mixed version suite, be pessimistic and always set this +// node to the 'last-stable' FCV +if (jsTestOptions().shardMixedBinVersions) { + assert.commandWorked(priConn.adminCommand({setFeatureCompatibilityVersion: lastStableFCV})); + replShard.awaitReplication(); +} - assert.writeOK(priConn.getDB('test').unsharded.insert({_id: 'marker'})); - checkBasicCRUD(priConn.getDB('test').unsharded); +assert.writeOK(priConn.getDB('test').unsharded.insert({_id: 'marker'})); +checkBasicCRUD(priConn.getDB('test').unsharded); - assert.writeOK(priConn.getDB('test').sharded.insert({_id: 'marker'})); - checkBasicCRUD(priConn.getDB('test').sharded); +assert.writeOK(priConn.getDB('test').sharded.insert({_id: 'marker'})); +checkBasicCRUD(priConn.getDB('test').sharded); - for (var x = 0; x < NUM_NODES; x++) { - replShard.restart(x, {shardsvr: ''}); - } +for (var x = 0; x < NUM_NODES; x++) { + replShard.restart(x, {shardsvr: ''}); +} - replShard.awaitNodesAgreeOnPrimary(); - assert.commandWorked(st.s.adminCommand({addShard: replShard.getURL()})); +replShard.awaitNodesAgreeOnPrimary(); +assert.commandWorked(st.s.adminCommand({addShard: replShard.getURL()})); - priConn = replShard.getPrimary(); - checkBasicCRUD(priConn.getDB('test').unsharded); - checkBasicCRUD(priConn.getDB('test').sharded); +priConn = replShard.getPrimary(); +checkBasicCRUD(priConn.getDB('test').unsharded); +checkBasicCRUD(priConn.getDB('test').sharded); - checkBasicCRUD(st.s.getDB('test').unsharded); - checkBasicCRUD(st.s.getDB('test').sharded); +checkBasicCRUD(st.s.getDB('test').unsharded); +checkBasicCRUD(st.s.getDB('test').sharded); - assert.commandWorked(st.s.adminCommand({enableSharding: 'test'})); - assert.commandWorked(st.s.adminCommand({shardCollection: 'test.sharded', key: {_id: 1}})); +assert.commandWorked(st.s.adminCommand({enableSharding: 'test'})); +assert.commandWorked(st.s.adminCommand({shardCollection: 'test.sharded', key: {_id: 1}})); - checkBasicCRUD(st.s.getDB('test').unsharded); - checkBasicCRUD(st.s.getDB('test').sharded); +checkBasicCRUD(st.s.getDB('test').unsharded); +checkBasicCRUD(st.s.getDB('test').sharded); - for (x = 0; x < 4; x++) { - assert.writeOK(st.s.getDB('test').sharded.insert({_id: x})); - assert.commandWorked(st.s.adminCommand({split: 'test.sharded', middle: {_id: x}})); - } +for (x = 0; x < 4; x++) { + assert.writeOK(st.s.getDB('test').sharded.insert({_id: x})); + assert.commandWorked(st.s.adminCommand({split: 'test.sharded', middle: {_id: x}})); +} - var newMongod = MongoRunner.runMongod({shardsvr: ''}); +var newMongod = MongoRunner.runMongod({shardsvr: ''}); - assert.commandWorked(st.s.adminCommand({addShard: newMongod.name, name: 'toRemoveLater'})); +assert.commandWorked(st.s.adminCommand({addShard: newMongod.name, name: 'toRemoveLater'})); - for (x = 0; x < 2; x++) { - assert.commandWorked( - st.s.adminCommand({moveChunk: 'test.sharded', find: {_id: x}, to: 'toRemoveLater'})); - } +for (x = 0; x < 2; x++) { + assert.commandWorked( + st.s.adminCommand({moveChunk: 'test.sharded', find: {_id: x}, to: 'toRemoveLater'})); +} - checkBasicCRUD(st.s.getDB('test').unsharded); - checkBasicCRUD(st.s.getDB('test').sharded); +checkBasicCRUD(st.s.getDB('test').unsharded); +checkBasicCRUD(st.s.getDB('test').sharded); - assert.commandWorked(st.s.adminCommand({removeShard: 'toRemoveLater'})); +assert.commandWorked(st.s.adminCommand({removeShard: 'toRemoveLater'})); - // Start the balancer to start draining the chunks. - st.startBalancer(); +// Start the balancer to start draining the chunks. +st.startBalancer(); - assert.soon(function() { - var res = st.s.adminCommand({removeShard: 'toRemoveLater'}); - return res.state == 'completed'; - }); +assert.soon(function() { + var res = st.s.adminCommand({removeShard: 'toRemoveLater'}); + return res.state == 'completed'; +}); - MongoRunner.stopMongod(newMongod); +MongoRunner.stopMongod(newMongod); - checkBasicCRUD(st.s.getDB('test').unsharded); - checkBasicCRUD(st.s.getDB('test').sharded); +checkBasicCRUD(st.s.getDB('test').unsharded); +checkBasicCRUD(st.s.getDB('test').sharded); - st.stop(); +st.stop(); - checkBasicCRUD(priConn.getDB('test').unsharded); - checkBasicCRUD(priConn.getDB('test').sharded); +checkBasicCRUD(priConn.getDB('test').unsharded); +checkBasicCRUD(priConn.getDB('test').sharded); - jsTest.log('About to restart repl w/o shardsvr'); +jsTest.log('About to restart repl w/o shardsvr'); - replShard.nodes.forEach(function(node) { - delete node.fullOptions.shardsvr; - }); +replShard.nodes.forEach(function(node) { + delete node.fullOptions.shardsvr; +}); - replShard.restart(replShard.nodes); - replShard.awaitNodesAgreeOnPrimary(); +replShard.restart(replShard.nodes); +replShard.awaitNodesAgreeOnPrimary(); - priConn = replShard.getPrimary(); - checkBasicCRUD(priConn.getDB('test').unsharded); - checkBasicCRUD(priConn.getDB('test').sharded); +priConn = replShard.getPrimary(); +checkBasicCRUD(priConn.getDB('test').unsharded); +checkBasicCRUD(priConn.getDB('test').sharded); - replShard.stopSet(); +replShard.stopSet(); })(); |