summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/update.cpp
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/db/ops/update.cpp
parent94880490ed1d138be2a6547726ef598511f8311a (diff)
downloadmongo-c75a777a2c438139b88e7d92eacd29e48735e7c2.tar.gz
SERVER-13951 Use a WriteUnitOfWork for each document in update and delete
Diffstat (limited to 'src/mongo/db/ops/update.cpp')
-rw-r--r--src/mongo/db/ops/update.cpp18
1 files changed, 13 insertions, 5 deletions
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? */,