Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
SERVER-18213: Retry insert in case of a write conflict during multi-u…
Browse files Browse the repository at this point in the history
…psert
  • Loading branch information
GeertBosch committed Jun 2, 2015
1 parent 2c1e081 commit 054c874
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/mongo/db/exec/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,18 +730,19 @@ namespace mongo {
if (request->isExplain()) {
return;
}

WriteUnitOfWork wunit(_txn);
invariant(_collection);
StatusWith<RecordId> newLoc = _collection->insertDocument(_txn,
newObj,
!request->isGod()/*enforceQuota*/,
request->isFromMigration());
uassertStatusOK(newLoc.getStatus());

// Technically, we should save/restore state here, but since we are going to return
// immediately after, it would just be wasted work.
wunit.commit();
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
WriteUnitOfWork wunit(_txn);
invariant(_collection);
const bool enforceQuota = !request->isGod();
uassertStatusOK(_collection->insertDocument(_txn,
newObj,
enforceQuota,
request->isFromMigration()));

// Technically, we should save/restore state here, but since we are going to return
// immediately after, it would just be wasted work.
wunit.commit();
} MONGO_WRITE_CONFLICT_RETRY_LOOP_END(_txn, "upsert", _collection->ns().ns());
}

bool UpdateStage::doneUpdating() {
Expand Down

0 comments on commit 054c874

Please sign in to comment.