summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2017-08-28 16:51:47 -0400
committerWilliam Schultz <william.schultz@mongodb.com>2017-08-28 16:52:09 -0400
commit2203abc793e888e1c7b281b8bf213e0fd0446795 (patch)
treedde616f24e04f29eaa70d2d32816e4fa389c611d /src/mongo/db
parent52dedd3e6c99ca13182e77866fccf7a2c525d851 (diff)
downloadmongo-2203abc793e888e1c7b281b8bf213e0fd0446795.tar.gz
SERVER-30849 _handleARMResultsCallback needs to hold mutex while accessing member variables
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/repl/collection_cloner.cpp19
-rw-r--r--src/mongo/db/repl/collection_cloner.h2
2 files changed, 14 insertions, 7 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,
diff --git a/src/mongo/db/repl/collection_cloner.h b/src/mongo/db/repl/collection_cloner.h
index 222886b9d72..1f8701c3ca5 100644
--- a/src/mongo/db/repl/collection_cloner.h
+++ b/src/mongo/db/repl/collection_cloner.h
@@ -237,7 +237,7 @@ private:
/**
* Pull all ready results from the ARM into a buffer to be inserted.
*/
- Status _bufferNextBatchFromArm();
+ Status _bufferNextBatchFromArm(WithLock lock);
/**
* Called whenever there is a new batch of documents ready from the 'AsyncResultsMerger'.