diff options
author | Adi Zaimi <adizaimi@yahoo.com> | 2023-01-18 21:23:20 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-18 22:00:02 +0000 |
commit | 02502cf9ba7cafdfcbef7810991b3cdc8ba08c4c (patch) | |
tree | 0cb13bc8b317b04bcf6ebcbab0144a0695a44a9b /jstests | |
parent | a317c9b75dbd84687acc53af4f4c3c5afa6dcc7e (diff) | |
download | mongo-02502cf9ba7cafdfcbef7810991b3cdc8ba08c4c.tar.gz |
SERVER-67795: Add serverstatus counters for updateMany, deleteMany calls(v4.4)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/sharding/server_status_crud_metrics.js | 22 | ||||
-rw-r--r-- | jstests/sharding/update_delete_many_metrics.js | 121 |
2 files changed, 132 insertions, 11 deletions
diff --git a/jstests/sharding/server_status_crud_metrics.js b/jstests/sharding/server_status_crud_metrics.js index 62a513242ca..7c30b6bd708 100644 --- a/jstests/sharding/server_status_crud_metrics.js +++ b/jstests/sharding/server_status_crud_metrics.js @@ -26,8 +26,8 @@ assert.commandWorked(unshardedColl.insert({x: 1, _id: 1})); // Verification for 'updateOneOpStyleBroadcastWithExactIDCount' metric. // Should increment the metric as the update cannot target single shard and are {multi:false}. -assert.commandWorked(testDB.coll.update({_id: "missing"}, {$set: {a: 1}}, {multi: false})); -assert.commandWorked(testDB.coll.update({_id: 1}, {$set: {a: 2}}, {multi: false})); +assert.commandWorked(testColl.update({_id: "missing"}, {$set: {a: 1}}, {multi: false})); +assert.commandWorked(testColl.update({_id: 1}, {$set: {a: 2}}, {multi: false})); // Should increment the metric because we broadcast by _id, even though the update subsequently // fails on the individual shard. @@ -42,21 +42,21 @@ let mongosServerStatus = testDB.adminCommand({serverStatus: 1}); assert.eq(4, mongosServerStatus.metrics.query.updateOneOpStyleBroadcastWithExactIDCount); // Shouldn't increment the metric when {multi:true}. -assert.commandWorked(testDB.coll.update({_id: 1}, {$set: {a: 3}}, {multi: true})); -assert.commandWorked(testDB.coll.update({}, {$set: {a: 3}}, {multi: true})); +assert.commandWorked(testColl.update({_id: 1}, {$set: {a: 3}}, {multi: true})); +assert.commandWorked(testColl.update({}, {$set: {a: 3}}, {multi: true})); // Shouldn't increment the metric when update can target single shard. -assert.commandWorked(testDB.coll.update({x: 11}, {$set: {a: 2}}, {multi: false})); -assert.commandWorked(testDB.coll.update({x: 1}, {$set: {a: 2}}, {multi: false})); +assert.commandWorked(testColl.update({x: 11}, {$set: {a: 2}}, {multi: false})); +assert.commandWorked(testColl.update({x: 1}, {$set: {a: 2}}, {multi: false})); // Shouldn't increment the metric for replacement style updates. -assert.commandWorked(testDB.coll.update({_id: 1}, {x: 1, a: 2})); -assert.commandWorked(testDB.coll.update({x: 1}, {x: 1, a: 1})); +assert.commandWorked(testColl.update({_id: 1}, {x: 1, a: 2})); +assert.commandWorked(testColl.update({x: 1}, {x: 1, a: 1})); // Shouldn't increment the metric when routing fails. -assert.commandFailedWithCode(testDB.coll.update({}, {$set: {x: 2}}, {multi: false}), +assert.commandFailedWithCode(testColl.update({}, {$set: {x: 2}}, {multi: false}), ErrorCodes.InvalidOptions); -assert.commandFailedWithCode(testDB.coll.update({_id: 1}, {$set: {x: 2}}, {upsert: true}), +assert.commandFailedWithCode(testColl.update({_id: 1}, {$set: {x: 2}}, {upsert: true}), ErrorCodes.ShardKeyNotFound); // Shouldn't increment the metrics for unsharded collection. @@ -65,7 +65,7 @@ assert.commandWorked(unshardedColl.update({_id: 1}, {$set: {a: 2}}, {multi: fals // Shouldn't incement the metrics when query had invalid operator. assert.commandFailedWithCode( - testDB.coll.update({_id: 1, $invalidOperator: 1}, {$set: {a: 2}}, {multi: false}), + testColl.update({_id: 1, $invalidOperator: 1}, {$set: {a: 2}}, {multi: false}), ErrorCodes.BadValue); mongosServerStatus = testDB.adminCommand({serverStatus: 1}); diff --git a/jstests/sharding/update_delete_many_metrics.js b/jstests/sharding/update_delete_many_metrics.js new file mode 100644 index 00000000000..bfa3dc86d09 --- /dev/null +++ b/jstests/sharding/update_delete_many_metrics.js @@ -0,0 +1,121 @@ +/** + * Tests for the 'metrics.query' section of the mongos and mongod serverStatus response verifying + * counters for updateMany and deleteMany + * @tags: [multiversion_incompatible] + */ + +(function() { +"use strict"; + +{ + const st = new ShardingTest({shards: 2, rs: {nodes: 2}}); + const mongodConns = []; + st.rs0.nodes.forEach(node => mongodConns.push(node)); + st.rs1.nodes.forEach(node => mongodConns.push(node)); + + const testDB = st.s.getDB("test"); + const testColl = testDB.coll; + const unshardedColl = testDB.unsharded; + + assert.commandWorked(st.s0.adminCommand({enableSharding: testDB.getName()})); + st.ensurePrimaryShard(testDB.getName(), st.shard0.shardName); + + // Shard testColl on {x:1}, split it at {x:0}, and move chunk {x:1} to shard1. + st.shardColl(testColl, {x: 1}, {x: 0}, {x: 1}); + + // Insert one document on each shard. + assert.commandWorked(testColl.insert({x: 1, _id: 1})); + assert.commandWorked(testColl.insert({x: -1, _id: 0})); + + assert.eq(2, testColl.countDocuments({})); + assert.commandWorked(unshardedColl.insert({x: 1, _id: 1})); + assert.eq(1, unshardedColl.countDocuments({})); + + let mongosServerStatus = testDB.adminCommand({serverStatus: 1}); + // Verification for 'updateManyCount' metric. + assert.eq(0, mongosServerStatus.metrics.query.updateManyCount); + // Verification for 'deleteManyCount' metric. + assert.eq(0, mongosServerStatus.metrics.query.deleteManyCount); + + assert.commandWorked(unshardedColl.update({_id: 1}, {$set: {a: 2}}, {multi: false})); + assert.commandWorked(testColl.update({_id: 1}, {$set: {a: 2}}, {multi: false})); + // 3 update with multi:true calls. + assert.commandWorked(unshardedColl.update({_id: 1}, {$set: {a: 2}}, {multi: true})); + assert.commandWorked(testColl.update({}, {$set: {a: 3}}, {multi: true})); + assert.commandWorked(testColl.update({_id: 1}, {$set: {a: 2}}, {multi: true})); + + // 2 updateMany calls. + assert.commandWorked(testColl.updateMany({}, {$set: {array: 'string', doc: 'string'}})); + assert.commandWorked(unshardedColl.updateMany({}, {$set: {array: 'string', doc: 'string'}})); + + // Use deleteMany to delete one of the documents. + const result = testColl.deleteMany({_id: 1}); + assert.commandWorked(result); + assert.eq(1, result.deletedCount); + assert.eq(1, testColl.countDocuments({})); + // Next call will not increase count. + assert.commandWorked(testColl.deleteOne({_id: 1})); + + // Use deleteMany to delete one document in the unsharded collection. + assert.commandWorked(unshardedColl.deleteMany({_id: 1})); + // Next call will not increase count. + assert.commandWorked(unshardedColl.deleteOne({_id: 1})); + + mongosServerStatus = testDB.adminCommand({serverStatus: 1}); + + // Verification for 'updateManyCount' metric. + assert.eq(5, mongosServerStatus.metrics.query.updateManyCount); + // Verification for 'deleteManyCount' metric. + assert.eq(2, mongosServerStatus.metrics.query.deleteManyCount); + + st.stop(); +} + +{ + const rst = new ReplSetTest({nodes: 2}); + rst.startSet(); + rst.initiate(); + + const primary = rst.getPrimary(); + const testDB = primary.getDB("test"); + const testColl = testDB.coll; + const unshardedColl = testDB.unsharded; + + // Insert one document on each shard. + assert.commandWorked(testColl.insert({x: 1, _id: 1})); + assert.commandWorked(testColl.insert({x: -1, _id: 0})); + assert.eq(2, testColl.countDocuments({})); + + let mongosServerStatus = testDB.adminCommand({serverStatus: 1}); + + // Verification for 'updateManyCount' metric. + assert.eq(0, mongosServerStatus.metrics.query.updateManyCount); + // Verification for 'deleteManyCount' metric. + assert.eq(0, mongosServerStatus.metrics.query.deleteManyCount); + + assert.commandWorked(testColl.update({_id: 1}, {$set: {a: 2}}, {multi: false})); + // 3 update with multi:true calls. + assert.commandWorked(testColl.update({}, {$set: {a: 3}}, {multi: true})); + assert.commandWorked(testColl.update({_id: 1}, {$set: {a: 2}}, {multi: true})); + + // 2 updateMany call. + assert.commandWorked(testColl.updateMany({}, {$set: {array: 'string', doc: 'string'}})); + + // Use deleteMany to delete one of the documents. + const result = testColl.deleteMany({_id: 1}); + assert.commandWorked(result); + assert.eq(1, result.deletedCount); + assert.eq(1, testColl.countDocuments({})); + // Next call will not increase count. + assert.commandWorked(testColl.deleteOne({_id: 1})); + + mongosServerStatus = testDB.adminCommand({serverStatus: 1}); + + // Verification for 'updateManyCount' metric. + assert.eq(3, mongosServerStatus.metrics.query.updateManyCount); + // Verification for 'deleteManyCount' metric. + assert.eq(1, mongosServerStatus.metrics.query.deleteManyCount); + + rst.stopSet(); +} +})(); |