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

Update without shard key might miss documents

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.3.1, 8.0.0-rc0
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • Cluster Scalability
    • Fully Compatible
    • ALL
    • v7.3
      1. Run the attached repro
    • Cluster Scalability 2024-3-18, Cluster Scalability 2024-4-1
    • 126

      PM-1632 added the possibility to run an update without a shard key in sharded clusters with all options. As part of the project SERVER-71133 added an optimization for findAndModify, trying to not go through the protocol if all the chunks are owned by a single shard. the collection has a single chunk.

      However, the following scenario might happen:

      1. A transaction with snapshot read concern starts and performs a write to a collection at time T1. This effectively sets the atClusterTime of the entire transaction to T1.
      2. A moveChunk happens, changing the placement for collection2 at time T2.
      3. A findAndModify for collection2 is issued, the said optimization for PM-1632 will try to target the destination shard of the migration, with the correct shard version, but with the wrong clusterTime (T1),

      This will cause the findAndModify to not find the document. You can find the repro attached. Until we can safely use the optimization, we could simply target using the default path.

      A similar bug can be observed for updateOne and deleteOne, although for that path, the targeting is separated from the decision to use the single shard optimization so we always will broadcast to all of the correct shards instead of using the two phase write protocol.

        1. snapshot_txn_with_migration.js
          1 kB
          Marcos José Grillo Ramirez

            Assignee:
            jason.zhang@mongodb.com Jason Zhang (Inactive)
            Reporter:
            marcos.grillo@mongodb.com Marcos José Grillo Ramirez
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: