summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2017-07-27 10:32:09 -0400
committerRandolph Tan <randolph@10gen.com>2017-08-17 16:58:40 -0400
commit1e11cda15ddae9972f9993a7d6b6cbf9d172bcb3 (patch)
tree07546cb1464f52398f92db85e8af063d9f3112e0 /src/mongo/db/exec
parentd7325950d72c6aacd25ecbd65888c050fe63482c (diff)
downloadmongo-1e11cda15ddae9972f9993a7d6b6cbf9d172bcb3.tar.gz
SERVER-30407 Store pre/post-image documents when running findAndModify with txnNumber
Diffstat (limited to 'src/mongo/db/exec')
-rw-r--r--src/mongo/db/exec/delete.cpp10
-rw-r--r--src/mongo/db/exec/update.cpp25
2 files changed, 33 insertions, 2 deletions
diff --git a/src/mongo/db/exec/delete.cpp b/src/mongo/db/exec/delete.cpp
index 6262279c054..497e4ed04ec 100644
--- a/src/mongo/db/exec/delete.cpp
+++ b/src/mongo/db/exec/delete.cpp
@@ -215,8 +215,14 @@ PlanStage::StageState DeleteStage::doWork(WorkingSetID* out) {
if (!_params.isExplain) {
try {
WriteUnitOfWork wunit(getOpCtx());
- _collection->deleteDocument(
- getOpCtx(), _params.stmtId, recordId, _params.opDebug, _params.fromMigrate);
+ _collection->deleteDocument(getOpCtx(),
+ _params.stmtId,
+ recordId,
+ _params.opDebug,
+ _params.fromMigrate,
+ false,
+ _params.returnDeleted ? Collection::StoreDeletedDoc::On
+ : Collection::StoreDeletedDoc::Off);
wunit.commit();
} catch (const WriteConflictException&) {
memberFreer.Dismiss(); // Keep this member around so we can retry deleting it.
diff --git a/src/mongo/db/exec/update.cpp b/src/mongo/db/exec/update.cpp
index 0788a621ee9..ea3c014c28c 100644
--- a/src/mongo/db/exec/update.cpp
+++ b/src/mongo/db/exec/update.cpp
@@ -143,6 +143,19 @@ const std::vector<std::unique_ptr<FieldRef>>* getImmutableFields(OperationContex
return NULL;
}
+OplogUpdateEntryArgs::StoreDocOption getStoreDocMode(const UpdateRequest& updateRequest) {
+ if (updateRequest.shouldReturnNewDocs()) {
+ return OplogUpdateEntryArgs::StoreDocOption::PostImage;
+ }
+
+ if (updateRequest.shouldReturnOldDocs()) {
+ return OplogUpdateEntryArgs::StoreDocOption::PreImage;
+ }
+
+ invariant(!updateRequest.shouldReturnAnyDocs());
+ return OplogUpdateEntryArgs::StoreDocOption::None;
+}
+
} // namespace
const char* UpdateStage::kStageType = "UPDATE";
@@ -289,6 +302,12 @@ BSONObj UpdateStage::transformAndUpdate(const Snapshotted<BSONObj>& oldObj, Reco
args.update = logObj;
args.criteria = idQuery;
args.fromMigrate = request->isFromMigration();
+ args.storeDocOption = getStoreDocMode(*request);
+
+ if (args.storeDocOption == OplogUpdateEntryArgs::StoreDocOption::PreImage) {
+ args.preImageDoc = oldObj.value().getOwned();
+ }
+
StatusWith<RecordData> newRecStatus = _collection->updateDocumentWithDamages(
getOpCtx(),
recordId,
@@ -320,6 +339,12 @@ BSONObj UpdateStage::transformAndUpdate(const Snapshotted<BSONObj>& oldObj, Reco
args.update = logObj;
args.criteria = idQuery;
args.fromMigrate = request->isFromMigration();
+ args.storeDocOption = getStoreDocMode(*request);
+
+ if (args.storeDocOption == OplogUpdateEntryArgs::StoreDocOption::PreImage) {
+ args.preImageDoc = oldObj.value().getOwned();
+ }
+
newRecordId = _collection->updateDocument(getOpCtx(),
recordId,
oldObj,