diff options
author | Dianna Hohensee <dianna.hohensee@mongodb.com> | 2020-05-15 17:53:29 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-20 21:21:10 +0000 |
commit | eae81ac42abf876039042d3f0e08e319e7e2da49 (patch) | |
tree | 58f2860fe4b46d32c621b7ea798987a6d8e055ef /src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp | |
parent | 1845ea31140161354ff6308296bde3436d0bd5f9 (diff) | |
download | mongo-eae81ac42abf876039042d3f0e08e319e7e2da49.tar.gz |
SERVER-48144 stop acquiring waitUntilDurable's barrier mutex before taking locks to update the oplogTruncateAfterPoint
Diffstat (limited to 'src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp')
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp index 94b1fb2a5f0..c9be79bf502 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp @@ -244,8 +244,6 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, // For inMemory storage engines, the data is "as durable as it's going to get". // That is, a restart is equivalent to a complete node failure. if (isEphemeral()) { - // Update the JournalListener before we return. As far as listeners are concerned, all - // writes are as 'durable' as they are ever going to get on an inMemory storage engine. auto journalListener = [&]() -> JournalListener* { // The JournalListener may not be set immediately, so we must check under a mutex so as // not to access the variable while setting a JournalListener. A JournalListener is only @@ -254,8 +252,11 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, return _journalListener; }(); if (journalListener && useListener == UseJournalListener::kUpdate) { + // Update the JournalListener before we return. Does a write while fetching the + // timestamp if primary. As far as listeners are concerned, all writes are as 'durable' + // as they are ever going to get on an inMemory storage engine. auto token = _journalListener->getToken(opCtx); - _journalListener->onDurable(token); + journalListener->onDurable(token); } return; } @@ -283,9 +284,6 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, UniqueWiredTigerSession session = getSession(); WT_SESSION* s = session->getSession(); { - // Update a value that tracks the latest write that is safe across startup recovery (in - // the repl layer) and then report the time of that write as durable after we flush - // in-memory to disk. auto journalListener = [&]() -> JournalListener* { // The JournalListener may not be set immediately, so we must check under a mutex so // as not to access the variable while setting a JournalListener. A JournalListener @@ -295,7 +293,11 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, }(); boost::optional<JournalListener::Token> token; if (journalListener && useListener == UseJournalListener::kUpdate) { - token = _journalListener->getToken(opCtx); + // Update a persisted value with the latest write timestamp that is safe across + // startup recovery in the repl layer. Then report that timestamp as durable to the + // repl layer below after we have flushed in-memory data to disk. + // Note: only does a write if primary, otherwise just fetches the timestamp. + token = journalListener->getToken(opCtx); } auto config = syncType == Fsync::kCheckpointStableTimestamp ? "use_timestamp=true" @@ -303,13 +305,29 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, invariantWTOK(s->checkpoint(s, config)); if (token) { - _journalListener->onDurable(token.get()); + journalListener->onDurable(token.get()); } } LOGV2_DEBUG(22418, 4, "created checkpoint (forced)"); return; } + auto journalListener = [&]() -> JournalListener* { + // The JournalListener may not be set immediately, so we must check under a mutex so as not + // to access the variable while setting a JournalListener. A JournalListener is only allowed + // to be set once, so using the pointer outside of a mutex is safe. + stdx::unique_lock<Latch> lk(_journalListenerMutex); + return _journalListener; + }(); + boost::optional<JournalListener::Token> token; + if (journalListener && useListener == UseJournalListener::kUpdate) { + // Update a persisted value with the latest write timestamp that is safe across startup + // recovery in the repl layer. Then report that timestamp as durable to the repl layer below + // after we have flushed in-memory data to disk. + // Note: only does a write if primary, otherwise just fetches the timestamp. + token = journalListener->getToken(opCtx); + } + uint32_t start = _lastSyncTime.load(); // Do the remainder in a critical section that ensures only a single thread at a time // will attempt to synchronize. @@ -323,20 +341,6 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, // Nobody has synched yet, so we have to sync ourselves. - // Update a value that tracks the latest write that is safe across startup recovery (in the repl - // layer) and then report the time of that write as durable after we flush in-memory to disk. - auto journalListener = [&]() -> JournalListener* { - // The JournalListener may not be set immediately, so we must check under a mutex so as not - // to access the variable while setting a JournalListener. A JournalListener is only allowed - // to be set once, so using the pointer outside of a mutex is safe. - stdx::unique_lock<Latch> lk(_journalListenerMutex); - return _journalListener; - }(); - boost::optional<JournalListener::Token> token; - if (journalListener && useListener == UseJournalListener::kUpdate) { - token = _journalListener->getToken(opCtx); - } - // Initialize on first use. if (!_waitUntilDurableSession) { invariantWTOK( @@ -353,7 +357,7 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, } if (token) { - _journalListener->onDurable(token.get()); + journalListener->onDurable(token.get()); } } |