diff options
author | William Schultz <william.schultz@mongodb.com> | 2016-11-08 15:24:16 -0500 |
---|---|---|
committer | William Schultz <william.schultz@mongodb.com> | 2016-11-15 10:26:35 -0500 |
commit | d7c5c9aaf6437be34193ed83d74defa52c0e031f (patch) | |
tree | 441037ab10dcb803913ee8a820b822256aa436ef | |
parent | 21821549cdeef84173293c46725695fc3a7834b0 (diff) | |
download | mongo-d7c5c9aaf6437be34193ed83d74defa52c0e031f.tar.gz |
SERVER-26852 Move read concern tests out of noPassthrough
SERVER-26852 Moved readConcern tests out of noPassthrough
-rw-r--r-- | buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml | 2 | ||||
-rw-r--r-- | jstests/libs/read_committed_lib.js | 111 | ||||
-rw-r--r-- | jstests/noPassthrough/read_committed_lookup.js | 187 | ||||
-rw-r--r-- | jstests/replsets/read_committed_lookup.js | 44 | ||||
-rw-r--r-- | jstests/sharding/read_committed_lookup.js | 64 |
5 files changed, 221 insertions, 187 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 038456931a7..b04da855c97 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 @@ -84,6 +84,8 @@ selector: - jstests/sharding/merge_chunks_test.js # TODO Change in error reporting, enable when 3.4 becomes last-stable. See SERVER-26440. - jstests/sharding/explain_cmd_invalid_namespace.js + # $graphLookup is not supported in versions <= 3.2 + - jstests/sharding/read_committed_lookup.js executor: js_test: diff --git a/jstests/libs/read_committed_lib.js b/jstests/libs/read_committed_lib.js new file mode 100644 index 00000000000..b7e00327f4e --- /dev/null +++ b/jstests/libs/read_committed_lib.js @@ -0,0 +1,111 @@ +/** + * Test readCommitted lookup/graphLookup. 'db' must be the test database for either the replica set + * primary or mongos instance. 'secondary' is the shard/replica set secondary. If 'db' is backed + * by a mongos instance then the associated cluster should have only a single shard. 'rst' is the + * ReplSetTest instance associated with the replica set/shard. + */ +function testReadCommittedLookup(db, secondary, rst) { + /** + * Uses the 'rsSyncApplyStop' fail point to stop application of oplog entries on the given + * secondary. + */ + function pauseReplication(sec) { + assert.commandWorked( + sec.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "alwaysOn"}), + "failed to enable fail point on secondary"); + } + + /** + * Turns off the 'rsSyncApplyStop' fail point to resume application of oplog entries on the + * given secondary. + */ + function resumeReplication(sec) { + assert.commandWorked(sec.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"}), + "failed to disable fail point on secondary"); + } + + const aggCmdLookupObj = { + aggregate: "local", + pipeline: [ + { + $lookup: { + from: "foreign", + localField: "foreignKey", + foreignField: "matchedField", + as: "match", + } + }, + ], + readConcern: { + level: "majority", + } + }; + + const aggCmdGraphLookupObj = { + aggregate: "local", + pipeline: [{ + $graphLookup: { + from: "foreign", + startWith: '$foreignKey', + connectFromField: 'foreignKey', + connectToField: "matchedField", + as: "match" + } + }], + readConcern: { + level: "majority", + } + }; + + // Seed matching data. + const majorityWriteConcernObj = {writeConcern: {w: "majority", wtimeout: 60 * 1000}}; + db.local.deleteMany({}, majorityWriteConcernObj); + const localId = db.local.insertOne({foreignKey: "x"}, majorityWriteConcernObj).insertedId; + db.foreign.deleteMany({}, majorityWriteConcernObj); + const foreignId = db.foreign.insertOne({matchedField: "x"}, majorityWriteConcernObj).insertedId; + + const expectedMatchedResult = [{ + _id: localId, + foreignKey: "x", + match: [ + {_id: foreignId, matchedField: "x"}, + ], + }]; + const expectedUnmatchedResult = [{ + _id: localId, + foreignKey: "x", + match: [], + }]; + + // Confirm lookup/graphLookup return the matched result. + let result = db.runCommand(aggCmdLookupObj).result; + assert.eq(result, expectedMatchedResult); + + result = db.runCommand(aggCmdGraphLookupObj).result; + assert.eq(result, expectedMatchedResult); + + // Stop oplog application on the secondary so that it won't acknowledge updates. + pauseReplication(secondary); + + // Update foreign data to no longer match, without a majority write concern. + db.foreign.updateOne({_id: foreignId}, {$set: {matchedField: "non-match"}}); + + // lookup/graphLookup should not see the update, since it has not been acknowledged by the + // secondary. + result = db.runCommand(aggCmdLookupObj).result; + assert.eq(result, expectedMatchedResult); + + result = db.runCommand(aggCmdGraphLookupObj).result; + assert.eq(result, expectedMatchedResult); + + // Restart oplog application on the secondary and wait for it's snapshot to catch up. + resumeReplication(secondary); + rst.awaitLastOpCommitted(); + + // Now lookup/graphLookup should report that the documents don't match. + result = db.runCommand(aggCmdLookupObj).result; + assert.eq(result, expectedUnmatchedResult); + + result = db.runCommand(aggCmdGraphLookupObj).result; + assert.eq(result, expectedUnmatchedResult); +} diff --git a/jstests/noPassthrough/read_committed_lookup.js b/jstests/noPassthrough/read_committed_lookup.js deleted file mode 100644 index 46345b68561..00000000000 --- a/jstests/noPassthrough/read_committed_lookup.js +++ /dev/null @@ -1,187 +0,0 @@ -/** - * Tests that a $lookup and $graphLookup stage within an aggregation pipeline will read only - * committed data if the pipeline is using a majority readConcern. This is tested both on a replica - * set, and on a sharded cluster with one shard which is a replica set. - */ - -load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority. - -(function() { - "use strict"; - - /** - * Test readCommitted lookup/graphLookup. 'db' must be the test database for either the shard - * primary or mongos instance. 'secondary' is the shard/replica set secondary. If 'db' is backed - * by a mongos instance then the associated cluster should have only a single shard. - */ - function testReadCommittedLookup(db, secondary) { - /** - * Uses the 'rsSyncApplyStop' fail point to stop application of oplog entries on the given - * secondary. - */ - function pauseReplication(sec) { - assert.commandWorked( - sec.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "alwaysOn"}), - "failed to enable fail point on secondary"); - } - - /** - * Turns off the 'rsSyncApplyStop' fail point to resume application of oplog entries on the - * given secondary. - */ - function resumeReplication(sec) { - assert.commandWorked( - sec.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"}), - "failed to disable fail point on secondary"); - } - - const aggCmdLookupObj = { - aggregate: "local", - pipeline: [ - { - $lookup: { - from: "foreign", - localField: "foreignKey", - foreignField: "matchedField", - as: "match", - } - }, - ], - readConcern: { - level: "majority", - } - }; - - const aggCmdGraphLookupObj = { - aggregate: "local", - pipeline: [{ - $graphLookup: { - from: "foreign", - startWith: '$foreignKey', - connectFromField: 'foreignKey', - connectToField: "matchedField", - as: "match" - } - }], - readConcern: { - level: "majority", - } - }; - - // Seed matching data. - const majorityWriteConcernObj = {writeConcern: {w: "majority", wtimeout: 60 * 1000}}; - db.local.deleteMany({}, majorityWriteConcernObj); - const localId = db.local.insertOne({foreignKey: "x"}, majorityWriteConcernObj).insertedId; - db.foreign.deleteMany({}, majorityWriteConcernObj); - const foreignId = - db.foreign.insertOne({matchedField: "x"}, majorityWriteConcernObj).insertedId; - - const expectedMatchedResult = [{ - _id: localId, - foreignKey: "x", - match: [ - {_id: foreignId, matchedField: "x"}, - ], - }]; - const expectedUnmatchedResult = [{ - _id: localId, - foreignKey: "x", - match: [], - }]; - - // Confirm lookup/graphLookup return the matched result. - let result = db.runCommand(aggCmdLookupObj).result; - assert.eq(result, expectedMatchedResult); - - result = db.runCommand(aggCmdGraphLookupObj).result; - assert.eq(result, expectedMatchedResult); - - // Stop oplog application on the secondary so that it won't acknowledge updates. - pauseReplication(secondary); - - // Update foreign data to no longer match, without a majority write concern. - db.foreign.updateOne({_id: foreignId}, {$set: {matchedField: "non-match"}}); - - // lookup/graphLookup should not see the update, since it has not been acknowledged by the - // secondary. - result = db.runCommand(aggCmdLookupObj).result; - assert.eq(result, expectedMatchedResult); - - result = db.runCommand(aggCmdGraphLookupObj).result; - assert.eq(result, expectedMatchedResult); - - // Restart oplog application on the secondary and wait for it's snapshot to catch up. - resumeReplication(secondary); - rst.awaitLastOpCommitted(); - - // Now lookup/graphLookup should report that the documents don't match. - result = db.runCommand(aggCmdLookupObj).result; - assert.eq(result, expectedUnmatchedResult); - - result = db.runCommand(aggCmdGraphLookupObj).result; - assert.eq(result, expectedUnmatchedResult); - } - - // - // Confirm majority readConcern works on a replica set. - // - const replSetName = "lookup_read_majority"; - let rst = new ReplSetTest({ - nodes: 3, - name: replSetName, - nodeOptions: { - enableMajorityReadConcern: "", - shardsvr: "", - } - }); - - if (!startSetIfSupportsReadMajority(rst)) { - jsTest.log("skipping test since storage engine doesn't support committed reads"); - return; - } - - const nodes = rst.nodeList(); - const config = { - _id: replSetName, - members: [ - {_id: 0, host: nodes[0]}, - {_id: 1, host: nodes[1], priority: 0}, - {_id: 2, host: nodes[2], arbiterOnly: true}, - ] - }; - updateConfigIfNotDurable(config); - rst.initiate(config); - - let shardSecondary = rst.liveNodes.slaves[0]; - - testReadCommittedLookup(rst.getPrimary().getDB("test"), shardSecondary); - - // - // Confirm read committed works on a cluster with a database that is not sharding enabled. - // - let st = new ShardingTest({ - manualAddShard: true, - }); - assert.commandWorked(st.s.adminCommand({addShard: rst.getURL()})); - testReadCommittedLookup(st.s.getDB("test"), shardSecondary); - - // - // Confirm read committed works on a cluster with: - // - A sharding enabled database - // - An unsharded local collection - // - assert.commandWorked(st.s.adminCommand({enableSharding: 'test'})); - testReadCommittedLookup(st.s.getDB("test"), shardSecondary); - - // - // Confirm read committed works on a cluster with: - // - A sharding enabled database - // - A sharded local collection. - // - assert.commandWorked(st.s.getDB("test").runCommand( - {createIndexes: 'local', indexes: [{name: "foreignKey_1", key: {foreignKey: 1}}]})); - assert.commandWorked(st.s.adminCommand({shardCollection: 'test.local', key: {foreignKey: 1}})); - testReadCommittedLookup(st.s.getDB("test"), shardSecondary); - - st.stop(); -})(); diff --git a/jstests/replsets/read_committed_lookup.js b/jstests/replsets/read_committed_lookup.js new file mode 100644 index 00000000000..d827e9580f3 --- /dev/null +++ b/jstests/replsets/read_committed_lookup.js @@ -0,0 +1,44 @@ +/** + * Tests that a $lookup and $graphLookup stage within an aggregation pipeline will read only + * committed data if the pipeline is using a majority readConcern. + */ + +load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority. +load("jstests/libs/read_committed_lib.js"); // For testReadCommittedLookup + +(function() { + "use strict"; + + // Confirm majority readConcern works on a replica set. + const replSetName = "lookup_read_majority"; + let rst = new ReplSetTest({ + nodes: 3, + name: replSetName, + nodeOptions: { + enableMajorityReadConcern: "", + shardsvr: "", + } + }); + + if (!startSetIfSupportsReadMajority(rst)) { + jsTest.log("skipping test since storage engine doesn't support committed reads"); + return; + } + + const nodes = rst.nodeList(); + const config = { + _id: replSetName, + members: [ + {_id: 0, host: nodes[0]}, + {_id: 1, host: nodes[1], priority: 0}, + {_id: 2, host: nodes[2], arbiterOnly: true}, + ] + }; + updateConfigIfNotDurable(config); + rst.initiate(config); + + let shardSecondary = rst.liveNodes.slaves[0]; + + testReadCommittedLookup(rst.getPrimary().getDB("test"), shardSecondary, rst); + +})(); diff --git a/jstests/sharding/read_committed_lookup.js b/jstests/sharding/read_committed_lookup.js new file mode 100644 index 00000000000..04200c3dcae --- /dev/null +++ b/jstests/sharding/read_committed_lookup.js @@ -0,0 +1,64 @@ +/** + * Tests that a $lookup and $graphLookup stage within an aggregation pipeline will read only + * committed data if the pipeline is using a majority readConcern. + */ + +load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority. +load("jstests/libs/read_committed_lib.js"); // For testReadCommittedLookup + +(function() { + + // Manually create a shard. + const replSetName = "lookup_read_majority"; + let rst = new ReplSetTest({ + nodes: 3, + name: replSetName, + nodeOptions: { + enableMajorityReadConcern: "", + shardsvr: "", + } + }); + + if (!startSetIfSupportsReadMajority(rst)) { + jsTest.log("skipping test since storage engine doesn't support committed reads"); + return; + } + + const nodes = rst.nodeList(); + const config = { + _id: replSetName, + members: [ + {_id: 0, host: nodes[0]}, + {_id: 1, host: nodes[1], priority: 0}, + {_id: 2, host: nodes[2], arbiterOnly: true}, + ] + }; + updateConfigIfNotDurable(config); + rst.initiate(config); + + let shardSecondary = rst.liveNodes.slaves[0]; + + // Confirm read committed works on a cluster with a database that is not sharding enabled. + let st = new ShardingTest({ + manualAddShard: true, + }); + assert.commandWorked(st.s.adminCommand({addShard: rst.getURL()})); + testReadCommittedLookup(st.s.getDB("test"), shardSecondary, rst); + + // Confirm read committed works on a cluster with: + // - A sharding enabled database + // - An unsharded local collection + assert.commandWorked(st.s.adminCommand({enableSharding: 'test'})); + testReadCommittedLookup(st.s.getDB("test"), shardSecondary, rst); + + // Confirm read committed works on a cluster with: + // - A sharding enabled database + // - A sharded local collection. + assert.commandWorked(st.s.getDB("test").runCommand( + {createIndexes: 'local', indexes: [{name: "foreignKey_1", key: {foreignKey: 1}}]})); + assert.commandWorked(st.s.adminCommand({shardCollection: 'test.local', key: {foreignKey: 1}})); + testReadCommittedLookup(st.s.getDB("test"), shardSecondary, rst); + + st.stop(); + +})(); |