[SERVER-65534] $documents doesn't work if a later stage needs to run on a shard (not mongos) Created: 13/Apr/22  Updated: 02/Feb/24  Resolved: 21/Sep/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Charlie Swanson Assignee: Chi-I Huang
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
causes SERVER-85892 $merge with pipeline after $documents... In Progress
Related
is related to SERVER-64480 Make $$SEARCH_META scope local to pip... Closed
is related to SERVER-65692 Avoid unnecessary cursors for $search... Closed
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.1, v6.0
Steps To Reproduce:

Try to run something like the following on a mongos:

db.aggregate([{$documents: [{}]}, {$out: "write it down"}])

Sprint: QO 2023-09-04, QO 2023-09-18, QO 2023-10-02
Participants:

 Description   

This limits the applicability, and is preventing another internal use case for $documents from working.



 Comments   
Comment by Githook User [ 28/Nov/23 ]

Author:

{'name': 'rakiz', 'email': 'sebastien.mendez@mongodb.com', 'username': 'rakiz'}

Message: SERVER-83461 Crash->throw on requiredToRunOnMongos/canRunOnMongos conflict

Since SERVER-65534 pipelines starting with the '$queue' stage must run on
mongoS when no 'CollectionRoutingInfo' is available. This, however, can
result in an invariant failure, because some pipelines starting with the
'$queue' stage may still not be allowed to run on mongoS.

In this fix we replace the invariant with a 'uassert', which was already
there, but did not cover the case introduced in SERVER-65534.
Branch: master
https://github.com/mongodb/mongo/commit/214fe871cc32544cbc63f1d85ff9ca8c785bcc78

Comment by Githook User [ 21/Sep/23 ]

Author:

{'name': 'Chi-I Huang', 'email': 'chii.huang@mongodb.com', 'username': 'chiihuang'}

Message: SERVER-65534 Introduce host requirement kRunOnceAnyNode for $documents

Running db.aggregate([{$documents: [{}]}, {$out: "test"}]) on mongos will fail because the host requirement of $queue kLocalOnly is translated to kMongoS, which conflicts with the requirement of $out which needs kPrimaryShard. In other words, kLocalOnly and kPrimaryShard cannot coexist in the same pipeline.

To avoid the conflict, this PR introduces a new requirement HostTypeRequirement::kRunOnceAnyNode which works well with kPrimaryShard.
Branch: master
https://github.com/mongodb/mongo/commit/7fd370bbe0236b26340d765480147fd9c0f13797

Comment by Ana Meza [ 22/Apr/22 ]

Passing to Product for guidance on priority

Generated at Thu Feb 08 06:02:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.