summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@mongodb.com>2019-12-17 11:34:39 +0000
committerevergreen <evergreen@mongodb.com>2019-12-17 11:34:39 +0000
commit85188fd753ef90a1e8ebd46e72f71e47d255da71 (patch)
tree94869ede01fc0d0647b5daac7456553a85dbf707 /jstests
parentcdfda6e9e9c4b14c4bdb55657a4c5cb91991acdf (diff)
downloadmongo-85188fd753ef90a1e8ebd46e72f71e47d255da71.tar.gz
SERVER-44733 Change stream should throw ChangeStreamFatalError if a single shard cannot be targeted for updateLookup
(cherry picked from commit ccecd50087d22d90df71ab3c5dd4a58905590307) (cherry picked from commit 20d508fbf59b05c6728162e85a9abfd06d41d0cd)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/sharding/change_streams_update_lookup_shard_metadata_missing.js65
-rw-r--r--jstests/sharding/resume_change_stream.js6
2 files changed, 68 insertions, 3 deletions
diff --git a/jstests/sharding/change_streams_update_lookup_shard_metadata_missing.js b/jstests/sharding/change_streams_update_lookup_shard_metadata_missing.js
new file mode 100644
index 00000000000..7e35b201438
--- /dev/null
+++ b/jstests/sharding/change_streams_update_lookup_shard_metadata_missing.js
@@ -0,0 +1,65 @@
+/**
+ * Tests that an updateLookup change stream throws ChangeStreamFatalError when it encounters an
+ * oplog entry whose documentKey omits the shard key.
+ * TODO SERVER-44598: the oplog entry will no longer omit the shard key when SERVER-44598 is fixed,
+ * and so this test will no longer be relevant.
+ * @tags: [uses_change_streams]
+ */
+(function() {
+ "use strict";
+
+ // The UUID consistency check can hit NotMasterNoSlaveOk when it attempts to obtain a list of
+ // collections from the shard Primaries through mongoS at the end of this test.
+ TestData.skipCheckingUUIDsConsistentAcrossCluster = true;
+
+ // Start a new sharded cluster with 2 nodes and obtain references to the test DB and collection.
+ const st = new ShardingTest({
+ shards: 2,
+ mongos: 1,
+ rs: {nodes: 3, setParameter: {writePeriodicNoops: true, periodicNoopIntervalSecs: 1}}
+ });
+
+ const mongosDB = st.s.getDB(jsTestName());
+ const mongosColl = mongosDB.test;
+ const shard0 = st.rs0;
+
+ // Enable sharding on the the test database and ensure that the primary is shard0.
+ assert.commandWorked(mongosDB.adminCommand({enableSharding: mongosDB.getName()}));
+ st.ensurePrimaryShard(mongosDB.getName(), shard0.getURL());
+
+ // Shard the source collection on {a: 1}, split across the shards at {a: 0}.
+ st.shardColl(mongosColl, {a: 1}, {a: 0}, {a: 1});
+
+ // Open a change stream on the collection.
+ const csCursor = mongosColl.watch();
+
+ // Write one document onto shard0 and obtain its resume token.
+ assert.commandWorked(mongosColl.insert({_id: 0, a: -100}));
+ assert.soon(() => csCursor.hasNext());
+
+ const resumeToken = csCursor.next()._id;
+
+ // Step up one of the Secondaries, which will not have any sharding metadata loaded.
+ shard0.stepUpNoAwaitReplication(shard0.getSecondary());
+
+ // Do a {multi:true} update. This will scatter to all shards and update the document on shard0.
+ // Because no metadata is loaded, this will write the update into the oplog with a documentKey
+ // containing only the _id field.
+ assert.soonNoExcept(() => assert.commandWorked(
+ mongosColl.update({_id: 0}, {$set: {updated: true}}, false, true)));
+
+ // Resume the change stream with {fullDocument: 'updateLookup'}.
+ const cmdRes = assert.commandWorked(mongosColl.runCommand("aggregate", {
+ pipeline: [{$changeStream: {resumeAfter: resumeToken, fullDocument: "updateLookup"}}],
+ cursor: {}
+ }));
+
+ // Begin pulling from the stream. We should hit a ChangeStreamFatalError when the updateLookup
+ // attempts to read the update entry that is missing the shard key value of the document.
+ assert.soonNoExcept(
+ () => assert.commandFailedWithCode(
+ mongosColl.runCommand({getMore: cmdRes.cursor.id, collection: mongosColl.getName()}),
+ ErrorCodes.ChangeStreamFatalError));
+
+ st.stop();
+})(); \ No newline at end of file
diff --git a/jstests/sharding/resume_change_stream.js b/jstests/sharding/resume_change_stream.js
index 9b5e33d0173..fa8fa12debf 100644
--- a/jstests/sharding/resume_change_stream.js
+++ b/jstests/sharding/resume_change_stream.js
@@ -124,14 +124,14 @@
db: mongosDB,
collName: collToWatch,
pipeline: [{$changeStream: {resumeAfter: resumeTokenFromFirstUpdateOnShard1}}],
- expectedCode: 40576
+ expectedCode: ErrorCodes.ChangeStreamFatalError
});
ChangeStreamTest.assertChangeStreamThrowsCode({
db: mongosDB,
collName: collToWatch,
pipeline: [{$changeStream: {startAtOperationTime: resumeTimeFirstUpdate}}],
- expectedCode: 40576
+ expectedCode: ErrorCodes.ChangeStreamFatalError
});
// Test that the change stream can't resume if the resume token *is* present in the oplog,
@@ -143,7 +143,7 @@
db: mongosDB,
collName: collToWatch,
pipeline: [{$changeStream: {resumeAfter: resumeTokenFromFirstUpdateOnShard0}}],
- expectedCode: 40576
+ expectedCode: ErrorCodes.ChangeStreamFatalError
});
// Drop the collection.