-
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
- [Query] The mongos targets first the DBPrimary to resolve the view.
- [Query] The mongos receives the resolved namespace (which is db.system.buckets.coll).
- [Rename] At this moment, 'collO' gets renamed to 'collT'. This operation also drops the buckets collection.
- [Query] The mongos will fetch the routing information for the buckets namespace, which will be UNSHARDED since the collection has been dropped.
- [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.