Shard key update fails with a duplicate key error when the target shard retains an orphan with the same _id

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: 7.0.0, 8.0.0, 9.0.0-rc0, 8.3.0
    • Component/s: None
    • None
    • Catalog and Routing
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      When updating a document's shard key in a way that requires moving the document to a different shard, the operation deletes the document from the current shard and inserts it on the shard owning the target key range, inside a transaction. The issue arises when the target shard of that insert is the same shard that previously donated the chunk containing the document and still retains the orphaned documents. When the shard key update then tries to insert the document with its new shard key value on that shard, it hits a duplicate key error on id due to the orphan. The operation fails with error code 11000 and the message: "Failed to update document's shard key field. There is either an orphan for this document or _id for this collection is not globally unique. :: caused by :: During insert stage of updating a shard key :: caused by :: E11000 duplicate key error collection: test.foo index: _id dup key:

      { _id: 1.0 }

      ".

        1. 0001-Repro-SERVER-129977.patch
          5 kB
          Jordi Serra Torrens

            Assignee:
            Unassigned
            Reporter:
            Jordi Serra Torrens
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: