[SERVER-73591] Data race involving SorterFileStats::_bytesSpilled Created: 03/Feb/23  Updated: 29/Oct/23  Resolved: 14/Feb/23

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

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: Adi Agrawal
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QE 2023-03-06
Participants:

 Description   

SorterFileStats keeps runtime stats associated with file IO done by the Sorter, our external sort implementation used to sort data both in query execution and during index builds. The opened and closed stats are both atomics. Why? Because it looks like the index building code keeps a single instance of SorterFileStats for all the index builds going on in the system. Presumably this means that multiple concurrent external sorts could be updating these stats concurrently.

The _bytesSpilled data member, however, is a plain long long. Unless I'm missing something, it therefore appears to be subject to a data race where multiple index builds are reading/writing this variable concurrently. It seems unlikely to cause problems in practice at the moment, but it goes without saying that we should avoid the possibility of UB.

A side note is that the SorterFileStats is also used by DocumentSourceGroupBase, but there is no data race in this case because each query allocates its own stats object that cannot be read by other threads.



 Comments   
Comment by Githook User [ 14/Feb/23 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'adi.agrawal@mongodb.com', 'username': 'Adityav369'}

Message: SERVER-73591 Make_bytesSpilled in sorterFileStats atomic
Branch: master
https://github.com/mongodb/mongo/commit/c315b8d211541600441fec639a9cc473479f2ee8

Generated at Thu Feb 08 06:25:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.