Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MB-54221: Make LinkedList field read for stats atomic
A TSAN failure has been seen: WARNING: ThreadSanitizer: data race (pid=28207) Write of size 8 at 0x7b4400001a00 by thread T21: #0 cb::NonNegativeCounter<unsigned long, cb::DefaultUnderflowPolicy>::fetch_sub(long) ../platform/include/platform/non_negative_counter.h:142 (ep_testsuite+0x5bd248) #1 cb::NonNegativeCounter<unsigned long, cb::DefaultUnderflowPolicy>::operator--() ../platform/include/platform/non_negative_counter.h:175 (ep_testsuite+0x9a535d) #2 BasicLinkedList::purgeListElem(boost::intrusive::list_iterator<boost::intrusive::mhtraits<OrderedStoredValue, boost::intrusive::list_member_hook<>, &OrderedStoredValue::seqno_hook>, false>, bool, bool) /home/couchbase/jenkins/workspace/kv_engine.threadsanitizer_master/kv_engine/engines/ep/src/linked_list.cc:412 (ep_testsuite+0xa948c1) Previous read of size 8 at 0x7b4400001a00 by main thread (mutexes: write M3032, write M1005282691001636776): #0 cb::NonNegativeCounter<unsigned long, cb::DefaultUnderflowPolicy>::load() const ../platform/include/platform/non_negative_counter.h:89 (ep_testsuite+0x5bcd35) #1 cb::NonNegativeCounter<unsigned long, cb::DefaultUnderflowPolicy>::operator unsigned long() const ../platform/include/platform/non_negative_counter.h:85 (ep_testsuite+0x687165) #2 BasicLinkedList::getNumStaleItems() const /home/couchbase/jenkins/workspace/kv_engine.threadsanitizer_master/kv_engine/engines/ep/src/linked_list.cc:307 (ep_testsuite+0xa94a7c) This is seen because we read the non-atomic numStaleItems from EphemeralVBucket::CountVisitor without a lock, while the value could be changed from another thread. We don't want to have to lock the list just to read the stats. Make the fields read for stats atomic to resolve the race condition. They are only used for stats; it does not need to be read with any particular consistency with other values. If it had, acquiring the listWriteLock would be required. Change-Id: Ie557b1363ffd987ef108c19e2bfc200481c6e5f1 Co-Authored-By: Vesko Karaganev <[email protected]> Reviewed-on: https://review.couchbase.org/c/kv_engine/+/189597 Tested-by: Vesko Karaganev <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
- Loading branch information