diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp index 8b8c130cba0e3..34a7bed9acfc7 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp @@ -53,7 +53,7 @@ void WiredTigerOplogManager::start(OperationContext* opCtx, invariant(!_isRunning); // Prime the oplog read timestamp. auto sessionCache = WiredTigerRecoveryUnit::get(opCtx)->getSessionCache(); - _setOplogReadTimestamp(_fetchAllCommittedValue(sessionCache->conn())); + setOplogReadTimestamp(Timestamp(_fetchAllCommittedValue(sessionCache->conn()))); std::unique_ptr reverseOplogCursor = oplogRecordStore->getCursor(opCtx, false /* false = reverse cursor */); @@ -187,10 +187,8 @@ void WiredTigerOplogManager::_oplogJournalThreadLoop(WiredTigerSessionCache* ses sessionCache->waitUntilDurable(/*forceCheckpoint=*/false, false); lk.lock(); - // Publish the new timestamp value. - _setOplogReadTimestamp(newTimestamp); - _opsBecameVisibleCV.notify_all(); + _setOplogReadTimestamp(lk, newTimestamp); lk.unlock(); // Wake up any await_data cursors and tell them more data might be visible now. @@ -209,11 +207,13 @@ std::uint64_t WiredTigerOplogManager::getOplogReadTimestamp() const { } void WiredTigerOplogManager::setOplogReadTimestamp(Timestamp ts) { - _oplogReadTimestamp.store(ts.asULL()); + stdx::lock_guard lk(_oplogVisibilityStateMutex); + _setOplogReadTimestamp(lk, ts.asULL()); } -void WiredTigerOplogManager::_setOplogReadTimestamp(uint64_t newTimestamp) { +void WiredTigerOplogManager::_setOplogReadTimestamp(WithLock, uint64_t newTimestamp) { _oplogReadTimestamp.store(newTimestamp); + _opsBecameVisibleCV.notify_all(); LOG(2) << "setting new oplogReadTimestamp: " << newTimestamp; } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h index f62bec8a66b5a..ac744f0d50228 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h @@ -35,6 +35,7 @@ #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/mutex.h" #include "mongo/stdx/thread.h" +#include "mongo/util/concurrency/with_lock.h" namespace mongo { @@ -83,7 +84,7 @@ class WiredTigerOplogManager { WiredTigerRecordStore* oplogRecordStore, bool isMasterSlave) noexcept; - void _setOplogReadTimestamp(uint64_t newTimestamp); + void _setOplogReadTimestamp(WithLock, uint64_t newTimestamp); uint64_t _fetchAllCommittedValue(WT_CONNECTION* conn);