|
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.
|