Skip to content

Commit da65c6d

Browse files
daverigbychiyoung
authored andcommitted
MB-19280: Fix data race in CouchKVStore stats access
As reported by ThreadSanitizer. CouchKVStore maintains a map of vBucketID to counter - dbFileRevMap. This is read by some of the stats functions (e.g. getNumPersistedDeletes) without a lock and hence there is a potential race. Solve this by changing the type of these counters to RelaxedAtomic<>. WARNING: ThreadSanitizer: data race (pid=10155) Read of size 8 at 0x7d9000008000 by main thread (mutexes: write M21730): #0 CouchKVStore::getNumPersistedDeletes(unsigned short) ep-engine/src/couch-kvstore/couch-kvstore.cc:2095 (ep.so+0x000000326779) #1 EventuallyPersistentEngine::doDcpVbTakeoverStats(void const*, void (*)(char const*, unsigned short, char const*, unsigned int, void const*), std::string&, unsigned short) ep-engine/src/ep_engine.cc:5312 (ep.so+0x000000155ca5) #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:4462 (ep.so+0x000000154622) Previous write of size 8 at 0x7d9000008000 by thread T8 (mutexes: write M15079): #0 CouchKVStore::updateDbFileMap(unsigned short, unsigned long) ep-engine/src/couch-kvstore/couch-kvstore.cc:1306 (ep.so+0x000000311d3c) #1 CouchKVStore::openDB(unsigned short, unsigned long, _db**, unsigned long, unsigned long*) ep-engine/src/couch-kvstore/couch-kvstore.cc:1336 (ep.so+0x00000030f7ae) #2 CouchKVStore::setVBucketState(unsigned short, vbucket_state&, Callback<KVStatsCtx>*) ep-engine/src/couch-kvstore/couch-kvstore.cc:981 (ep.so+0x00000031a557) #3 CouchKVStore::snapshotVBucket(unsigned short, vbucket_state&, Callback<KVStatsCtx>*) ep-engine/src/couch-kvstore/couch-kvstore.cc:891 (ep.so+0x00000031a11c) #4 EventuallyPersistentStore::snapshotVBuckets(Priority const&, unsigned short) ep-engine/src/ep.cc:949 (ep.so+0x0000000dce69) Change-Id: I83db17ffce0d0a49cfe80f23a34e5dac25ede719 Reviewed-on: http://review.couchbase.org/63081 Well-Formed: buildbot <[email protected]> Reviewed-by: Jim Walker <[email protected]> Reviewed-by: Will Gardner <[email protected]> Tested-by: buildbot <[email protected]>
1 parent 9bd4782 commit da65c6d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/couch-kvstore/couch-kvstore.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "config.h"
2222
#include "libcouchstore/couch_db.h"
23+
#include <relaxed_atomic.h>
2324

2425
#include <map>
2526
#include <string>
@@ -638,7 +639,12 @@ class CouchKVStore : public KVStore
638639
EPStats &epStats;
639640
Configuration &configuration;
640641
const std::string dbname;
641-
std::vector<uint64_t>dbFileRevMap;
642+
643+
// Map of the fileRev for each vBucket. Using RelaxedAtomic so
644+
// stats gathering (doDcpVbTakeoverStats) can get a snapshot
645+
// without having to lock.
646+
std::vector<Couchbase::RelaxedAtomic<uint64_t> > dbFileRevMap;
647+
642648
uint16_t numDbFiles;
643649
std::vector<CouchRequest *> pendingReqsQ;
644650
bool intransaction;

0 commit comments

Comments
 (0)