summaryrefslogtreecommitdiff
path: root/jstests/sharding/mongos_validate_writes.js
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@gmail.com>2018-05-12 14:06:35 +0100
committerBernard Gorman <bernard.gorman@gmail.com>2018-06-11 11:58:10 +0100
commit0dd1fc7ddde2a489558f5328dce5125bddfb9e4d (patch)
treec7d8336ff21e411eeeb20d11c25dd7a4bbb2b76a /jstests/sharding/mongos_validate_writes.js
parentc7451c0e11c2a782e9c0dabe16cbad744e4c451a (diff)
downloadmongo-0dd1fc7ddde2a489558f5328dce5125bddfb9e4d.tar.gz
SERVER-34971 Improve mongoS targeting for single-shard updates, and for replacement-style updates when the shard key includes _id
Diffstat (limited to 'jstests/sharding/mongos_validate_writes.js')
-rw-r--r--jstests/sharding/mongos_validate_writes.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/jstests/sharding/mongos_validate_writes.js b/jstests/sharding/mongos_validate_writes.js
index 85b7dbb136f..d9114a6033f 100644
--- a/jstests/sharding/mongos_validate_writes.js
+++ b/jstests/sharding/mongos_validate_writes.js
@@ -21,7 +21,11 @@
assert.commandWorked(admin.runCommand({enableSharding: coll.getDB() + ""}));
st.ensurePrimaryShard(coll.getDB().getName(), st.shard1.shardName);
coll.ensureIndex({a: 1});
- assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {a: 1}}));
+
+ // Shard the collection on {a: 1} and move one chunk to another shard. Updates need to be across
+ // two shards to trigger an error, otherwise they are versioned and will succeed after raising
+ // a StaleConfigException.
+ st.shardColl(coll, {a: 1}, {a: 0}, {a: 1}, coll.getDB(), true);
// Let the stale mongos see the collection state
staleCollA.findOne();
@@ -30,7 +34,7 @@
// Change the collection sharding state
coll.drop();
coll.ensureIndex({b: 1});
- assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {b: 1}}));
+ st.shardColl(coll, {b: 1}, {b: 0}, {b: 1}, coll.getDB(), true);
// Make sure that we can successfully insert, even though we have stale state
assert.writeOK(staleCollA.insert({b: "b"}));
@@ -41,7 +45,7 @@
// Change the collection sharding state
coll.drop();
coll.ensureIndex({c: 1});
- assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {c: 1}}));
+ st.shardColl(coll, {c: 1}, {c: 0}, {c: 1}, coll.getDB(), true);
// Make sure we can successfully upsert, even though we have stale state
assert.writeOK(staleCollA.update({c: "c"}, {c: "c"}, true));
@@ -52,7 +56,7 @@
// Change the collection sharding state
coll.drop();
coll.ensureIndex({d: 1});
- assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {d: 1}}));
+ st.shardColl(coll, {d: 1}, {d: 0}, {d: 1}, coll.getDB(), true);
// Make sure we can successfully update, even though we have stale state
assert.writeOK(coll.insert({d: "d"}));
@@ -67,13 +71,9 @@
// Change the collection sharding state
coll.drop();
coll.ensureIndex({e: 1});
- // Deletes need to be across two shards to trigger an error - this is probably an exceptional
- // case
+ // Deletes need to be across two shards to trigger an error.
st.ensurePrimaryShard(coll.getDB().getName(), st.shard0.shardName);
- assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {e: 1}}));
- assert.commandWorked(admin.runCommand({split: coll + "", middle: {e: 0}}));
- assert.commandWorked(
- admin.runCommand({moveChunk: coll + "", find: {e: 0}, to: st.shard1.shardName}));
+ st.shardColl(coll, {e: 1}, {e: 0}, {e: 1}, coll.getDB(), true);
// Make sure we can successfully remove, even though we have stale state
assert.writeOK(coll.insert({e: "e"}));