[SERVER-38349] Aggregate with exchange can trip invariant Created: 30/Nov/18  Updated: 29/Oct/23  Resolved: 07/Dec/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 4.1.5
Fix Version/s: 4.1.7

Type: Bug Priority: Major - P3
Reporter: Ian Boros Assignee: Charlie Swanson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:
Linked BF Score: 45

 Description   

(function() {
 
    const st = new ShardingTest({shards: 2});
 
    assert.commandWorked(st.s.adminCommand({enableSharding: 'test'}));
    st.ensurePrimaryShard("test", st.shard0.shardName);
 
    assert.commandWorked(st.s.adminCommand({shardCollection: 'test.user', key: {_id: 1}}));
 
    const mongosDB = st.s.getDB('test');
    const coll = mongosDB.user;
    coll.insert({_id: 1});
    coll.insert({_id: -1});
 
    var res = assert.commandWorked(mongosDB.runCommand({
        aggregate: coll.getName(),
        pipeline: [],
        exchange: {policy: 'broadcast', consumers: NumberInt(5), bufferSize: NumberInt(1024)},
        cursor: {batchSize: 0}
    }));
 
    st.stop();
})();

This test will trip this invariant.

The situation is that we have an aggregation targeting 1 shard, but the request sent to the shard says there are 5 consumers, so the shard will open 5 cursors. On mongos, establishCursors() will return 5 cursors, leading to the invariant failing.



 Comments   
Comment by Githook User [ 07/Dec/18 ]

Author:

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

Message: SERVER-38349 Disallow exchange passed to mongos
Branch: master
https://github.com/mongodb/mongo/commit/67e98183b1d80bd12c6fd815fffe4e51619e0156

Comment by Charlie Swanson [ 04/Dec/18 ]

+1 on that idea - seems reasonable to me.

Comment by Ian Boros [ 04/Dec/18 ]

Yeah, after spending more time reading exchange I think that makes sense.

Comment by David Storch [ 04/Dec/18 ]

If I'm not mistaken, we should fix this by having mongos uassert() if the application specifies the exchange option to the aggregate command.

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