summaryrefslogtreecommitdiff
path: root/jstests/sharding
diff options
context:
space:
mode:
authorAdi Zaimi <adizaimi@yahoo.com>2022-11-08 23:57:29 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-09 00:36:21 +0000
commit96352a08d339f7f86e3b1365b834145ce5ad08e5 (patch)
tree9f8e2fbbd7e83702387192be363e257a2bc4994d /jstests/sharding
parentf803681c3ae19817d31958965850193de067c516 (diff)
downloadmongo-96352a08d339f7f86e3b1365b834145ce5ad08e5.tar.gz
SERVER-67795: Add serverstatus counters for updateMany, deleteMany calls (v6.0)
Diffstat (limited to 'jstests/sharding')
-rw-r--r--jstests/sharding/server_status_crud_metrics.js29
-rw-r--r--jstests/sharding/update_delete_many_metrics.js122
2 files changed, 136 insertions, 15 deletions
diff --git a/jstests/sharding/server_status_crud_metrics.js b/jstests/sharding/server_status_crud_metrics.js
index 4f83d7e4b6e..99821f78b4c 100644
--- a/jstests/sharding/server_status_crud_metrics.js
+++ b/jstests/sharding/server_status_crud_metrics.js
@@ -26,15 +26,14 @@ 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.
-assert.commandFailedWithCode(testDB.coll.update({_id: 1}, {$set: {x: 2}}, {multi: false}), 31025);
-assert.commandFailedWithCode(
- testDB.coll.update({_id: 1}, {$set: {x: 12}, $hello: 1}, {multi: false}),
- ErrorCodes.FailedToParse);
+assert.commandFailedWithCode(testColl.update({_id: 1}, {$set: {x: 2}}, {multi: false}), 31025);
+assert.commandFailedWithCode(testColl.update({_id: 1}, {$set: {x: 12}, $hello: 1}, {multi: false}),
+ ErrorCodes.FailedToParse);
let mongosServerStatus = testDB.adminCommand({serverStatus: 1});
@@ -42,21 +41,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 +64,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..af7daf59d20
--- /dev/null
+++ b/jstests/sharding/update_delete_many_metrics.js
@@ -0,0 +1,122 @@
+/**
+ * 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();
+}
+})();