Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-18705

DBClientRS::_isSecondaryQuery will return false for $query wrapped commands

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.0.3, 3.1.3
    • Component/s: Internal Client
    • Labels:
      None
    • ALL

      // 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.

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            adam.midvidy Adam Midvidy
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: