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-12 01:25:41 +0000
commit6f7d770b36a493a724cde0a2d2a7efae62b30963 (patch)
tree5406f651beacc23137a68bc19c8de5fea14174cd
parent3d37a082d3799f4b25738c7972c48febcb1d1406 (diff)
downloadmongo-6f7d770b36a493a724cde0a2d2a7efae62b30963.tar.gz
SERVER-48279 Eliminate race in WiredTigerRecordStore::OplogStones::awaitHasExcessStonesOrDead
(cherry picked from commit bf8cb71787d18a907173dd67a8ff9950e56a4199)
-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 33b67692e06..8f9fd454830 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 =