summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@10gen.com>2017-09-20 13:59:01 -0400
committerDianna Hohensee <dianna.hohensee@10gen.com>2017-09-25 11:13:51 -0400
commitf9a41c8419554d727381c0b5766193f48c0ddc98 (patch)
tree68a07ddf39b9a39370a6e1a48e8c07213ddb0e94
parentf007ee07aebecd5371c38388423b05cd82ef02a2 (diff)
downloadmongo-f9a41c8419554d727381c0b5766193f48c0ddc98.tar.gz
SERVER-30550 Test that safe secondary reads is inactive until 3.6 feature compatibility version is set
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml1
-rw-r--r--jstests/sharding/secondary_shard_version_protocol_with_fcv.js87
2 files changed, 88 insertions, 0 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
index df85698c542..e154cc8dd6e 100644
--- a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
@@ -39,6 +39,7 @@ selector:
- jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js
- jstests/sharding/secondary_shard_versioning.js
- jstests/sharding/secondary_shard_version_protocol_with_causal_consistency.js
+ - jstests/sharding/secondary_shard_version_protocol_with_fcv.js
- jstests/sharding/session_info_in_oplog.js
- jstests/sharding/enable_sharding_basic.js
- jstests/sharding/retryable_writes.js
diff --git a/jstests/sharding/secondary_shard_version_protocol_with_fcv.js b/jstests/sharding/secondary_shard_version_protocol_with_fcv.js
new file mode 100644
index 00000000000..b20016ce138
--- /dev/null
+++ b/jstests/sharding/secondary_shard_version_protocol_with_fcv.js
@@ -0,0 +1,87 @@
+/**
+ * Tests that v3.6 secondaries do not participate in the shard version protocol while feature
+ * compatibility version 3.4 is set. Then tests that v3.6 secondaries do participate when feature
+ * compatibility gets raised to 3.6. This is verified by reading orphans on secondaries in fcv 3.4,
+ * then not seeing them after fcv 3.6 is set.
+ */
+(function() {
+ "use strict";
+
+ let st = new ShardingTest({mongos: 2, shards: 2, rs: {nodes: 2}});
+ let mongos = st.s0, admin = mongos.getDB('admin'), dbName = "testDB", collName = 'testColl',
+ ns = dbName + "." + collName, coll = mongos.getCollection(ns), donor = st.shard0,
+ recipient = st.shard1, donorColl = donor.getCollection(ns),
+ recipientColl = recipient.getCollection(ns);
+
+ jsTest.log('Setting feature compatibility to 3.4');
+ assert.commandWorked(admin.runCommand({setFeatureCompatibilityVersion: "3.4"}));
+
+ jsTest.log('Sharding the collection and pre-splitting into two chunks....');
+ assert.commandWorked(admin.runCommand({enableSharding: dbName}));
+ st.ensurePrimaryShard(dbName, donor.shardName);
+ assert.commandWorked(admin.runCommand({shardCollection: ns, key: {a: 1}}));
+ assert.commandWorked(admin.runCommand({split: ns, middle: {a: 20}}));
+
+ jsTest.log('Inserting 6 docs into donor shard, 3 in each chunk....');
+ for (var i = 0; i < 3; ++i)
+ assert.writeOK(coll.insert({a: i}));
+ for (var i = 20; i < 23; ++i)
+ assert.writeOK(coll.insert({a: i}));
+ st.rs0.awaitReplication();
+ assert.eq(6, coll.count());
+
+ jsTest.log('Moving 1 (of 2) chunks to recipient shard....');
+ assert.commandWorked(admin.runCommand({
+ moveChunk: ns,
+ find: {a: 30},
+ to: recipient.shardName,
+ _secondaryThrottle: true,
+ writeConcern: {w: 2},
+ _waitForDelete: true, // Ensure we don't delete the orphans we're about to insert.
+ }));
+
+ jsTest.log('Insert 3 orphan documents into donor shard....');
+ for (var i = 40; i < 43; ++i)
+ assert.writeOK(donorColl.insert({a: i}));
+ st.rs0.awaitReplication();
+
+ jsTest.log('Checking query results to primaries and secondaries in 3.4 fcv mode');
+ // Primary reads should not return orphaned documents.
+ let res = coll.runCommand({find: collName, $readPreference: {mode: "primary"}});
+ assert.commandWorked(res);
+ assert.eq(6, res.cursor.firstBatch.length);
+
+ // Secondary reads should return orphaned documents.
+ res = coll.runCommand({find: collName, $readPreference: {mode: "secondary"}});
+ assert.commandWorked(res);
+ assert.eq(9, res.cursor.firstBatch.length);
+
+ jsTest.log('Raising feature compatibility to 3.6');
+ assert.commandWorked(admin.runCommand({setFeatureCompatibilityVersion: "3.6"}));
+
+ jsTest.log('Rechecking query results on primaries and secondaries now that it is 3.6 fcv mode');
+ // Primary reads should default to 'local' read concern level.
+ res = coll.runCommand({find: collName, $readPreference: {mode: "primary"}});
+ assert.commandWorked(res);
+ assert.eq(6, res.cursor.firstBatch.length);
+
+ // Primary reads should return orphaned documents when read concern level 'available' is
+ // specified.
+ res = coll.runCommand(
+ {find: collName, $readPreference: {mode: "primary"}, readConcern: {"level": "available"}});
+ assert.commandWorked(res);
+ assert.eq(9, res.cursor.firstBatch.length);
+
+ // Secondary reads should no longer return orphaned documents with read concern level 'local'.
+ res = coll.runCommand(
+ {find: collName, $readPreference: {mode: "secondary"}, readConcern: {"level": "local"}});
+ assert.commandWorked(res);
+ assert.eq(6, res.cursor.firstBatch.length);
+
+ // Secondary reads should default to read concern level 'available' and return orphans.
+ res = coll.runCommand({find: collName, $readPreference: {mode: "secondary"}});
+ assert.commandWorked(res);
+ assert.eq(9, res.cursor.firstBatch.length);
+
+ st.stop();
+})();