From 936fbbe8b45ed9a9a5ba78a327d3f0f6cb3974d2 Mon Sep 17 00:00:00 2001 From: Bernard Gorman Date: Fri, 4 Dec 2020 15:53:59 +0000 Subject: SERVER-53233 Fix change_streams_update_lookup_shard_metadata_missing.js to pull from the correct cursor (cherry picked from commit 9b518b1c13000e6c0568ee43d520b6bd712e820a) --- ...streams_update_lookup_shard_metadata_missing.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 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 index 8e91f160773..212a795e453 100644 --- a/jstests/sharding/change_streams_update_lookup_shard_metadata_missing.js +++ b/jstests/sharding/change_streams_update_lookup_shard_metadata_missing.js @@ -32,7 +32,7 @@ st.shardColl(mongosColl, {a: 1}, {a: 0}, {a: 1}); // Open a change stream on the collection. - const csCursor = mongosColl.watch(); + let csCursor = mongosColl.watch(); // Write one document onto shard0 and obtain its resume token. assert.commandWorked(mongosColl.insert({_id: 0, a: -100})); @@ -58,17 +58,19 @@ 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: {} - })); - + // Resume the change stream with {fullDocument: 'updateLookup'}. Update lookup can successfully + // identify the document based on its _id alone so long as the _id is unique in the collection, + // so this alone does not prove that the multi-update wrote its shard key into the oplog. + csCursor = mongosColl.watch([], {resumeAfter: resumeToken, fullDocument: "updateLookup"}); assert.soon(() => csCursor.hasNext()); + assert.docEq(csCursor.next().fullDocument, {_id: 0, a: -100, updated: true}); - const updateObj = csCursor.next(); - - assert.eq(true, updateObj.updateDescription.updatedFields.updated); + // Now insert a new document with the same _id on the other shard. Update lookup will be able to + // distinguish between the two, proving that they both have full shard keys available. + assert.commandWorked(mongosColl.insert({_id: 0, a: 100})); + csCursor = mongosColl.watch([], {resumeAfter: resumeToken, fullDocument: "updateLookup"}); + assert.soon(() => csCursor.hasNext()); + assert.docEq(csCursor.next().fullDocument, {_id: 0, a: -100, updated: true}); st.stop(); })(); \ No newline at end of file -- cgit v1.2.1