[SERVER-37779] mongos does not correctly enforce that a change stream must be the first stage Created: 26/Oct/18  Updated: 29/Oct/23  Resolved: 07/Nov/18

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 4.0.0, 4.1.4
Fix Version/s: 4.0.5, 4.1.5

Type: Bug Priority: Critical - P2
Reporter: Charlie Swanson Assignee: Charlie Swanson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Participants:
Linked BF Score: 45

 Description   

The $changeStream stage is implemented by parsing as a single stage, but expanding into several internal-only stages for execution. One of those stages (DocumentSourceOplogMatch) is responsible for enforcing that it must be the first stage in the pipeline.

Unfortunately, there are some cases where we never send a $changeStream to a shard, and so we never create a DocumentSourceOplogMatch, and so it is never enforced that it must be the first stage in the pipeline. For example, the following pipeline should be illegal, but the $changeStream stage stays on mongos, because the $sort stage forces a split in the pipeline and keeps the merging half on mongos:

db.sharded_collection.aggregate([{$sort: {x: 1}}, {$changeStream: {}}])



 Comments   
Comment by Githook User [ 14/Nov/18 ]

Author:

{'name': 'Charlie Swanson', 'email': 'charlie.swanson@mongodb.com', 'username': 'cswanson310'}

Message: SERVER-37779 Step up enforcement that $changeStream must be first

Adds an additional check which enforces a $changeStream stage must be
the first stage in the pipeline which is robust to the case where a
$changeStream is only ever sent to a mongos.

(cherry picked from commit 505114314a5f4309f2857573db442604cb0e2b26)
Branch: v4.0
https://github.com/mongodb/mongo/commit/4624baffeaab8211af7f8cdef5c08529aa09e9f6

Comment by Githook User [ 07/Nov/18 ]

Author:

{'name': 'Charlie Swanson', 'email': 'charlie.swanson@mongodb.com', 'username': 'cswanson310'}

Message: SERVER-37779 Step up enforcement that $changeStream must be first

Adds an additional check which enforces a $changeStream stage must be
the first stage in the pipeline which is robust to the case where a
$changeStream is only ever sent to a mongos.
Branch: master
https://github.com/mongodb/mongo/commit/505114314a5f4309f2857573db442604cb0e2b26

Comment by Charlie Swanson [ 02/Nov/18 ]

This is through code review, just waiting for 4.0 to unfreeze

Generated at Thu Feb 08 04:46:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.