MB-19732: Fix the data race on lastSendTime between stats and dcp worker threads 03/64803/3
authorManu Dhundi <manu@couchbase.com>
Wed, 8 Jun 2016 17:38:21 +0000 (10:38 -0700)
committerDave Rigby <daver@couchbase.com>
Thu, 9 Jun 2016 16:19:58 +0000 (16:19 +0000)
Fix the thread sanitizer warning
http://cv.jenkins.couchbase.com/job/ep-engine-threadsanitizer-3.0.x/258/console

Change-Id: I2a2b0b0f01b10ecb31701bfc2330881bbafc6b74
Reviewed-on: http://review.couchbase.org/64803
Well-Formed: buildbot <build@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
src/dcp-producer.cc
src/dcp-producer.h

index a19a4d5..19194ae 100644 (file)
@@ -392,7 +392,7 @@ ENGINE_ERROR_CODE DcpProducer::step(struct dcp_message_producers* producers) {
         delete resp;
     }
 
-    lastSendTime = ep_current_time();
+    lastSendTime.store(ep_current_time(), memory_order_relaxed);
     return (ret == ENGINE_SUCCESS) ? ENGINE_WANT_MORE : ret;
 }
 
@@ -537,7 +537,8 @@ void DcpProducer::addStats(ADD_STAT add_stat, const void *c) {
     addStat("items_sent", getItemsSent(), add_stat, c);
     addStat("items_remaining", getItemsRemaining(), add_stat, c);
     addStat("total_bytes_sent", getTotalBytes(), add_stat, c);
-    addStat("last_sent_time", lastSendTime, add_stat, c);
+    addStat("last_sent_time", lastSendTime.load(memory_order_relaxed), add_stat,
+            c);
     addStat("noop_enabled", noopCtx.enabled, add_stat, c);
     addStat("noop_wait", noopCtx.pendingRecv, add_stat, c);
 
@@ -720,7 +721,7 @@ ENGINE_ERROR_CODE DcpProducer::maybeSendNoop(struct dcp_message_producers* produ
                 ret = ENGINE_WANT_MORE;
                 noopCtx.pendingRecv = true;
                 noopCtx.sendTime = ep_current_time();
-                lastSendTime = ep_current_time();
+                lastSendTime.store(ep_current_time(), memory_order_relaxed);
             }
             return ret;
         }
index ce3d9e6..b88c5cc 100644 (file)
@@ -292,7 +292,7 @@ private:
     DcpResponse *rejectResp; // stash response for retry if E2BIG was hit
 
     bool notifyOnly;
-    rel_time_t lastSendTime;
+    AtomicValue<rel_time_t> lastSendTime;
     BufferLog log;
 
     // Guards all accesses to streams map. If only reading elements in streams