MB-19256: Address possible data race on VBCBAdaptor::currentvb 74/62974/6
authorabhinavdangeti <abhinav@couchbase.com>
Mon, 5 Oct 2015 20:06:13 +0000 (13:06 -0700)
committerChiyoung Seo <chiyoung@couchbase.com>
Sat, 23 Apr 2016 01:08:07 +0000 (01:08 +0000)
WARNING: ThreadSanitizer: data race (pid=12312)

Read of size 2 at 0x7d400000fff8 by main thread (mutexes: write M12542):
    #0 VBCBAdaptor::getDescription() /home/abhinav/couchbase/ep-engine/src/ep.h:128 (ep.so+0x0000000a7fe1)
    #1 ExecutorPool::_stopTaskGroup(unsigned long, task_type_t, bool) /home/abhinav/couchbase/ep-engine/src/executorpool.cc:562 (ep.so+0x0000000f3c21)
    #2 ExecutorPool::stopTaskGroup(unsigned long, task_type_t, bool) /home/abhinav/couchbase/ep-engine/src/executorpool.cc:585 (ep.so+0x0000000f3f5e)
    #3 ~EventuallyPersistentStore /home/abhinav/couchbase/ep-engine/src/ep.cc:468 (ep.so+0x0000000836c6)
    #4 ~EventuallyPersistentEngine /home/abhinav/couchbase/ep-engine/src/ep_engine.cc:6326 (ep.so+0x0000000d4eda)
    #5 EvpDestroy(engine_interface*, bool) /home/abhinav/couchbase/ep-engine/src/ep_engine.cc:141 (ep.so+0x0000000b4b8c)
    #6 mock_destroy(engine_interface*, bool) /home/abhinav/couchbase/memcached/programs/engine_testapp/engine_testapp.cc:98 (engine_testapp+0x0000000ba027)
    #7 destroy_bucket(engine_interface*, engine_interface_v1*, bool) /home/abhinav/couchbase/memcached/programs/engine_testapp/engine_testapp.cc:995 (engine_testapp+0x0000000b952e)
    #8 __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287 (libc.so.6+0x000000021ec4)

Previous write of size 2 at 0x7d400000fff8 by thread T10:
    #0 VBCBAdaptor::run() /home/abhinav/couchbase/ep-engine/src/ep.cc:3776 (ep.so+0x00000009d7e3)
    #1 ExecutorThread::run() /home/abhinav/couchbase/ep-engine/src/executorthread.cc:112 (ep.so+0x0000000f94d3)
    #2 launch_executor_thread(void*) /home/abhinav/couchbase/ep-engine/src/executorthread.cc:33 (ep.so+0x0000000f9055)
    #3 platform_thread_wrap /home/abhinav/couchbase/platform/src/cb_pthreads.c:23 (libplatform.so.0.1.0+0x000000003d31)

Change-Id: I316fb1a845fbee09f634d39e64057c170fab4795
Reviewed-on: http://review.couchbase.org/62974
Well-Formed: buildbot <build@couchbase.com>
Reviewed-by: Will Gardner <will.gardner@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
src/ep.cc
src/ep.h

index 76ca30c..4bcd493 100644 (file)
--- a/src/ep.cc
+++ b/src/ep.cc
@@ -3134,7 +3134,7 @@ VBCBAdaptor::VBCBAdaptor(EventuallyPersistentStore *s,
 
 bool VBCBAdaptor::run(void) {
     if (!vbList.empty()) {
-        currentvb = vbList.front();
+        currentvb.store(vbList.front());
         RCPtr<VBucket> vb = store->vbMap.getBucket(currentvb);
         if (vb) {
             if (visitor->pauseVisitor()) {
index 510d937..fcac2e7 100644 (file)
--- a/src/ep.h
+++ b/src/ep.h
@@ -122,7 +122,7 @@ public:
 
     std::string getDescription() {
         std::stringstream rv;
-        rv << label << " on vb " << currentvb;
+        rv << label << " on vb " << currentvb.load();
         return rv.str();
     }
 
@@ -134,7 +134,7 @@ private:
     shared_ptr<VBucketVisitor>  visitor;
     const char                 *label;
     double                      sleepTime;
-    uint16_t                    currentvb;
+    AtomicValue<uint16_t>       currentvb;
 
     DISALLOW_COPY_AND_ASSIGN(VBCBAdaptor);
 };