diff options
author | ali-mir <ali.mir@mongodb.com> | 2022-03-29 17:54:21 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-22 18:34:33 +0000 |
commit | 40a2da19ffc71fc9b22ea9c828ef9de6a79fa35a (patch) | |
tree | 52044ea1862f5ad8b34b007a3b6db3144376dfce /jstests | |
parent | 88f6fb33c3608ed20b55a7e0566815886a9d45f5 (diff) | |
download | mongo-40a2da19ffc71fc9b22ea9c828ef9de6a79fa35a.tar.gz |
SERVER-64741 Create mongos appendOplogNote command
(cherry picked from commit 55f3bca3212d994bf00f1165021db34b3ce1d0bb)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/sharding/append_oplog_note_mongos.js | 76 | ||||
-rw-r--r-- | jstests/sharding/database_and_shard_versioning_all_commands.js | 1 |
2 files changed, 77 insertions, 0 deletions
diff --git a/jstests/sharding/append_oplog_note_mongos.js b/jstests/sharding/append_oplog_note_mongos.js new file mode 100644 index 00000000000..1369ecb06be --- /dev/null +++ b/jstests/sharding/append_oplog_note_mongos.js @@ -0,0 +1,76 @@ +/** + * Tests that the 'appendOplogNote' command on mongos correctly performs a no-op write on each + * shard and advances the $clusterTime. + */ + +(function() { +"use strict"; + +load("jstests/libs/fail_point_util.js"); + +function checkOplogEntry(actualOplogEntry) { + const {op, o} = actualOplogEntry; + assert.eq({op, o}, {op: "n", o: {a: 2}}, actualOplogEntry); +} + +// We need to disable the periodic no-op writer so we can verify that the 'appendOplogNote' +// no-op is the latest operation on the oplog. +const st = new ShardingTest( + {mongos: 1, shards: 2, rs: {nodes: 2, setParameter: {writePeriodicNoops: false}}}); +const admin = st.getDB('admin'); +const shardOnePrimary = st.rs0.getPrimary(); +const shardTwoPrimary = st.rs1.getPrimary(); + +// Test that issuing the command without the 'data' field results in an error. +let res = assert.commandFailed(admin.runCommand({appendOplogNote: 1})); +assert.eq(res.code, ErrorCodes.NoSuchKey); +assert(res.hasOwnProperty("raw"), res); + +// Test that the error response contains the correct fields. +const appendOplogNoteFailpoint = configureFailPoint(shardOnePrimary, "failCommand", { + errorCode: ErrorCodes.HostUnreachable, + failCommands: ["appendOplogNote"], + failInternalCommands: true +}); + +res = assert.commandFailed(admin.runCommand({appendOplogNote: 1, data: {a: 1}})); +assert(res.hasOwnProperty("errmsg"), res); +assert.eq(res.code, ErrorCodes.HostUnreachable); +assert(res.hasOwnProperty("raw"), res); + +appendOplogNoteFailpoint.wait(); +appendOplogNoteFailpoint.off(); + +// Test that a successful 'appendOplogNote' command performs a no-op write and advances the +// $clusterTime. +const shardOneBefore = + assert.commandWorked(shardOnePrimary.getDB("admin").runCommand({replSetGetStatus: 1})); +const shardTwoBefore = + assert.commandWorked(shardTwoPrimary.getDB("admin").runCommand({replSetGetStatus: 1})); + +res = assert.commandWorked(admin.runCommand({appendOplogNote: 1, data: {a: 2}})); +assert(res.hasOwnProperty("raw"), res); + +const shardOneAfter = + assert.commandWorked(shardOnePrimary.getDB("admin").runCommand({replSetGetStatus: 1})); +const shardTwoAfter = + assert.commandWorked(shardTwoPrimary.getDB("admin").runCommand({replSetGetStatus: 1})); + +assert.lt(shardOneBefore.members[0].optime.ts, shardOneAfter.members[0].optime.ts); +assert.lt(shardTwoBefore.members[0].optime.ts, shardTwoAfter.members[0].optime.ts); + +let lastEntryShardOne = + shardOnePrimary.getDB("local").oplog.rs.find().sort({$natural: -1}).limit(1).toArray()[0]; +let lastEntryShardTwo = + shardTwoPrimary.getDB("local").oplog.rs.find().sort({$natural: -1}).limit(1).toArray()[0]; + +// The $clusterTime in the 'replSetGetStatus' response should be equal to the timestamp of +// 'appendOplogNote' command no-op write, which is the last operation on the shard oplogs. +checkOplogEntry(lastEntryShardOne); +checkOplogEntry(lastEntryShardTwo); + +assert.eq(shardOneAfter.members[0].optime.ts, lastEntryShardOne.ts); +assert.eq(shardTwoAfter.members[0].optime.ts, lastEntryShardTwo.ts); + +st.stop(); +}()); diff --git a/jstests/sharding/database_and_shard_versioning_all_commands.js b/jstests/sharding/database_and_shard_versioning_all_commands.js index ca9d56c8a80..6e001ef5a2d 100644 --- a/jstests/sharding/database_and_shard_versioning_all_commands.js +++ b/jstests/sharding/database_and_shard_versioning_all_commands.js @@ -57,6 +57,7 @@ let testCases = { sendsShardVersion: true, command: {aggregate: collName, pipeline: [{$match: {x: 1}}], cursor: {batchSize: 10}}, }, + appendOplogNote: {skip: "unversioned and executes on all shards"}, authenticate: {skip: "does not forward command to primary shard"}, availableQueryOptions: {skip: "executes locally on mongos (not sent to any remote node)"}, balancerStart: {skip: "not on a user database"}, |