summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-06-03 11:23:48 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-05 18:15:46 +0000
commitbf8cb71787d18a907173dd67a8ff9950e56a4199 (patch)
tree81d4e17bb5520849c6db23735e719aa20b256709
parent242a0b8f7f27a597eec2ebfea181a39a4263ac12 (diff)
downloadmongo-bf8cb71787d18a907173dd67a8ff9950e56a4199.tar.gz
SERVER-48279 Eliminate race in WiredTigerRecordStore::OplogStones::awaitHasExcessStonesOrDead
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index e9ba3ddb047..640e085d652 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -196,6 +196,7 @@ private:
WiredTigerRecordStore::OplogStones::OplogStones(OperationContext* opCtx, WiredTigerRecordStore* rs)
: _rs(rs) {
+ stdx::lock_guard<Latch> reclaimLk(_oplogReclaimMutex);
stdx::lock_guard<Latch> lk(_mutex);
invariant(rs->isCapped());
@@ -226,10 +227,8 @@ bool WiredTigerRecordStore::OplogStones::isDead() {
}
void WiredTigerRecordStore::OplogStones::kill() {
- {
- stdx::lock_guard<Latch> lk(_oplogReclaimMutex);
- _isDead = true;
- }
+ stdx::lock_guard<Latch> lk(_oplogReclaimMutex);
+ _isDead = true;
_oplogReclaimCv.notify_one();
}
@@ -306,10 +305,16 @@ void WiredTigerRecordStore::OplogStones::popOldestStone() {
void WiredTigerRecordStore::OplogStones::createNewStoneIfNeeded(OperationContext* opCtx,
RecordId lastRecord,
Date_t wallTime) {
+ // Try to lock both mutexes, if we fail to lock a mutex then someone else is either already
+ // creating a new stone or popping the oldest one. In the latter case, we let the next insert
+ // trigger the new stone's creation.
+ stdx::unique_lock<Latch> reclaimLk(_oplogReclaimMutex, stdx::try_to_lock);
+ if (!reclaimLk) {
+ return;
+ }
+
stdx::unique_lock<Latch> lk(_mutex, stdx::try_to_lock);
if (!lk) {
- // Someone else is either already creating a new stone or popping the oldest one. In the
- // latter case, we let the next insert trigger the new stone's creation.
return;
}
@@ -597,6 +602,7 @@ void WiredTigerRecordStore::OplogStones::_pokeReclaimThreadIfNeeded() {
}
void WiredTigerRecordStore::OplogStones::adjust(int64_t maxSize) {
+ stdx::lock_guard<Latch> reclaimLk(_oplogReclaimMutex);
stdx::lock_guard<Latch> lk(_mutex);
const unsigned int oplogStoneSize =