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

$unionWith stage for explain does not use the router role API

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0
    • Affects Version/s: 8.1.0-rc0, 8.0.0-rc13
    • Component/s: Query Execution
    • None
    • Query Execution
    • Fully Compatible
    • ALL
    • v8.0
    • Hide

      1. Run the attached repro in version c3475ffa8

      Show
      1. Run the attached repro in version c3475ffa8
    • QE 2024-07-22, QE 2024-08-05
    • 0

      SPM-3229 introduced the usage of the routing role API in queries, for example, SERVER-83751 changed how the $unionWith stage uses the mongoProcessInterface, it made sure that the routing role API is used ensuring query correctness in regards to data placement by honoring the shard versioning protocol in the execution of queries. However, the explain code is not currently using the routing role API, making the following scenario possible:

      Suppose a sharded cluster with 3 shards: shard0, shard1 and shard2

      1. We create a database db, and it's primary shard is shard0
      2. We create two collections: coll1 and coll2
      3. We move coll1 to shard2 with moveCollection
      4. We issue a query to shard2 that refreshes both caches for coll1 and coll2, like an aggregation with a $unionWith stage for example
      5. We move coll2 to shard1, making shard2 cache of coll2 stale
      6. We issue an explain of an aggregation with the $unionWith stage, with coll1 as outer collection, and coll2 as inner collection
      7. The explain command will be sent first to shard2, and then to shard0, because of the stale cache for coll2
      8. Considering the code pointed at above, the cache of coll2 will not be refreshed in shard2, the exception will be thrown back to the router
      9. The router will exhaust it's retries and the query will fail

      You can find a reproducible attached to the ticket. We should ensure the shard role API is being used not only in the stage code, but also in the explain path.

            Assignee:
            denis.grebennicov@mongodb.com Denis Grebennicov
            Reporter:
            marcos.grillo@mongodb.com Marcos José Grillo Ramirez
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: