Skip to content

Commit 7b11a7f

Browse files
manudhundidaverigby
authored andcommitted
MB-19897: Fix the data race on lastSendTime between stats and dcp worker threads
Fix the thread sanitizer warning http://cv.jenkins.couchbase.com/job/ep-engine-threadsanitizer-3.0.x/258/console WARNING: ThreadSanitizer: data race (pid=102290) Read of size 4 at 0x7d580000f71c by thread T14 (mutexes: write M969): #0 void ConnHandler::addStat<unsigned int>(char const*, unsigned int const&, void (*)(char const*, unsigned short, char const*, unsigned int, void const*), void const*) const /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/tapconnection.h:294 (ep.so+0x00000020e9f3) #1 DcpProducer::addStats(void (*)(char const*, unsigned short, char const*, unsigned int, void const*), void const*) /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/dcp-producer.cc:557 (ep.so+0x00000027fbe5) #2 ConnStatBuilder::operator()(SingleThreadedRCPtr<ConnHandler>&) /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/ep_engine.cc:3701 (ep.so+0x000000183c44) #3 ConnStatBuilder std::for_each<std::_List_iterator<SingleThreadedRCPtr<ConnHandler> >, ConnStatBuilder>(std::_List_iterator<SingleThreadedRCPtr<ConnHandler> >, std::_List_iterator<SingleThreadedRCPtr<ConnHandler> >, ConnStatBuilder) /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_algo.h:3755 (ep.so+0x0000001838a5) #4 void ConnMap::each_UNLOCKED<ConnStatBuilder>(ConnStatBuilder) /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/connmap.h:148 (ep.so+0x000000183808) #5 void ConnMap::each<ConnStatBuilder>(ConnStatBuilder) /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/connmap.h:140 (ep.so+0x00000017732e) #6 EventuallyPersistentEngine::doDcpStats(void const*, void (*)(char const*, unsigned short, char const*, unsigned int, void const*)) /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/ep_engine.cc:3954 (ep.so+0x00000014c5ed) Previous write of size 4 at 0x7d580000f71c by main thread: #0 DcpProducer::maybeSendNoop(dcp_message_producers*) /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/dcp-producer.cc:740 (ep.so+0x00000027d8ce) #1 DcpProducer::step(dcp_message_producers*) /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/dcp-producer.cc:323 (ep.so+0x00000027c920) #2 EvpDcpStep(engine_interface*, void const*, dcp_message_producers*) /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-3.0.x/ep-engine/src/ep_engine.cc:1404 (ep.so+0x000000138baa) Change-Id: I2a2b0b0f01b10ecb31701bfc2330881bbafc6b74 Reviewed-on: http://review.couchbase.org/64959 Well-Formed: buildbot <[email protected]> Tested-by: buildbot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 7d3c7f7 commit 7b11a7f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/dcp-producer.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ ENGINE_ERROR_CODE DcpProducer::step(struct dcp_message_producers* producers) {
442442
delete resp;
443443
}
444444

445-
lastSendTime = ep_current_time();
445+
lastSendTime.store(ep_current_time(), std::memory_order_relaxed);
446446
return (ret == ENGINE_SUCCESS) ? ENGINE_WANT_MORE : ret;
447447
}
448448

@@ -608,7 +608,8 @@ void DcpProducer::addStats(ADD_STAT add_stat, const void *c) {
608608
addStat("items_sent", getItemsSent(), add_stat, c);
609609
addStat("items_remaining", getItemsRemaining(), add_stat, c);
610610
addStat("total_bytes_sent", getTotalBytes(), add_stat, c);
611-
addStat("last_sent_time", lastSendTime, add_stat, c);
611+
addStat("last_sent_time", lastSendTime.load(std::memory_order_relaxed),
612+
add_stat, c);
612613
addStat("noop_enabled", noopCtx.enabled, add_stat, c);
613614
addStat("noop_wait", noopCtx.pendingRecv, add_stat, c);
614615
addStat("priority", priority.c_str(), add_stat, c);
@@ -798,7 +799,8 @@ ENGINE_ERROR_CODE DcpProducer::maybeSendNoop(struct dcp_message_producers* produ
798799
ret = ENGINE_WANT_MORE;
799800
noopCtx.pendingRecv = true;
800801
noopCtx.sendTime = ep_current_time();
801-
lastSendTime = ep_current_time();
802+
lastSendTime.store(ep_current_time(),
803+
std::memory_order_relaxed);
802804
}
803805
return ret;
804806
}

src/dcp-producer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class DcpProducer : public Producer {
307307

308308
bool notifyOnly;
309309
bool enableExtMetaData;
310-
rel_time_t lastSendTime;
310+
AtomicValue<rel_time_t> lastSendTime;
311311
BufferLog log;
312312

313313
BackfillManager* backfillMgr;

0 commit comments

Comments
 (0)