diff options
author | Dianna Hohensee <dianna.hohensee@10gen.com> | 2016-02-16 10:13:49 -0500 |
---|---|---|
committer | Dianna Hohensee <dianna.hohensee@10gen.com> | 2016-02-18 17:13:59 -0500 |
commit | ee31993039163d1b0a055f90a8f76093e694d7dd (patch) | |
tree | b2e30af77f7c421cbda3b03e631d5fd9b0aca5f0 /src/mongo/db/instance.cpp | |
parent | 16fdea66101dce875cc370314f00bc34dd407bf6 (diff) | |
download | mongo-ee31993039163d1b0a055f90a8f76093e694d7dd.tar.gz |
SERVER-22239 DuplicateKey Error, update optime to latest after insert failure
Diffstat (limited to 'src/mongo/db/instance.cpp')
-rw-r--r-- | src/mongo/db/instance.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index ddd12888c95..da33e909fee 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -1023,6 +1023,12 @@ NOINLINE_DECL void insertMulti(OperationContext* txn, int64_t chunkCount = 0; int64_t chunkSize = 0; + auto client = txn->getClient(); + auto lastOpAtOperationStart = repl::ReplClientInfo::forClient(client).getLastOp(); + ScopeGuard lastOpSetterGuard = MakeObjGuard(repl::ReplClientInfo::forClient(client), + &repl::ReplClientInfo::setLastOpToSystemLastOpTime, + txn); + for (vector<BSONObj>::iterator it = docs.begin(); it != docs.end(); it++) { StatusWith<BSONObj> fixed = fixDocumentForInsert(*it); uassertStatusOK(fixed.getStatus()); @@ -1047,6 +1053,13 @@ NOINLINE_DECL void insertMulti(OperationContext* txn, } if (chunkBegin != docs.end()) insertMultiVector(txn, ctx, keepGoing, ns, op, chunkBegin, docs.end()); + + if (repl::ReplClientInfo::forClient(client).getLastOp() != lastOpAtOperationStart) { + // If this operation has already generated a new lastOp, don't bother setting it + // here. No-op inserts will not generate a new lastOp, so we still need the + // guard to fire in that case. + lastOpSetterGuard.Dismiss(); + } } static void convertSystemIndexInsertsToCommands(DbMessage& d, BSONArrayBuilder* allCmdsBuilder) { |