summaryrefslogtreecommitdiff
path: root/jstests/sharding/multi_write_target.js
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-02-09 16:34:21 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-02-10 06:55:10 -0500
commit4b4cbf4dc3349744bec757382dfe01a3e363d0fc (patch)
treed3e83b05e54f7e8499b338de312bb4d60296ccac /jstests/sharding/multi_write_target.js
parentd84483b8a6a9890c2c93f267d8c28969dc563c37 (diff)
downloadmongo-4b4cbf4dc3349744bec757382dfe01a3e363d0fc.tar.gz
SERVER-22543 multi_write_target.js should not rely on order of shard ids
Diffstat (limited to 'jstests/sharding/multi_write_target.js')
-rw-r--r--jstests/sharding/multi_write_target.js79
1 files changed, 37 insertions, 42 deletions
diff --git a/jstests/sharding/multi_write_target.js b/jstests/sharding/multi_write_target.js
index ca467cff2e1..3de867ed5ea 100644
--- a/jstests/sharding/multi_write_target.js
+++ b/jstests/sharding/multi_write_target.js
@@ -1,78 +1,73 @@
//
// Tests that multi-writes (update/delete) target *all* shards and not just shards in the collection
//
+(function() {
+'use strict';
-var st = new ShardingTest({ shards : 3, mongos : 2 });
-st.stopBalancer();
+var st = new ShardingTest({ shards: 3, mongos: 2 });
-var mongos = st.s0;
-var admin = mongos.getDB( "admin" );
-var shards = mongos.getCollection( "config.shards" ).find().toArray();
-var coll = mongos.getCollection( "foo.bar" );
+var admin = st.s0.getDB( "admin" );
+var coll = st.s0.getCollection( "foo.bar" );
-assert( admin.runCommand({ enableSharding : coll.getDB() + "" }).ok );
-printjson( admin.runCommand({ movePrimary : coll.getDB() + "", to : shards[0]._id }) );
-assert( admin.runCommand({ shardCollection : coll + "", key : { skey : 1 } }).ok );
-assert( admin.runCommand({ split : coll + "", middle : { skey : 0 } }).ok );
-assert( admin.runCommand({ split : coll + "", middle : { skey : 100 } }).ok );
-assert( admin.runCommand({ moveChunk : coll + "",
- find : { skey : 0 },
- to : shards[1]._id }).ok );
-assert( admin.runCommand({ moveChunk : coll + "",
- find : { skey : 100 },
- to : shards[2]._id }).ok );
+assert.commandWorked(admin.runCommand({ enableSharding: coll.getDB() + "" }));
+st.ensurePrimaryShard(coll.getDB() + "", st.shard0.shardName);
+assert.commandWorked(admin.runCommand({ shardCollection: coll + "", key: { skey: 1 } }));
-st.printShardingStatus();
+assert.commandWorked(admin.runCommand({ split: coll + "", middle: { skey: 0 } }));
+assert.commandWorked(admin.runCommand({ split: coll + "", middle: { skey: 100 } }));
+assert.commandWorked(
+ admin.runCommand({ moveChunk: coll + "", find: { skey: 0 }, to: st.shard1.shardName }));
+assert.commandWorked(
+ admin.runCommand({ moveChunk: coll + "", find: { skey: 100 }, to: st.shard2.shardName }));
jsTest.log("Testing multi-update...");
// Put data on all shards
-assert.writeOK(st.s0.getCollection(coll.toString()).insert({ _id : 0, skey : -1, x : 1 }));
-assert.writeOK(st.s0.getCollection(coll.toString()).insert({ _id : 1, skey : 1, x : 1 }));
+assert.writeOK(st.s0.getCollection(coll.toString()).insert({ _id: 0, skey: -1, x: 1 }));
+assert.writeOK(st.s0.getCollection(coll.toString()).insert({ _id: 1, skey: 1, x: 1 }));
assert.writeOK(st.s0.getCollection(coll.toString()).insert({ _id: 0, skey: 100, x: 1 }));
// Non-multi-update doesn't work without shard key
-assert.writeError(coll.update({ x : 1 }, { $set : { updated : true } }, { multi : false }));
-
-assert.writeOK(coll.update({ x : 1 }, { $set : { updated : true } }, { multi : true }));
+assert.writeError(coll.update({ x: 1 }, { $set: { updated: true } }, { multi: false }));
+assert.writeOK(coll.update({ x: 1 }, { $set: { updated: true } }, { multi: true }));
// Ensure update goes to *all* shards
-assert.neq(null, st.shard0.getCollection(coll.toString()).findOne({ updated : true }));
-assert.neq(null, st.shard1.getCollection(coll.toString()).findOne({ updated : true }));
-assert.neq(null, st.shard2.getCollection(coll.toString()).findOne({ updated : true }));
+assert.neq(null, st.shard0.getCollection(coll.toString()).findOne({ updated: true }));
+assert.neq(null, st.shard1.getCollection(coll.toString()).findOne({ updated: true }));
+assert.neq(null, st.shard2.getCollection(coll.toString()).findOne({ updated: true }));
// _id update works, and goes to all shards even on the stale mongos
var staleColl = st.s1.getCollection('foo.bar');
-assert.writeOK(staleColl.update({ _id : 0 }, { $set : { updatedById : true } }, { multi : false }));
+assert.writeOK(staleColl.update({ _id: 0 }, { $set: { updatedById: true } }, { multi: false }));
// Ensure _id update goes to *all* shards
-assert.neq(null, st.shard0.getCollection(coll.toString()).findOne({ updatedById : true }));
-assert.neq(null, st.shard2.getCollection(coll.toString()).findOne({ updatedById : true }));
+assert.neq(null, st.shard0.getCollection(coll.toString()).findOne({ updatedById: true }));
+assert.neq(null, st.shard2.getCollection(coll.toString()).findOne({ updatedById: true }));
jsTest.log("Testing multi-delete...");
// non-multi-delete doesn't work without shard key
-assert.writeError(coll.remove({ x : 1 }, { justOne : true }));
+assert.writeError(coll.remove({ x: 1 }, { justOne: true }));
-assert.writeOK(coll.remove({ x : 1 }, { justOne : false }));
+assert.writeOK(coll.remove({ x: 1 }, { justOne: false }));
// Ensure delete goes to *all* shards
-assert.eq(null, st.shard0.getCollection(coll.toString()).findOne({ x : 1 }));
-assert.eq(null, st.shard1.getCollection(coll.toString()).findOne({ x : 1 }));
-assert.eq(null, st.shard2.getCollection(coll.toString()).findOne({ x : 1 }));
+assert.eq(null, st.shard0.getCollection(coll.toString()).findOne({ x: 1 }));
+assert.eq(null, st.shard1.getCollection(coll.toString()).findOne({ x: 1 }));
+assert.eq(null, st.shard2.getCollection(coll.toString()).findOne({ x: 1 }));
// Put more on all shards
-assert.writeOK(st.shard0.getCollection(coll.toString()).insert({ _id : 0, skey : -1, x : 1 }));
-assert.writeOK(st.shard1.getCollection(coll.toString()).insert({ _id : 1, skey : 1, x : 1 }));
+assert.writeOK(st.shard0.getCollection(coll.toString()).insert({ _id: 0, skey: -1, x: 1 }));
+assert.writeOK(st.shard1.getCollection(coll.toString()).insert({ _id: 1, skey: 1, x: 1 }));
// Data not in chunks
-assert.writeOK(st.shard2.getCollection(coll.toString()).insert({ _id : 0, x : 1 }));
+assert.writeOK(st.shard2.getCollection(coll.toString()).insert({ _id: 0, x: 1 }));
-assert.writeOK(coll.remove({ _id : 0 }, { justOne : true }));
+assert.writeOK(coll.remove({ _id: 0 }, { justOne: true }));
// Ensure _id delete goes to *all* shards
-assert.eq(null, st.shard0.getCollection(coll.toString()).findOne({ x : 1 }));
-assert.eq(null, st.shard2.getCollection(coll.toString()).findOne({ x : 1 }));
-
-jsTest.log( "DONE!" );
+assert.eq(null, st.shard0.getCollection(coll.toString()).findOne({ x: 1 }));
+assert.eq(null, st.shard2.getCollection(coll.toString()).findOne({ x: 1 }));
st.stop();
+
+})();