diff options
author | George Wangensteen <george.wangensteen@mongodb.com> | 2020-11-18 20:38:20 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-11-20 19:10:57 +0000 |
commit | 997bfb9552e33f34bfcfb6d39e8851a412390c9f (patch) | |
tree | 098a0e60b5d13a3011c5e6a739884334100879db | |
parent | cfa95825eebad3d8d9de0a4903523fd6a41184eb (diff) | |
download | mongo-997bfb9552e33f34bfcfb6d39e8851a412390c9f.tar.gz |
SERVER-51656 Make CollectionBulkLoader::init retry on write conflicts
-rw-r--r-- | src/mongo/db/repl/collection_bulk_loader_impl.cpp | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/src/mongo/db/repl/collection_bulk_loader_impl.cpp b/src/mongo/db/repl/collection_bulk_loader_impl.cpp index 43a834a86c8..903f2d3e692 100644 --- a/src/mongo/db/repl/collection_bulk_loader_impl.cpp +++ b/src/mongo/db/repl/collection_bulk_loader_impl.cpp @@ -75,40 +75,49 @@ CollectionBulkLoaderImpl::~CollectionBulkLoaderImpl() { Status CollectionBulkLoaderImpl::init(const std::vector<BSONObj>& secondaryIndexSpecs) { return _runTaskReleaseResourcesOnFailure([&secondaryIndexSpecs, this]() -> Status { - WriteUnitOfWork wuow(_opCtx.get()); - // All writes in CollectionBulkLoaderImpl should be unreplicated. - // The opCtx is accessed indirectly through _secondaryIndexesBlock. - UnreplicatedWritesBlock uwb(_opCtx.get()); - // This enforces the buildIndexes setting in the replica set configuration. - CollectionWriter collWriter(*_collection); - auto indexCatalog = collWriter.getWritableCollection()->getIndexCatalog(); - auto specs = indexCatalog->removeExistingIndexesNoChecks(_opCtx.get(), secondaryIndexSpecs); - if (specs.size()) { - _secondaryIndexesBlock->ignoreUniqueConstraint(); - auto status = - _secondaryIndexesBlock - ->init(_opCtx.get(), collWriter, specs, MultiIndexBlock::kNoopOnInitFn) - .getStatus(); - if (!status.isOK()) { - return status; - } - } else { - _secondaryIndexesBlock.reset(); - } - if (!_idIndexSpec.isEmpty()) { - auto status = - _idIndexBlock - ->init(_opCtx.get(), collWriter, _idIndexSpec, MultiIndexBlock::kNoopOnInitFn) - .getStatus(); - if (!status.isOK()) { - return status; - } - } else { - _idIndexBlock.reset(); - } + return writeConflictRetry( + _opCtx.get(), + "CollectionBulkLoader::init", + _collection->getNss().ns(), + [&secondaryIndexSpecs, this] { + WriteUnitOfWork wuow(_opCtx.get()); + // All writes in CollectionBulkLoaderImpl should be unreplicated. + // The opCtx is accessed indirectly through _secondaryIndexesBlock. + UnreplicatedWritesBlock uwb(_opCtx.get()); + // This enforces the buildIndexes setting in the replica set configuration. + CollectionWriter collWriter(*_collection); + auto indexCatalog = collWriter.getWritableCollection()->getIndexCatalog(); + auto specs = + indexCatalog->removeExistingIndexesNoChecks(_opCtx.get(), secondaryIndexSpecs); + if (specs.size()) { + _secondaryIndexesBlock->ignoreUniqueConstraint(); + auto status = + _secondaryIndexesBlock + ->init(_opCtx.get(), collWriter, specs, MultiIndexBlock::kNoopOnInitFn) + .getStatus(); + if (!status.isOK()) { + return status; + } + } else { + _secondaryIndexesBlock.reset(); + } + if (!_idIndexSpec.isEmpty()) { + auto status = _idIndexBlock + ->init(_opCtx.get(), + collWriter, + _idIndexSpec, + MultiIndexBlock::kNoopOnInitFn) + .getStatus(); + if (!status.isOK()) { + return status; + } + } else { + _idIndexBlock.reset(); + } - wuow.commit(); - return Status::OK(); + wuow.commit(); + return Status::OK(); + }); }); } |