summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2014-07-14 17:52:21 -0400
committerMathias Stearn <mathias@10gen.com>2014-07-28 11:59:21 -0400
commitc75a777a2c438139b88e7d92eacd29e48735e7c2 (patch)
treeaf851483ba7e6cb9a390a28e3bbacfc4dac907e0 /src/mongo
parent94880490ed1d138be2a6547726ef598511f8311a (diff)
downloadmongo-c75a777a2c438139b88e7d92eacd29e48735e7c2.tar.gz
SERVER-13951 Use a WriteUnitOfWork for each document in update and delete
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp10
-rw-r--r--src/mongo/db/instance.cpp4
-rw-r--r--src/mongo/db/ops/delete_executor.cpp4
-rw-r--r--src/mongo/db/ops/update.cpp18
4 files changed, 19 insertions, 17 deletions
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index 419c01be9c6..759a5bed992 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -857,9 +857,7 @@ namespace mongo {
WriteOpResult result;
- WriteUnitOfWork wunit(_txn->recoveryUnit());
multiUpdate( _txn, updateItem, &result );
- wunit.commit();
if ( !result.getStats().upsertedID.isEmpty() ) {
*upsertedId = result.getStats().upsertedID;
@@ -1108,7 +1106,6 @@ namespace mongo {
Lock::DBWrite writeLock(txn->lockState(), nsString.ns(), useExperimentalDocLocking);
///////////////////////////////////////////
- WriteUnitOfWork wunit(txn->recoveryUnit());
if (!checkShardVersion(txn, &shardingState, *updateItem.getRequest(), result))
return;
@@ -1135,7 +1132,6 @@ namespace mongo {
}
result->setError(toWriteError(status));
}
- wunit.commit();
}
/**
@@ -1164,7 +1160,6 @@ namespace mongo {
///////////////////////////////////////////
Lock::DBWrite writeLock(txn->lockState(), nss.ns());
///////////////////////////////////////////
- WriteUnitOfWork wunit(txn->recoveryUnit());
// Check version once we're locked
@@ -1175,10 +1170,10 @@ namespace mongo {
// Context once we're locked, to set more details in currentOp()
// TODO: better constructor?
- Client::Context writeContext(txn, nss.ns(), false /* don't check version */);
+ Client::Context ctx(txn, nss.ns(), false /* don't check version */);
try {
- result->getStats().n = executor.execute(writeContext.db());
+ result->getStats().n = executor.execute(ctx.db());
}
catch ( const DBException& ex ) {
status = ex.toStatus();
@@ -1187,7 +1182,6 @@ namespace mongo {
}
result->setError(toWriteError(status));
}
- wunit.commit();
}
} // namespace mongo
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index ad2f9fd8a19..709b4920d57 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -600,7 +600,6 @@ namespace mongo {
uassertStatusOK(executor.prepare());
Lock::DBWrite lk(txn->lockState(), ns.ns(), useExperimentalDocLocking);
- WriteUnitOfWork wunit(txn->recoveryUnit());
// if this ever moves to outside of lock, need to adjust check
// Client::Context::_finishInit
@@ -613,7 +612,6 @@ namespace mongo {
// for getlasterror
lastError.getSafe()->recordUpdate( res.existing , res.numMatched , res.upserted );
- wunit.commit();
}
void receivedDelete(OperationContext* txn, Message& m, CurOp& op) {
@@ -642,7 +640,6 @@ namespace mongo {
DeleteExecutor executor(&request);
uassertStatusOK(executor.prepare());
Lock::DBWrite lk(txn->lockState(), ns.ns());
- WriteUnitOfWork wunit(txn->recoveryUnit());
// if this ever moves to outside of lock, need to adjust check Client::Context::_finishInit
if ( ! broadcast && handlePossibleShardedMessage( m , 0 ) )
@@ -653,7 +650,6 @@ namespace mongo {
long long n = executor.execute(ctx.db());
lastError.getSafe()->recordDelete( n );
op.debug().ndeleted = n;
- wunit.commit();
}
QueryResult* emptyMoreResult(long long);
diff --git a/src/mongo/db/ops/delete_executor.cpp b/src/mongo/db/ops/delete_executor.cpp
index 3fdbf6c77f9..42459e77f05 100644
--- a/src/mongo/db/ops/delete_executor.cpp
+++ b/src/mongo/db/ops/delete_executor.cpp
@@ -152,6 +152,8 @@ namespace mongo {
}
BSONObj toDelete;
+ WriteUnitOfWork wunit(_request->getOpCtx()->recoveryUnit());
+
// TODO: do we want to buffer docs and delete them in a group rather than
// saving/restoring state repeatedly?
exec->saveState();
@@ -173,6 +175,8 @@ namespace mongo {
}
}
+ wunit.commit();
+
if (!_request->isMulti()) {
break;
}
diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp
index e0269ecd146..6280be64f22 100644
--- a/src/mongo/db/ops/update.cpp
+++ b/src/mongo/db/ops/update.cpp
@@ -622,6 +622,8 @@ namespace mongo {
}
}
+ WriteUnitOfWork wunit(request.getOpCtx()->recoveryUnit());
+
// Save state before making changes
exec->saveState();
@@ -679,6 +681,8 @@ namespace mongo {
NULL, request.isFromMigration());
}
+ wunit.commit();
+
// Only record doc modifications if they wrote (exclude no-ops)
if (docWasModified)
opDebug->nModified++;
@@ -774,6 +778,13 @@ namespace mongo {
driver->modOptions()) );
}
+ // Insert the doc
+ BSONObj newObj = doc.getObject();
+ uassert(17420,
+ str::stream() << "Document to upsert is larger than " << BSONObjMaxUserSize,
+ newObj.objsize() <= BSONObjMaxUserSize);
+
+ WriteUnitOfWork wunit(request.getOpCtx()->recoveryUnit());
// Only create the collection if the doc will be inserted.
if (!collection) {
collection = db->getCollection(request.getOpCtx(), request.getNamespaceString().ns());
@@ -782,11 +793,6 @@ namespace mongo {
}
}
- // Insert the doc
- BSONObj newObj = doc.getObject();
- uassert(17420,
- str::stream() << "Document to upsert is larger than " << BSONObjMaxUserSize,
- newObj.objsize() <= BSONObjMaxUserSize);
StatusWith<DiskLoc> newLoc = collection->insertDocument(request.getOpCtx(),
newObj,
@@ -802,6 +808,8 @@ namespace mongo {
request.isFromMigration());
}
+ wunit.commit();
+
opDebug->nMatched = 1;
return UpdateResult(false /* updated a non existing document */,
!driver->isDocReplacement() /* $mod or obj replacement? */,