[SERVER-16063] Rewrite findAndModify Created: 10/Nov/14  Updated: 12/Jul/16  Resolved: 14/Apr/15

Status: Closed
Project: Core Server
Component/s: Querying, Write Ops
Affects Version/s: None
Fix Version/s: 3.1.2

Type: Improvement Priority: Major - P3
Reporter: J Rassi Assignee: Charlie Swanson
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-6865 positional operator projection does n... Closed
is duplicated by SERVER-23171 Bad projection with findAndModify() Closed
is duplicated by SERVER-12414 Projecting {$meta: textScore} does no... Closed
is duplicated by SERVER-15128 Explain command for explaining findAn... Closed
Related
related to SERVER-16071 The nscanned and nscannedObjects is n... Closed
related to SERVER-16469 findAndModify with sort exceeds inter... Closed
related to SERVER-18054 Crash when running findAndModify agai... Closed
related to SERVER-19957 findAndModify with remove=true doesn'... Closed
related to SERVER-24462 findAndModify does not update Top Closed
is related to SERVER-15715 find_and_modify appears to be taking ... Closed
Backwards Compatibility: Fully Compatible
Sprint: Quint 3.1.0, Quint Iteration 3.1.1, Quint Iteration 3.1.2
Participants:

 Description   
Overview

The findAndModify command will be re-implemented in terms of getExecutorDelete() and getExecutorUpdate(). If the findAndModify specifies remove, then it will use getExecutorDelete() to retrieve a PlanExecutor wrapping a DeleteStage. If findAndModify specifies update, then it will use getExecutorUpdate() to retrieve a PlanExecutor wrapping an UpdateStage.

Details

In order to support findAndModify, the UpdateStage and the DeleteStage will be extended as follows:

  • A returnDeleted option will be added to DeleteRequest, with a default of false. Find and modify operations will set this option to true. A delete PlanExecutor with returnDeleted set will return PlanExecutor::ADVANCED and an owned copy of the deleted object every time that it commits a document delete.
  • The option returnDocs will be added to UpdateRequest, replacing the existing storeResultDoc option. It will take one of three values: RETURN_NEW, RETURN_OLD, or RETURN_NONE.
  • If RETURN_NEW, the PlanExecutor will return PlanExecutor::ADVANCED with a owned or unowned copy of each updated document's post-image. If the update results in an insert, it will return ADVANCED once and return the inserted document.
  • If RETURN_OLD, the PlanExecutor will return PlanExecutor::ADVANCED with an owned copy of each updated document's pre-image. If the update results in an insert, it will return neither ADVANCED nor will it return a copy of the updated document.
  • If RETURN_NONE, the behavior will remain as is. Namely, the PlanExecutor will never return ADVANCED.
Explain

This change should allow for a sane implementation of CmdFindAndModify::explain(). The explain will return the UPDATE or DELETE plan tree being used to execute the operation.

Further notes
  • findAndModify will have the same behavior under concurrency as regular updates and deletes. It will take a MODE_IX lock and will use a YIELD_AUTO plan.
  • If upsert is set to true, this will simply be passed through by setting the upsert flag on the UpdateRequest.
  • findAndModify will continue to require its own handling for WriteConflictException retry and for collection creation on upsert into an empty collection.
  • Find and modify will no longer depend on helpers such as deleteObjects() or mongo::update().
  • This will probably involve a rewrite or at least clean up the parsing of the command BSON.


 Comments   
Comment by Githook User [ 14/Apr/15 ]

Author:

{u'name': u'Charlie', u'email': u'charlie.swanson@mongodb.com'}

Message: SERVER-16063 Rewrite the findAndModify command.

Changed UpdateStage to return the prior or newly-updated version of
a document if request. also changed DeleteStage to return the deleted
document if requested.

Added explain support to the findAndModify command.
Branch: master
https://github.com/mongodb/mongo/commit/7a36b1598c45ea07a4713d4630fee204ff782e96

Comment by J Rassi [ 02/Mar/15 ]

matt.parlane@gmail.com: nope. This ticket is a simple refactor of existing functionality, and will include no user-facing changes.

Comment by Matt Parlane [ 02/Mar/15 ]

Is this anything to do with https://jira.mongodb.org/browse/SERVER-11753 ? Would be ultra sweet if that could be done as well.

Generated at Thu Feb 08 03:39:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.