diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2019-10-04 19:51:52 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-04 19:51:52 +0000 |
commit | 658b49389bd5bdf1112b81707e683cf6d8203a6e (patch) | |
tree | 2cf0f26c732285c65135d6ca16a454c8a222a192 | |
parent | a808ebb60041c5eb2a0c49a91f3db4689b5d3288 (diff) | |
download | mongo-658b49389bd5bdf1112b81707e683cf6d8203a6e.tar.gz |
SERVER-43701 Fix race condition between endBackup and cleanShutdown
3 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index e6daab5e98c..ae7e620290c 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -1059,6 +1059,10 @@ Status WiredTigerKVEngine::beginBackup(OperationContext* opCtx) { } void WiredTigerKVEngine::endBackup(OperationContext* opCtx) { + if (_sessionCache->isShuttingDown()) { + // There could be a race with clean shutdown which unconditionally closes all the sessions. + _backupSession->_session = nullptr; // Prevent calling _session->close() in destructor. + } _backupSession.reset(); } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp index 8b56cf66ec9..cf04a16d550 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp @@ -235,6 +235,10 @@ void WiredTigerSessionCache::shuttingDown() { closeAll(); } +bool WiredTigerSessionCache::isShuttingDown() { + return _shuttingDown.load() & kShuttingDownMask; +} + void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx, bool forceCheckpoint, bool stableCheckpoint) { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h index 3cd9b974010..e2d0ce3b2e0 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h @@ -175,6 +175,7 @@ public: private: friend class WiredTigerSessionCache; + friend class WiredTigerKVEngine; // The cursor cache is a list of pairs that contain an ID and cursor typedef std::list<WiredTigerCachedCursor> CursorCache; @@ -264,6 +265,11 @@ public: */ void shuttingDown(); + /** + * True when in the process of shutting down. + */ + bool isShuttingDown(); + bool isEphemeral(); /** |