[false alarm] A query to a viewful timeseries may return an empty response if the collection gets recreated through a rename

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Do
    • Priority: Major - P3
    • None
    • Affects Version/s: 5.0.0, 6.0.0, 7.0.0, 8.0.0, 8.2.0-rc0
    • Component/s: None
    • None
    • Catalog and Routing
    • ALL
    • 🟥 DDL
    • None
    • None
    • None
    • None
    • None
    • None

      Symptom

      Querying a viewful timeseries collection, on a sharded cluster, while a concurrent rename is targeting its main namespace may return an empty list of documents when the queried namespace has always had documents.

      const collT = db.createCollection("collT", {timeseries:{timeField:"t"}});
      const collO = db.createCollection("collO");
      
      // Inserting documents to both collections so that none of them are empty.
      collO.insert([{x:1},{x:2},{x:3}]);
      collT.insert(timeseriesDocs);
      
      // Run rename 'collO' to 'collT' in a parallell thread:
      const waitForParallelShell = startParallelShell(function() {
          db.adminCommand({renameCollection:"collO", to: "collT", dropTarget: true});
      });
      
      
      // The 'docs' variable can be empty even if neither of the two collections is empty.
      const docs = collT.find().toArray();

      This is a transitory behavior, meaning that the following queries will get correct results.

       

      Sequence of events that led to this behavior

      1. [Query] The mongos targets first the DBPrimary to resolve the view.
      2. [Query] The mongos receives the resolved namespace (which is db.system.buckets.coll).
      3. [Rename] At this moment, 'collO' gets renamed to 'collT'. This operation also drops the buckets collection.
      4. [Query] The mongos will fetch the routing information for the buckets namespace, which will be UNSHARDED since the collection has been dropped.
      5. [Query] The mongos will propagate the find command to the DBPrimary shard, which will return an empty list of documents since the buckets collection doesn't exist.

       

      Summary

      This bug is a consequence of the extra DBPrimary round trip done when querying viewful timeseries. Hence, it's been there since v5.0 when timeseries were introduced.

       

      Proposal solution

      A possible solution is to use the same method that write commands use to target a viewful timeseries collection. This involves checking whether routing information for the underlying bucket collection exists. If it does, the namespace and command are automatically translated on the mongos, without requiring a round-trip to the DBPrimary.

            Assignee:
            Unassigned
            Reporter:
            Silvia Surroca
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: