summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2017-04-18 14:48:42 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2017-05-02 20:11:03 -0400
commitf55883b2c7e530a669e9c93ae3a41654ab4dae4f (patch)
tree5c58753228cb5248687b226a571a1b77a9fd6f6c
parent40281df08e24e6992ec8322fb5854481de61c344 (diff)
downloadmongo-f55883b2c7e530a669e9c93ae3a41654ab4dae4f.tar.gz
SERVER-28490 Check the state after acquiring the lock in bgsync.
(cherry picked from commit b077e090642dbb50ea235e2b26af90399896eb04)
-rw-r--r--src/mongo/db/repl/bgsync.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index 41781d2fcc9..9223b73e4e9 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -276,6 +276,9 @@ void BackgroundSync::_produce(OperationContext* opCtx) {
const OpTime minValidSaved = storageInterface->getMinValid(opCtx);
stdx::lock_guard<stdx::mutex> lock(_mutex);
+ if (_state != ProducerState::Running) {
+ return;
+ }
const auto requiredOpTime = (minValidSaved > _lastOpTimeFetched) ? minValidSaved : OpTime();
lastOpTimeFetched = _lastOpTimeFetched;
_syncSourceHost = HostAndPort();
@@ -340,10 +343,11 @@ void BackgroundSync::_produce(OperationContext* opCtx) {
}
return;
} else if (syncSourceResp.isOK() && !syncSourceResp.getSyncSource().empty()) {
- stdx::lock_guard<stdx::mutex> lock(_mutex);
- _syncSourceHost = syncSourceResp.getSyncSource();
- source = _syncSourceHost;
-
+ {
+ stdx::lock_guard<stdx::mutex> lock(_mutex);
+ _syncSourceHost = syncSourceResp.getSyncSource();
+ source = _syncSourceHost;
+ }
// If our sync source has not changed, it is likely caused by our heartbeat data map being
// out of date. In that case we sleep for 1 second to reduce the amount we spin waiting
// for our map to update.
@@ -427,6 +431,9 @@ void BackgroundSync::_produce(OperationContext* opCtx) {
stdx::placeholders::_3),
onOplogFetcherShutdownCallbackFn);
stdx::lock_guard<stdx::mutex> lock(_mutex);
+ if (_state != ProducerState::Running) {
+ return;
+ }
_oplogFetcher = std::move(oplogFetcherPtr);
oplogFetcher = _oplogFetcher.get();
} catch (const mongo::DBException& ex) {