[SERVER-18705] DBClientRS::_isSecondaryQuery will return false for $query wrapped commands Created: 28/May/15  Updated: 13/Jan/17  Resolved: 13/Jan/17

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 3.0.3, 3.1.3
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Adam Midvidy Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

// This is a command with secondary-possible read pref                                                                                                                                                     
// Only certain commands are supported for secondary operation.                                                                                                                                            
BSONObj actualQueryObj;                                                                                                                                                                                    
if (strcmp(queryObj.firstElement().fieldName(), "query") == 0) {                                                                                                                                           
    actualQueryObj = queryObj["query"].embeddedObject();                                                                                                                                                   
}                                                                                                                                                                                                          
else {                                                                                                                                                                                                     
    actualQueryObj = queryObj;                                                                                                                                                                             
}  

In practice, the embedded "wrapped" command can have a fieldname of either 'query' or '$query' and we only check for 'query'. The Server Selection spec actually mandates that drivers use '$query': see ( https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#id17).

The effect is that for commands that can run on a secondary, such as inline mapreduce, mongos will incorrectly run the commands on a primary of the shard, even with readPreference mode secondary. Note that this affects drivers OTHER than the shell, which wraps commands with 'query'.

EDIT: in practice this is not an issue as mongos already unwraps the queries (correctly) by the time they reach this point of the codebase.


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