MB-19258: Address data race with replicationThrottle parameters 76/62976/8
authorabhinavdangeti <abhinav@couchbase.com>
Thu, 28 Jan 2016 20:31:56 +0000 (12:31 -0800)
committerChiyoung Seo <chiyoung@couchbase.com>
Sat, 23 Apr 2016 01:09:16 +0000 (01:09 +0000)
The detected usage is just in stats, however there is an indirect
usage of this variable (persistenceQueueSmallEnough, via
stats.replicationThrottleWriteQueueCap) which /might/ result in an
incorrect queue size being used.

WARNING: ThreadSanitizer: data race (pid=31345)
  Read of size 8 at 0x7d08000066c0 by thread T12:
    #0 ReplicationThrottle::adjustWriteQueueCap(unsigned long) ep-engine/src/replicationthrottle.cc:49 (ep.so+0x000000114c7f)
    #1 EventuallyPersistentEngine::doEngineStats(void const*, void (*)(char const*, unsigned short, char const*, unsigned int, void const*)) ep-engine/src/ep_engine.cc:3100 (ep.so+0x0000000bb424)
    #2 EventuallyPersistentEngine::getStats(void const*, char const*, int, void (*)(char const*, unsigned short, char const*, unsigned int, void const*)) ep-engine/src/ep_engine.cc:4597 (ep.so+0x0000000c54d5)
    #3 EventuallyPersistentStore::snapshotStats() ep-engine/src/ep.cc:1744 (ep.so+0x000000090f2e)
    #4 StatSnap::run() ep-engine/src/tasks.cc:100 (ep.so+0x000000136dd6)
    #5 ExecutorThread::run() ep-engine/src/executorthread.cc:115 (ep.so+0x0000000f6966)
    #6 launch_executor_thread(void*) ep-engine/src/executorthread.cc:33 (ep.so+0x0000000f6515)
    #7 platform_thread_wrap(void*) platform/src/cb_pthreads.cc:54 (libplatform.so.0.1.0+0x00000000551b)
12:23:35
  Previous write of size 8 at 0x7d08000066c0 by main thread (mutexes: write M2287262534014660504):
    #0 EPStoreValueChangeListener::sizeValueChanged(std::string const&, unsigned long) ep-engine/src/replicationthrottle.h:42 (ep.so+0x0000000b35ee)
    #1 Configuration::setParameter(std::string const&, long) ep-engine/src/configuration.cc:225 (ep.so+0x000000197ac5)
    #2 Configuration::setReplicationThrottleQueueCap(long const&) build/ep-engine/src/generated_configuration.cc:459 (ep.so+0x0000001a6fa8)
    #3 setTapParam(EventuallyPersistentEngine*, char const*, char const*, std::string&) ep-engine/src/ep_engine.cc:323 (ep.so+0x0000000d7f3f)
    #4 EvpUnknownCommand(engine_interface*, void const*, protocol_binary_request_header*, bool (*)(void const*, unsigned short, void const*, unsigned char, void const*, unsigned int, unsigned char, unsigned short, unsigned long, void const*)) ep-engine/src/ep_engine.cc:1365 (ep.so+0x0000000b4f68)
    #5 mock_unknown_command(engine_interface*, void const*, protocol_binary_request_header*, bool (*)(void const*, unsigned short, void const*, unsigned char, void const*, unsigned int, unsigned char, unsigned short, unsigned long, void const*)) memcached/programs/engine_testapp/engine_testapp.cc:382 (engine_testapp+0x0000004ce149)
    #6 set_param(engine_interface*, engine_interface_v1*, protocol_binary_engine_param_t, char const*, char const*) ep-engine/tests/ep_test_apis.cc:597 (ep_testsuite_dcp.so+0x000000038e17)
    #7 test_consumer_backoff_stat(engine_interface*, engine_interface_v1*) ep-engine/tests/ep_testsuite_dcp.cc:2184 (ep_testsuite_dcp.so+0x000000017411)
    #8 execute_test(test, char const*, char const*) memcached/programs/engine_testapp/engine_testapp.cc:1131 (engine_testapp+0x0000004cc600)
    #9 __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226 (libc.so.6+0x00000002176c)

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

index daa97b9..f0b84c2 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "config.h"
 
+#include <relaxed_atomic.h>
+
 #include "common.h"
 #include "stats.h"
 
@@ -48,8 +50,8 @@ private:
     bool persistenceQueueSmallEnough() const;
     bool hasSomeMemory() const;
 
-    ssize_t queueCap;
-    size_t capPercent;
+    Couchbase::RelaxedAtomic<ssize_t> queueCap;
+    Couchbase::RelaxedAtomic<size_t> capPercent;
     EPStats &stats;
 };