MB-19383: [BP] Address possible data race with startuptime 19/63419/4
authorabhinavdangeti <abhinav@couchbase.com>
Tue, 26 Apr 2016 21:03:11 +0000 (14:03 -0700)
committerabhinav dangeti <abhinav@couchbase.com>
Thu, 28 Apr 2016 00:14:46 +0000 (00:14 +0000)
WARNING: ThreadSanitizer: data race (pid=14344)

  Read of size 8 at 0x7d780000fa58 by thread T6:
    #0 void STATWRITER_NAMESPACE::add_casted_stat<long>(char const*, long const&, void (*)(char const*, unsigned short, char const*, unsigned int, void const*), void const*) /home/abhinav/couchbase/ep-engine/src/statwriter.h:45 (ep.so+0x000000037ff5)
    #1 EventuallyPersistentEngine::doEngineStats(void const*, void (*)(char const*, unsigned short, char const*, unsigned int, void const*)) /home/abhinav/couchbase/ep-engine/src/ep_engine.cc:3557 (ep.so+0x0000000be990)
    #2 EventuallyPersistentEngine::getStats(void const*, char const*, int, void (*)(char const*, unsigned short, char const*, unsigned int, void const*)) /home/abhinav/couchbase/ep-engine/src/ep_engine.cc:4554 (ep.so+0x0000000c5c8c)
    #3 EventuallyPersistentStore::snapshotStats() /home/abhinav/couchbase/ep-engine/src/ep.cc:1671 (ep.so+0x00000008f1fe)
    #4 StatSnap::run() /home/abhinav/couchbase/ep-engine/src/tasks.cc:97 (ep.so+0x00000013cea6)
    #5 ExecutorThread::run() /home/abhinav/couchbase/ep-engine/src/executorthread.cc:112 (ep.so+0x0000000f94e3)
    #6 launch_executor_thread(void*) /home/abhinav/couchbase/ep-engine/src/executorthread.cc:33 (ep.so+0x0000000f9065)
    #7 platform_thread_wrap /home/abhinav/couchbase/platform/src/cb_pthreads.c:23 (libplatform.so.0.1.0+0x000000003d31)

  Previous write of size 8 at 0x7d780000fa58 by main thread:
    #0 EventuallyPersistentEngine::initialize(char const*) /home/abhinav/couchbase/ep-engine/src/ep_engine.cc:2167 (ep.so+0x0000000b728a)
    #1 EvpInitialize(engine_interface*, char const*) /home/abhinav/couchbase/ep-engine/src/ep_engine.cc:133 (ep.so+0x0000000b4aa8)
    #2 init_engine_instance /home/abhinav/couchbase/memcached/utilities/engine_loader.c:157 (libmcd_util.so.1.0.0+0x0000000058bb)
    #3 create_bucket(bool, char const*) /home/abhinav/couchbase/memcached/programs/engine_testapp/engine_testapp.cc:980 (engine_testapp+0x0000000b9e12)
    #4 execute_test(test, char const*, char const*) /home/abhinav/couchbase/memcached/programs/engine_testapp/engine_testapp.cc:1083 (engine_testapp+0x0000000b93db)
    #5 __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287 (libc.so.6+0x000000021ec4)

(Reviewed-on: http://review.couchbase.org/55776)

Change-Id: Ibec6c267f9138aab626359c703fc067f91e1ee43
Reviewed-on: http://review.couchbase.org/63419
Well-Formed: buildbot <build@couchbase.com>
Reviewed-by: Will Gardner <will.gardner@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: abhinav dangeti <abhinav@couchbase.com>
src/ep_engine.cc
src/ep_engine.h

index 3e6c08f..57780e2 100644 (file)
@@ -2036,7 +2036,7 @@ ENGINE_ERROR_CODE EventuallyPersistentEngine::initialize(const char* config) {
     dcpConnMap_->initialize(DCP_CONN_NOTIFIER);
 
     // record engine initialization time
-    startupTime = ep_real_time();
+    startupTime.store(ep_real_time());
 
     LOG(EXTENSION_LOG_DEBUG, "Engine init complete.\n");
 
@@ -3382,7 +3382,7 @@ ENGINE_ERROR_CODE EventuallyPersistentEngine::doEngineStats(const void *cookie,
                         add_stat, cookie);
     }
 
-    add_casted_stat("ep_startup_time", startupTime, add_stat, cookie);
+    add_casted_stat("ep_startup_time", startupTime.load(), add_stat, cookie);
 
     if (getConfiguration().isWarmup()) {
         Warmup *wp = epstore->getWarmup();
index 657dfae..0eb5aa1 100644 (file)
@@ -915,7 +915,7 @@ private:
     bool flushAllEnabled;
     // a unique system generated token initialized at each time
     // ep_engine starts up.
-    time_t startupTime;
+    AtomicValue<time_t> startupTime;
 
 };