[SERVER-57578] Use isEmpty instead of numRecords to check if there are any documents left in a collection Created: 09/Jun/21  Updated: 29/Oct/23  Resolved: 15/Jun/21

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Jason Zhang Assignee: Benety Goh
Resolution: Fixed Votes: 0
Labels: neweng, sharding-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to SERVER-45718 Index builder can skip index building... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Execution Team 2021-06-28
Participants:
Linked BF Score: 15

 Description   

We use Collection::numRecords here to check if there are any more documents. Due to the unreliability of Collection::numRecords (see BF-20792 for more details), we should replace the check with Collection::isEmpty.



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 16/Jun/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-57578 CreateIndexesCmd::runCreateIndexesOnNewCollection() checks collection state using Collection::isEmpty() instead of numRecords()
Branch: SERVER-34632
https://github.com/mongodb/mongo/commit/77156e1bcb57788cfc1d80a51233301eba0beed9

Comment by Githook User [ 16/Jun/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-57578 NonShardServerProcessInterface::createIndexesOnEmptyCollection() uses Collection::isEmpty() instead of numRecords()
Branch: SERVER-34632
https://github.com/mongodb/mongo/commit/5dc06b3ff47fe60838537f9e82818d41693ffa75

Comment by Githook User [ 16/Jun/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-57578 MigrationDestinationManager checks collection state using Collection::isEmpty()

Using Collection::isEmpty() is preferred to numRecords() because the former is more reliable
in cases where we do not need to know the exact number of documents in a collection.
Collection::numRecords() depends on the fast count cache which may become inaccurate due to
stepdowns and unclean shutdowns.
Branch: SERVER-34632
https://github.com/mongodb/mongo/commit/0ff1cb8c8735fb596d1e925471e1c4d71c935911

Comment by Githook User [ 14/Jun/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-57578 CreateIndexesCmd::runCreateIndexesOnNewCollection() checks collection state using Collection::isEmpty() instead of numRecords()
Branch: master
https://github.com/mongodb/mongo/commit/77156e1bcb57788cfc1d80a51233301eba0beed9

Comment by Githook User [ 14/Jun/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-57578 NonShardServerProcessInterface::createIndexesOnEmptyCollection() uses Collection::isEmpty() instead of numRecords()
Branch: master
https://github.com/mongodb/mongo/commit/5dc06b3ff47fe60838537f9e82818d41693ffa75

Comment by Githook User [ 14/Jun/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-57578 MigrationDestinationManager checks collection state using Collection::isEmpty()

Using Collection::isEmpty() is preferred to numRecords() because the former is more reliable
in cases where we do not need to know the exact number of documents in a collection.
Collection::numRecords() depends on the fast count cache which may become inaccurate due to
stepdowns and unclean shutdowns.
Branch: master
https://github.com/mongodb/mongo/commit/0ff1cb8c8735fb596d1e925471e1c4d71c935911

Generated at Thu Feb 08 05:42:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.