From 1512c333827379f6ae74a4e2cceeaadbe768ba04 Mon Sep 17 00:00:00 2001 From: Christopher Caplinger Date: Mon, 14 Mar 2022 15:02:12 +0000 Subject: SERVER-64456: Use countDocuments() instead of count() to ensure accurate document count --- jstests/replsets/tenant_migration_collection_ttl.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jstests/replsets/tenant_migration_collection_ttl.js b/jstests/replsets/tenant_migration_collection_ttl.js index e76196b4fa4..6571e08c214 100644 --- a/jstests/replsets/tenant_migration_collection_ttl.js +++ b/jstests/replsets/tenant_migration_collection_ttl.js @@ -77,7 +77,13 @@ function waitForOneTTLPassAtNode(node) { } function getDocumentCount(dbName, node) { - return node.getDB(dbName)[collName].count(); + // Use "countDocuments" instead of "count" to ensure that we get an accurate + // count instead of an approximate count from metadata. Otherwise, the count + // can be inaccurate if a TTL pass happens concurrently with the count call when + // the access blocker is blocking writes. In this case, the TTL delete will fail and + // be rolled back, but count calls before the rollback is applied will still reflect + // the delete. + return node.getDB(dbName)[collName].countDocuments({}); } function assertTTLNotDeleteExpiredDocs(dbName, node) { -- cgit v1.2.1