diff options
author | Cheahuychou Mao <mao.cheahuychou@gmail.com> | 2022-11-11 21:31:36 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-11 22:01:51 +0000 |
commit | 654aa51fc14325b279b525900c814e4283bfe284 (patch) | |
tree | bb1e93b28670c7557a9b58eca812ec448c7d2c3a | |
parent | baafd67539f65f9ab620f4d67431881013fa66b5 (diff) | |
download | mongo-654aa51fc14325b279b525900c814e4283bfe284.tar.gz |
SERVER-71281 Make opcounters.command on mongos not count inserts, updates and deletes
-rw-r--r-- | jstests/sharding/catalog_cache_refresh_counters.js | 16 | ||||
-rw-r--r-- | jstests/sharding/opcounters.js | 54 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_write_cmd.h | 4 |
3 files changed, 68 insertions, 6 deletions
diff --git a/jstests/sharding/catalog_cache_refresh_counters.js b/jstests/sharding/catalog_cache_refresh_counters.js index 028ef2f2c59..f4422f4ab76 100644 --- a/jstests/sharding/catalog_cache_refresh_counters.js +++ b/jstests/sharding/catalog_cache_refresh_counters.js @@ -67,13 +67,17 @@ let runTest = (operationToRunFn, expectedOpIncreases) => { setUp(); +// TODO (SERVER-71289): Remove mongos version check in catalog_cache_refresh_counters.js. +const isLatestMongos = jsTestOptions().mongosBinVersion !== "last-lts" && + jsTestOptions().mongosBinVersion !== "last-continuous"; + /** * Verify that insert operations get logged when blocked by a refresh. */ runTest(() => assert.commandWorked(mongos1Coll.insert({x: 250})), [ - {opType: 'countAllOperations', increase: 2}, + {opType: 'countAllOperations', increase: isLatestMongos ? 1 : 2}, {opType: 'countInserts', increase: 1}, - {opType: 'countCommands', increase: 1} + {opType: 'countCommands', increase: isLatestMongos ? 0 : 1} ]); /** @@ -86,18 +90,18 @@ runTest(() => mongos1Coll.findOne({x: 250}), * Verify that updates get logged when blocked by a refresh. */ runTest(() => assert.commandWorked(mongos1Coll.update({x: 250}, {$set: {a: 1}})), [ - {opType: 'countAllOperations', increase: 2}, + {opType: 'countAllOperations', increase: isLatestMongos ? 1 : 2}, {opType: 'countUpdates', increase: 1}, - {opType: 'countCommands', increase: 1} + {opType: 'countCommands', increase: isLatestMongos ? 0 : 1} ]); /** * Verify that deletes get logged when blocked by a refresh. */ runTest(() => assert.commandWorked(mongos1Coll.remove({x: 250})), [ - {opType: 'countAllOperations', increase: 2}, + {opType: 'countAllOperations', increase: isLatestMongos ? 1 : 2}, {opType: 'countDeletes', increase: 1}, - {opType: 'countCommands', increase: 1} + {opType: 'countCommands', increase: isLatestMongos ? 0 : 1} ]); /** diff --git a/jstests/sharding/opcounters.js b/jstests/sharding/opcounters.js new file mode 100644 index 00000000000..5032a7cb967 --- /dev/null +++ b/jstests/sharding/opcounters.js @@ -0,0 +1,54 @@ +/** + * Tests that opcounters.command on mongos doesn't count inserts, updates and deletes. + * + * @tags: [requires_fcv_62] + */ + +(function() { +'use strict'; + +const st = new ShardingTest({mongos: 2, shards: 1}); + +function getOpCounters(conn) { + const opcounters = assert.commandWorked(conn.adminCommand({serverStatus: 1})).opcounters; + jsTest.log("opcounters " + tojson(opcounters)); + return opcounters; +} + +const dbName = "testDb"; +const collName = "testColl"; +const mongosDB = st.s.getDB(dbName); + +{ + const opCountersBefore = getOpCounters(st.s); + assert.commandWorked(mongosDB.runCommand({insert: collName, documents: [{x: 0}]})); + const opCountersAfter = getOpCounters(st.s); + + assert.eq(opCountersAfter.insert, opCountersBefore.insert + 1); + // "command" should only increase by 1 (i.e. count only the 'serverStatus' command). + assert.eq(opCountersAfter.command, opCountersBefore.command + 1); +} + +{ + const opCountersBefore = getOpCounters(st.s); + assert.commandWorked( + mongosDB.runCommand({update: collName, updates: [{q: {x: 0}, u: {$set: {y: 0}}}]})); + const opCountersAfter = getOpCounters(st.s); + + assert.eq(opCountersAfter.update, opCountersBefore.update + 1); + // "command" should only increase by 1 (i.e. count only the 'serverStatus' command). + assert.eq(opCountersAfter.command, opCountersBefore.command + 1); +} + +{ + const opCountersBefore = getOpCounters(st.s); + assert.commandWorked(mongosDB.runCommand({delete: collName, deletes: [{q: {x: 0}, limit: 0}]})); + const opCountersAfter = getOpCounters(st.s); + + assert.eq(opCountersAfter.delete, opCountersBefore.delete + 1); + // "command" should only increase by 1 (i.e. count only the 'serverStatus' command). + assert.eq(opCountersAfter.command, opCountersBefore.command + 1); +} + +st.stop(); +})(); diff --git a/src/mongo/s/commands/cluster_write_cmd.h b/src/mongo/s/commands/cluster_write_cmd.h index 2b0bb507423..9151de7cd7b 100644 --- a/src/mongo/s/commands/cluster_write_cmd.h +++ b/src/mongo/s/commands/cluster_write_cmd.h @@ -50,6 +50,10 @@ public: return AllowedOnSecondary::kNever; } + bool shouldAffectCommandCounter() const final { + return false; + } + bool supportsRetryableWrite() const final { return true; } |