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-04-21 23:05:21 -0400
commitb077e090642dbb50ea235e2b26af90399896eb04 (patch)
treefe565e5dff8c9be0808c0fc9c8cd6d8667f268f7
parentd36bda7504883775be245d829ce7ada221d182ec (diff)
downloadmongo-b077e090642dbb50ea235e2b26af90399896eb04.tar.gz
SERVER-28490 Check the state after acquiring the lock in bgsync.
-rw-r--r--src/mongo/db/repl/bgsync.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index 9d129284de0..09784b76d67 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -284,6 +284,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();
@@ -347,10 +350,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.
@@ -433,6 +437,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) {
@@ -635,6 +642,9 @@ void BackgroundSync::_runRollback(OperationContext* opCtx,
};
stdx::lock_guard<stdx::mutex> lock(_mutex);
+ if (_state != ProducerState::Running) {
+ return;
+ }
_rollback = stdx::make_unique<RollbackImpl>(executor,
&localOplog,
source,