From 1e11cda15ddae9972f9993a7d6b6cbf9d172bcb3 Mon Sep 17 00:00:00 2001 From: Randolph Tan Date: Thu, 27 Jul 2017 10:32:09 -0400 Subject: SERVER-30407 Store pre/post-image documents when running findAndModify with txnNumber --- src/mongo/db/exec/delete.cpp | 10 ++++++++-- src/mongo/db/exec/update.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src/mongo/db/exec') 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>* 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& 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 newRecStatus = _collection->updateDocumentWithDamages( getOpCtx(), recordId, @@ -320,6 +339,12 @@ BSONObj UpdateStage::transformAndUpdate(const Snapshotted& 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, -- cgit v1.2.1