diff options
author | Ruoxin Xu <ruoxin.xu@mongodb.com> | 2022-07-25 14:00:10 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-27 18:12:53 +0000 |
commit | 00ab5dc0f33224d35141cb8af3e66cf4d590cb72 (patch) | |
tree | 888cdc5cfed74b990217465d422883bed67173dd /jstests | |
parent | 5b9d243e83a567ad42c5723037267f113bc28418 (diff) | |
download | mongo-00ab5dc0f33224d35141cb8af3e66cf4d590cb72.tar.gz |
SERVER-68041 Robustify merge_write_concern.js and add diagnostic log
(cherry picked from commit 7684a3e44eadcc9eaaf1b20cf0c13f2aa2b4e1f3)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/sharding/query/merge_write_concern.js | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/jstests/sharding/query/merge_write_concern.js b/jstests/sharding/query/merge_write_concern.js index 1aac599f0f8..a29c8b7e6b8 100644 --- a/jstests/sharding/query/merge_write_concern.js +++ b/jstests/sharding/query/merge_write_concern.js @@ -17,12 +17,21 @@ assert.commandWorked(mongosDB.adminCommand({enableSharding: mongosDB.getName()}) st.ensurePrimaryShard(mongosDB.getName(), st.shard0.shardName); function testWriteConcernError(rs) { + // Split the target collection at {_id: 10} so that there'll be doc $merge-ed to both shards. + if (FixtureHelpers.isSharded(target)) { + mongosDB.adminCommand({split: target.getFullName(), middle: {_id: 10}}); + } + // Make sure that there are only 2 nodes up so w:3 writes will always time out. const stoppedSecondary = rs.getSecondary(); rs.stop(stoppedSecondary); // Test that $merge correctly returns a WC error. withEachMergeMode(({whenMatchedMode, whenNotMatchedMode}) => { + // When either mode is "fail", a different error rather than WC error is thrown. + if (whenMatchedMode === "fail" || whenNotMatchedMode === "fail") { + return; + } const res = mongosDB.runCommand({ aggregate: "source", pipeline: [{ @@ -36,13 +45,24 @@ function testWriteConcernError(rs) { cursor: {}, }); + jsTestLog("Testing Mode: " + tojson(whenMatchedMode) + tojson(whenNotMatchedMode)); + jsTestLog("Target collection after $merge: " + tojson(target.find().toArray())); + + let oplogEntries = shard0.getPrimary() + .getDB("local") + .oplog.rs.find({"ns": {$regex: "merge_write_concern.*"}}) + .toArray(); + jsTestLog("Shard0 oplog entries: " + tojson(oplogEntries)); + oplogEntries = shard1.getPrimary() + .getDB("local") + .oplog.rs.find({"ns": {$regex: "merge_write_concern.*"}}) + .toArray(); + jsTestLog("Shard1 oplog entries: " + tojson(oplogEntries)); + // $merge writeConcern errors are handled differently from normal writeConcern // errors. Rather than returing ok:1 and a WriteConcernError, the entire operation // fails. - assert.commandFailedWithCode(res, - whenNotMatchedMode == "fail" - ? [13113, ErrorCodes.WriteConcernFailed] - : ErrorCodes.WriteConcernFailed); + assert.commandFailedWithCode(res, ErrorCodes.WriteConcernFailed); assert.commandWorked(target.remove({})); }); |