diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2021-06-10 18:39:10 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-11 16:03:45 +0000 |
commit | d984013330025d5b65dfdeabf8c72b0cba997204 (patch) | |
tree | 990b04d4ec11a4396929a5cf1d489fb30e307158 | |
parent | 7dbe1790e854157fae9e612e7a925f9083efbbfc (diff) | |
download | mongo-d984013330025d5b65dfdeabf8c72b0cba997204.tar.gz |
SERVER-57610 IndexAccessMethod::commitBulk() retries inserting index keys on WriteConflictException
-rw-r--r-- | src/mongo/db/index/index_access_method.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index 10df321f252..2bc543f4d64 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -764,9 +764,17 @@ Status AbstractIndexAccessMethod::commitBulk(OperationContext* opCtx, continue; } - WriteUnitOfWork wunit(opCtx); - Status status = builder->addKey(data.first); - wunit.commit(); + Status status = writeConflictRetry( + opCtx, "addingKey", _indexCatalogEntry->getNSSFromCatalog(opCtx).ns(), [&] { + WriteUnitOfWork wunit(opCtx); + Status status = builder->addKey(data.first); + if (!status.isOK()) { + return status; + } + + wunit.commit(); + return Status::OK(); + }); if (!status.isOK()) { // Duplicates are checked before inserting. |