-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.2.3, 2.4.0-rc1
-
Component/s: Concurrency
-
Fully Compatible
-
ALL
-
-
Storage 2016-12-12
Once upon a time, the _insert counter in the OpCounters class was only ever incremented when the single global writelock was held. In that world, the implementation that uses a non-atomic operation to increment the counter wouldn't lead to lost counts, though it could hypothetically lead to incorrect reads if the _insert counter weren't 4-byte aligned.
Today, the function is often called without a global lock held (only a per database lock), making these adds lossy.
It would be wise to fix this, perhaps by consolidating the implementation of AtomicUInt with the AtomicWord<T> or at least the AtomicIntrinsics<T> from mongo/platform/atomic_word.h. This would also allow us to make these counters 64-bit instead of 32-bit, in case we're ever worried about rollover.