summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/bgsync.cpp
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2017-03-21 21:05:45 -0400
committerBenety Goh <benety@mongodb.com>2017-04-04 15:32:14 -0400
commit9818bae9a907ef224972470e461a590422149df8 (patch)
tree8ffe06c1241f0ab9fc1ada4486ed414a8d761e4b /src/mongo/db/repl/bgsync.cpp
parent672583baac51af7c9e3e92c658d1880fd2b035b6 (diff)
downloadmongo-9818bae9a907ef224972470e461a590422149df8.tar.gz
SERVER-28181 Fix the deadlock in OplogFetcher's constructor.
(cherry picked from commit 7361e94af31142ec018ccad70b0398e3a472eba5)
Diffstat (limited to 'src/mongo/db/repl/bgsync.cpp')
-rw-r--r--src/mongo/db/repl/bgsync.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index d50d66b6af1..8683fffe24c 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -367,20 +367,18 @@ void BackgroundSync::_produce(OperationContext* opCtx) {
auto rbidCopyForFetcher = syncSourceResp.rbid; // OplogFetcher's callback modifies this.
OplogFetcher* oplogFetcher;
try {
- auto executor = _replicationCoordinatorExternalState->getTaskExecutor();
- auto config = _replCoord->getConfig();
auto onOplogFetcherShutdownCallbackFn =
[&fetcherReturnStatus](const Status& status, const OpTimeWithHash& lastFetched) {
fetcherReturnStatus = status;
};
-
- stdx::lock_guard<stdx::mutex> lock(_mutex);
- _oplogFetcher = stdx::make_unique<OplogFetcher>(
- executor,
+ // The construction of OplogFetcher has to be outside bgsync mutex, because it calls
+ // replication coordinator.
+ auto oplogFetcherPtr = stdx::make_unique<OplogFetcher>(
+ _replicationCoordinatorExternalState->getTaskExecutor(),
OpTimeWithHash(lastHashFetched, lastOpTimeFetched),
source,
NamespaceString(rsOplogName),
- config,
+ _replCoord->getConfig(),
_replicationCoordinatorExternalState->getOplogFetcherMaxFetcherRestarts(),
&dataReplicatorExternalState,
stdx::bind(&BackgroundSync::_enqueueDocuments,
@@ -390,6 +388,8 @@ void BackgroundSync::_produce(OperationContext* opCtx) {
stdx::placeholders::_3,
&rbidCopyForFetcher),
onOplogFetcherShutdownCallbackFn);
+ stdx::lock_guard<stdx::mutex> lock(_mutex);
+ _oplogFetcher = std::move(oplogFetcherPtr);
oplogFetcher = _oplogFetcher.get();
} catch (const mongo::DBException& ex) {
fassertFailedWithStatus(34440, exceptionToStatus());