Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-19957

findAndModify with remove=true doesn't retry deleting document on WCE

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.8
    • Affects Version/s: 3.1.2
    • Component/s: Querying, Write Ops
    • None
    • Fully Compatible
    • ALL
    • Quint 9 09/18/15

      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.

            Assignee:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: