[SERVER-19957] findAndModify with remove=true doesn't retry deleting document on WCE Created: 14/Aug/15  Updated: 19/Sep/15  Resolved: 08/Sep/15

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

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Max Hirschhorn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-16063 Rewrite findAndModify Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Quint 9 09/18/15
Participants:

 Description   

The WorkingSetMember is transitioned into the OWNED_OBJ state prior to the deletion of the document from the collection.

if (_params.returnDeleted) {
    // Save a copy of the document that is about to get deleted.
    BSONObj deletedDoc = member->obj.value();
    member->obj.setValue(deletedDoc.getOwned());
    member->loc = RecordId();
    member->transitionToOwnedObj();
}

Consider the following sequence of events:

  1. The user does {findAndModify: 'coll', query: {}, remove: true}}.
  2. The child of the DeleteStage advances and the corresponding WorkingSetMember is in the LOC_AND_OBJ state.
  3. We intend to return the delete document, so the WorkingSetMember is transitioned into the OWNED_OBJ state.
  4. Collection::deleteDocument() is called and throws a WriteConflictException.
  5. The WorkingSetID of the WorkingSetMember is saved in _idRetrying and the DeleteStage returns NEED_YIELD.
  6. DeleteStage::work() is called again and status is set to ADVANCED and the id is set to _idRetrying.
  7. The WorkingSetMember is in the OWNED_OBJ state and therefore returns false when member->hasLoc() is called.
  8. nInvalidateSkips is incremented and the DeleteStage returns NEED_TIME.

Thus, we won't actually retry deleting the document if a WriteConflictException occurred. Instead, we should transition the WorkingSetMember to the OWNED_OBJ state after the delete occurs.



 Comments   
Comment by Githook User [ 08/Sep/15 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: SERVER-19957 Transition to OWNED_OBJ state after performing the delete.

Otherwise if a WriteConflictException were to occur during
Collection::deleteDocument(), then a findAndModify operation with
remove=true would not retry deleting that document because the
associated WorkingSetMember no longer has a loc.
Branch: master
https://github.com/mongodb/mongo/commit/d346f03b7a5c67af809173a56c770801bd1e9eaf

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