Skip to content

Commit b194f2a

Browse files
committed
MB-19641: Fix data race on ItemPager::phase
ItemPager::phase is accessed by multiple threads (when different vbuckets are being processed by different executors), so it needs to be atomic. As reported by ThreadSanitizer: WARNING: ThreadSanitizer: data race (pid=180366) Read of size 4 at 0x7d1c0000d650 by thread T18 (mutexes: write M18437): #0 PagingVisitor::visit(StoredValue*) ep-engine/src/item_pager.cc:86 (ep.so+0x000000107734) #1 HashTable::visit(HashTableVisitor&) ep-engine/src/stored-value.cc:475 (ep.so+0x00000011d1b8) #2 VBCBAdaptor::run() ep-engine/src/ep.cc:3929 (ep.so+0x0000000a3c2f) #3 ExecutorThread::run() ep-engine/src/executorthread.cc:115 (ep.so+0x0000000fb086) Previous write of size 4 at 0x7d1c0000d650 by thread T17: #0 PagingVisitor::complete() ep-engine/src/item_pager.cc:179 (ep.so+0x000000108004) #1 VBCBAdaptor::run() ep-engine/src/ep.cc:3937 (ep.so+0x0000000a3d7e) #2 ExecutorThread::run() ep-engine/src/executorthread.cc:115 (ep.so+0x0000000fb086) Change-Id: I9652a9f7f36f18967b6ec5903db53f3c7fb917fe Reviewed-on: http://review.couchbase.org/64161 Tested-by: buildbot <[email protected]> Well-Formed: buildbot <[email protected]> Reviewed-by: Will Gardner <[email protected]>
1 parent 85c0728 commit b194f2a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/item_pager.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class PagingVisitor : public VBucketVisitor {
5858
*/
5959
PagingVisitor(EventuallyPersistentStore &s, EPStats &st, double pcnt,
6060
std::shared_ptr<AtomicValue<bool>> &sfin, pager_type_t caller,
61-
bool pause = false, double bias = 1,
62-
item_pager_phase *phase = NULL) :
61+
bool pause, double bias,
62+
std::atomic<item_pager_phase>* phase) :
6363
store(s), stats(st), percent(pcnt),
6464
activeBias(bias), ejected(0),
6565
startTime(ep_real_time()), stateFinalizer(sfin), owner(caller),
@@ -239,7 +239,7 @@ class PagingVisitor : public VBucketVisitor {
239239
bool completePhase;
240240
bool wasHighMemoryUsage;
241241
hrtime_t taskStart;
242-
item_pager_phase *pager_phase;
242+
std::atomic<item_pager_phase>* pager_phase;
243243
};
244244

245245
ItemPager::ItemPager(EventuallyPersistentEngine *e, EPStats &st) :

src/item_pager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ class ItemPager : public GlobalTask {
7575
EventuallyPersistentEngine *engine;
7676
EPStats &stats;
7777
std::shared_ptr<AtomicValue<bool>> available;
78-
item_pager_phase phase;
78+
79+
// Current pager phase. Atomic as may be accessed by multiple PagingVisitor
80+
// objects running on different threads.
81+
std::atomic<item_pager_phase> phase;
7982
bool doEvict;
8083
};
8184

0 commit comments

Comments
 (0)