summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2015-03-13 06:35:51 -0400
committermatt dannenberg <matt.dannenberg@10gen.com>2015-04-09 10:57:16 -0400
commit1725d76f448323a2bbaa11ffd37fd7b10cd6a64b (patch)
treebe35489fd99d5b0040f27d86b731cfcae1e4479a /src/mongo/db/exec
parentacc7a72194990f35ff706bdcab7ec443c39fb0d5 (diff)
downloadmongo-1725d76f448323a2bbaa11ffd37fd7b10cd6a64b.tar.gz
SERVER-17573 move OpObserver calls into the datalayer as much as possible and eliminate repl bools
Diffstat (limited to 'src/mongo/db/exec')
-rw-r--r--src/mongo/db/exec/delete.cpp14
-rw-r--r--src/mongo/db/exec/update.cpp67
2 files changed, 35 insertions, 46 deletions
diff --git a/src/mongo/db/exec/delete.cpp b/src/mongo/db/exec/delete.cpp
index b6bf7b03361..d519cb2ec47 100644
--- a/src/mongo/db/exec/delete.cpp
+++ b/src/mongo/db/exec/delete.cpp
@@ -158,20 +158,6 @@ namespace mongo {
_collection->deleteDocument(_txn, rloc, deleteCappedOK, deleteNoWarn,
_params.shouldCallLogOp ? &deletedDoc : NULL);
- if (_params.shouldCallLogOp) {
- if (deletedDoc.isEmpty()) {
- log() << "Deleted object without id in collection " << _collection->ns()
- << ", not logging.";
- }
- else {
- getGlobalServiceContext()->getOpObserver()->onDelete(
- _txn,
- _collection->ns().ns(),
- deletedDoc,
- _params.fromMigrate);
- }
- }
-
wunit.commit();
}
diff --git a/src/mongo/db/exec/update.cpp b/src/mongo/db/exec/update.cpp
index d9f8e291662..835d2eb7b33 100644
--- a/src/mongo/db/exec/update.cpp
+++ b/src/mongo/db/exec/update.cpp
@@ -530,7 +530,7 @@ namespace mongo {
// Verify that no immutable fields were changed and data is valid for storage.
- if (!(request->isFromReplication() || request->isFromMigration())) {
+ if (!(!_txn->writesAreReplicated() || request->isFromMigration())) {
const std::vector<FieldRef*>* immutableFields = NULL;
if (lifecycle)
immutableFields = lifecycle->getImmutableFields();
@@ -554,14 +554,22 @@ namespace mongo {
// Don't actually do the write if this is an explain.
if (!request->isExplain()) {
invariant(_collection);
+ newObj = oldObj.value();
const RecordData oldRec(oldObj.value().objdata(), oldObj.value().objsize());
- _collection->updateDocumentWithDamages(_txn, loc,
- Snapshotted<RecordData>(oldObj.snapshotId(),
- oldRec),
- source, _damages);
+ BSONObj idQuery = driver->makeOplogEntryQuery(newObj, request->isMulti());
+ oplogUpdateEntryArgs args;
+ args.update = logObj;
+ args.criteria = idQuery;
+ args.fromMigrate = request->isFromMigration();
+ _collection->updateDocumentWithDamages(
+ _txn,
+ loc,
+ Snapshotted<RecordData>(oldObj.snapshotId(), oldRec),
+ source,
+ _damages,
+ args);
}
- newObj = oldObj.value();
_specificStats.fastmod = true;
newLoc = loc;
}
@@ -577,27 +585,25 @@ namespace mongo {
// Don't actually do the write if this is an explain.
if (!request->isExplain()) {
invariant(_collection);
+ BSONObj idQuery = driver->makeOplogEntryQuery(newObj, request->isMulti());
+ oplogUpdateEntryArgs args;
+ args.update = logObj;
+ args.criteria = idQuery;
+ args.fromMigrate = request->isFromMigration();
StatusWith<RecordId> res = _collection->updateDocument(
- _txn,
- loc, oldObj, newObj,
- true, driver->modsAffectIndices(),
- _params.opDebug);
+ _txn,
+ loc,
+ oldObj,
+ newObj,
+ true,
+ driver->modsAffectIndices(),
+ _params.opDebug,
+ args);
uassertStatusOK(res.getStatus());
newLoc = res.getValue();
}
}
- // Call logOp if requested, and we're not an explain.
- if (request->shouldCallLogOp() && !logObj.isEmpty() && !request->isExplain()) {
- BSONObj idQuery = driver->makeOplogEntryQuery(newObj, request->isMulti());
- getGlobalServiceContext()->getOpObserver()->onUpdate(
- _txn,
- request->getNamespaceString().ns().c_str(),
- logObj,
- idQuery,
- request->isFromMigration());
- }
-
invariant(oldObj.snapshotId() == _txn->recoveryUnit()->getSnapshotId());
wunit.commit();
@@ -710,7 +716,7 @@ namespace mongo {
_specificStats.inserted = true;
const UpdateRequest* request = _params.request;
- bool isInternalRequest = request->isFromReplication() || request->isFromMigration();
+ bool isInternalRequest = !_txn->writesAreReplicated() || request->isFromMigration();
// Reset the document we will be writing to.
_doc.reset();
@@ -738,15 +744,10 @@ namespace mongo {
WriteUnitOfWork wunit(_txn);
invariant(_collection);
StatusWith<RecordId> newLoc = _collection->insertDocument(_txn,
- newObj,
- !request->isGod()/*enforceQuota*/);
+ newObj,
+ !request->isGod()/*enforceQuota*/,
+ request->isFromMigration());
uassertStatusOK(newLoc.getStatus());
- if (request->shouldCallLogOp()) {
- getGlobalServiceContext()->getOpObserver()->onInsert(_txn,
- request->getNamespaceString().ns(),
- newObj,
- request->isFromMigration());
- }
// Technically, we should save/restore state here, but since we are going to return EOF
// immediately after, it would just be wasted work.
@@ -948,8 +949,10 @@ namespace mongo {
const NamespaceString& nsString(request.getNamespaceString());
// We may have stepped down during the yield.
- if (request.shouldCallLogOp() &&
- !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(nsString.db())) {
+ bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
+ !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(nsString.db());
+
+ if (userInitiatedWritesAndNotPrimary) {
return Status(ErrorCodes::NotMaster,
str::stream() << "Demoted from primary while performing update on "
<< nsString.ns());