diff options
author | William Schultz <william.schultz@mongodb.com> | 2019-09-25 15:19:24 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-25 15:19:24 +0000 |
commit | c41af3e315a115b04a53706837d36a729d174fc3 (patch) | |
tree | c39327e225d6bf77d6e45916a1178066b0701e4d /src/mongo/db/repl | |
parent | 6db227bc5616d6af031a797d87eaad193c8c32f0 (diff) | |
download | mongo-c41af3e315a115b04a53706837d36a729d174fc3.tar.gz |
SERVER-42484 Ensure we are inside a WriteUnitOfWork when writing index keys during initial sync collection cloning
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/collection_bulk_loader_impl.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/mongo/db/repl/collection_bulk_loader_impl.cpp b/src/mongo/db/repl/collection_bulk_loader_impl.cpp index 81bfef20622..29f82e61768 100644 --- a/src/mongo/db/repl/collection_bulk_loader_impl.cpp +++ b/src/mongo/db/repl/collection_bulk_loader_impl.cpp @@ -150,13 +150,23 @@ Status CollectionBulkLoaderImpl::_insertDocumentsForUncappedCollection( return status; } - // Inserts index entries into the external sorter. This will not update - // pre-existing indexes. - for (size_t index = 0; index < locs.size(); ++index) { - status = _addDocumentToIndexBlocks(*iter++, locs.at(index)); - if (!status.isOK()) { - return status; + // Inserts index entries into the external sorter. This will not update pre-existing + // indexes. Wrap this in a WUOW since the index entry insertion may modify the durable + // record store which can throw a write conflict exception. + status = writeConflictRetry(_opCtx.get(), "_addDocumentToIndexBlocks", _nss.ns(), [&] { + WriteUnitOfWork wunit(_opCtx.get()); + for (size_t index = 0; index < locs.size(); ++index) { + status = _addDocumentToIndexBlocks(*iter++, locs.at(index)); + if (!status.isOK()) { + return status; + } } + wunit.commit(); + return Status::OK(); + }); + + if (!status.isOK()) { + return status; } } return Status::OK(); |