Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-706

Aggregate and mapReduce commands sent to mongos break when setting read preference

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.10.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      There is an incompatibility between mongos versions 2.0 and greater and previous version, in the way that command are handled.

      In mongos 2.0 and greater, commands could be wrapped in a $query field, e.g.

       
      {$query : {count : "test"} }
      

      so that they were more in line with how regular queries work, which require the wrapping when sending special fields, like $hint or $explain. In version 1.8 and previous, this wasn't allowed.

      The java driver never actually wrapped command like this, since commands didn't have any extra special fields to send. That changed with the 2.9.0 driver, when support for sending read preferences with commands was added. The way it was done was like this:

       
      {count : "test", $readPreference : {mode : "primary"}} 
      

      This works for most commands, but breaks some, including mapReduce and aggregate. To fix it, the driver should wraps the command in $query:

       
      {$query : { count : "test" }, $readPreference : {mode : "primary"}} 
      

      Unfortunately, this will break when sending the command to mongos version < 2.0, which doesn't support the wrapping. To alleviate this, we will take care to only do this wrapping if the requested read preference is something besides primary or secondaryPreferred. For primary, there is no need since that's the default, and for secondaryPreferred the driver will use the slaveOk bit instead.

      Since mongos < 2.2 don't understand read preferences anyway, this looks to be an acceptable choice.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: