diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index ced1bff..8151e8c 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -614,47 +614,23 @@ namespace { } } else { - // do upserts for inserts as we might get replayed more than once - OpDebug debug; - BSONElement _id; - if( !o.getObjectID(_id) ) { - /* No _id. This will be very slow. */ - Timer t; - - const NamespaceString requestNs(ns); - UpdateRequest request(requestNs); - - request.setQuery(o); - request.setUpdates(o); - request.setUpsert(); - request.setFromReplication(); - UpdateLifecycleImpl updateLifecycle(true, requestNs); - request.setLifecycle(&updateLifecycle); - - update(txn, db, request, &debug); - - if( t.millis() >= 2 ) { - RARELY OCCASIONALLY log() << "warning, repl doing slow updates (no _id field) for " << ns << endl; - } + uassert(ErrorCodes::NamespaceNotFound, str::stream() << + "Failed to apply insert due to missing collection: " << op.toString(), + collection); + + WriteUnitOfWork wuow(txn); + StatusWith status = collection->insertDocument( txn, o, true ); + + if (status.isOK()) { + wuow.commit(); } - else { - /* todo : it may be better to do an insert here, and then catch the dup key exception and do update - then. very few upserts will not be inserts... - */ - BSONObjBuilder b; - b.append(_id); - - const NamespaceString requestNs(ns); - UpdateRequest request(requestNs); - - request.setQuery(b.done()); - request.setUpdates(o); - request.setUpsert(); - request.setFromReplication(); - UpdateLifecycleImpl updateLifecycle(true, requestNs); - request.setLifecycle(&updateLifecycle); - - update(txn, db, request, &debug); + else if (!status.isOK() && status.getStatus().code() != ErrorCodes::DuplicateKey) { + log() << "skipping document duplicate key error during replicated insert: " + << o.toString(); + + } + else if (!status.isOK()) { + failedUpdate = true; } } }