diff options
author | William Schultz <william.schultz@mongodb.com> | 2017-08-28 16:51:47 -0400 |
---|---|---|
committer | William Schultz <william.schultz@mongodb.com> | 2017-08-28 16:52:09 -0400 |
commit | 2203abc793e888e1c7b281b8bf213e0fd0446795 (patch) | |
tree | dde616f24e04f29eaa70d2d32816e4fa389c611d /src/mongo/db/repl/collection_cloner.cpp | |
parent | 52dedd3e6c99ca13182e77866fccf7a2c525d851 (diff) | |
download | mongo-2203abc793e888e1c7b281b8bf213e0fd0446795.tar.gz |
SERVER-30849 _handleARMResultsCallback needs to hold mutex while accessing member variables
Diffstat (limited to 'src/mongo/db/repl/collection_cloner.cpp')
-rw-r--r-- | src/mongo/db/repl/collection_cloner.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp index 98d658b49f9..ad2987e7603 100644 --- a/src/mongo/db/repl/collection_cloner.cpp +++ b/src/mongo/db/repl/collection_cloner.cpp @@ -612,7 +612,7 @@ StatusWith<std::vector<BSONElement>> CollectionCloner::_parseParallelCollectionS } } -Status CollectionCloner::_bufferNextBatchFromArm() { +Status CollectionCloner::_bufferNextBatchFromArm(WithLock lock) { while (_arm->ready()) { auto armResultStatus = _arm->nextReady(); if (!armResultStatus.getStatus().isOK()) { @@ -671,13 +671,20 @@ void CollectionCloner::_handleARMResultsCallback( } // Pull the documents from the ARM into a buffer until the entire batch has been processed. - auto nextBatchStatus = _bufferNextBatchFromArm(); - if (!nextBatchStatus.isOK()) { - setResultAndCancelRemainingWork(onCompletionGuard, nextBatchStatus); - return; + bool lastBatch; + { + UniqueLock lk(_mutex); + auto nextBatchStatus = _bufferNextBatchFromArm(lk); + if (!nextBatchStatus.isOK()) { + onCompletionGuard->setResultAndCancelRemainingWork_inlock(lk, nextBatchStatus); + return; + } + + // Check if this is the last batch of documents to clone. + lastBatch = _arm->remotesExhausted(); } - bool lastBatch = _arm->remotesExhausted(); + // Schedule the next document batch insertion. auto&& scheduleResult = _scheduleDbWorkFn(stdx::bind(&CollectionCloner::_insertDocumentsCallback, this, |