diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2017-06-15 18:29:55 -0400 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2017-06-22 10:12:38 -0400 |
commit | ed1be6cce837630b65dd35c2b683007e970caea8 (patch) | |
tree | 1e58ee23d9c11376c59e0fba57624ef5857a6e4c /jstests | |
parent | 0d79ab8b66fcaf06bf5622de580ed5a85c95bc16 (diff) | |
download | mongo-ed1be6cce837630b65dd35c2b683007e970caea8.tar.gz |
SERVER-29654 Enable keys generation and logicalTime processing on shards and config when FCV is 3.6
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/noPassthrough/causal_consistency_feature_compatibility.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/jstests/noPassthrough/causal_consistency_feature_compatibility.js b/jstests/noPassthrough/causal_consistency_feature_compatibility.js new file mode 100644 index 00000000000..99a0acd55ac --- /dev/null +++ b/jstests/noPassthrough/causal_consistency_feature_compatibility.js @@ -0,0 +1,95 @@ +/** + * Tests the behavior of a sharded cluster when featureCompatibilityVersion is set to 3.4, with + * respect to causal consistency. In noPassthrough to avoid issues with auth. + */ +(function() { + "use strict"; + + load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority. + + function logicalTimeCanBeProcessed(db) { + const increment = 5000; + + let initialTime = db.runCommand({isMaster: 1}).$logicalTime; + let laterTime = Object.merge( + initialTime, + {clusterTime: Timestamp(initialTime.clusterTime.getTime() + increment, 0)}); + let returnedTime = rst.getPrimary() + .getDB("test") + .runCommand({isMaster: 1, $logicalTime: laterTime}) + .$logicalTime; + + // Use a range to allow for unrelated activity advancing cluster time. + return (returnedTime.clusterTime.getTime() - initialTime.clusterTime.getTime()) >= + increment; + } + + const rst = new ReplSetTest({ + nodes: 1, + nodeOptions: { + enableMajorityReadConcern: "", + shardsvr: "", + } + }); + + if (!startSetIfSupportsReadMajority(rst)) { + jsTestLog("Skipping test since storage engine doesn't support majority read concern."); + return; + } + rst.initiate(); + + // Start the sharding test and add the majority read concern enabled replica set. + const st = new ShardingTest({ + manualAddShard: true, + }); + assert.commandWorked(st.s.adminCommand({addShard: rst.getURL()})); + + const testDB = st.s.getDB("test"); + + // Initialize sharding. + assert.commandWorked(testDB.adminCommand({enableSharding: "test"})); + assert.commandWorked( + testDB.adminCommand({shardCollection: testDB.foo.getFullName(), key: {_id: 1}})); + + // Insert some data to find. + assert.commandWorked(testDB.runCommand( + {insert: "foo", documents: [{_id: 1, x: 1}], writeConcern: {w: "majority"}})); + + // Verify afterClusterTime can be processed by mongos and mongod. + assert.commandWorked(testDB.runCommand( + {find: "foo", readConcern: {level: "majority", afterClusterTime: Timestamp(1, 1)}})); + + assert.commandWorked(rst.getPrimary().getDB("test").runCommand( + {find: "foo", readConcern: {level: "majority", afterClusterTime: Timestamp(1, 1)}})); + + // Verify logical time can be processed by shards and the config servers. + assert(logicalTimeCanBeProcessed(rst.getPrimary().getDB("test"))); + assert(logicalTimeCanBeProcessed(st.configRS.getPrimary().getDB("test"))); + + // Set featureCompatibilityVersion to 3.4 + assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: "3.4"})); + + // Verify logical time cannot be processed by shards and the config servers now. + assert(!logicalTimeCanBeProcessed(rst.getPrimary().getDB("test"))); + assert(!logicalTimeCanBeProcessed(st.configRS.getPrimary().getDB("test"))); + + // afterClusterTime should be rejected by mongos and mongod. + assert.commandFailedWithCode( + testDB.runCommand( + {find: "foo", readConcern: {level: "majority", afterClusterTime: Timestamp(1, 1)}}), + ErrorCodes.InvalidOptions); + + assert.commandFailedWithCode( + rst.getPrimary().getDB("test").runCommand( + {find: "foo", readConcern: {level: "majority", afterClusterTime: Timestamp(1, 1)}}), + ErrorCodes.InvalidOptions); + + // setFeatureCompatibilityVersion can only be run on the admin database on mongos. + assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: "3.6"})); + + // Verify logical time can be processed by shards and the config servers again. + assert(logicalTimeCanBeProcessed(rst.getPrimary().getDB("test"))); + assert(logicalTimeCanBeProcessed(st.configRS.getPrimary().getDB("test"))); + + st.stop(); +})(); |