Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-559

Aggregations are not performed on a secondary with SECONDARY_PREFERRED

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.5.2
    • Component/s: None
    • Environment:
      Ubuntu 12.04
      Mongos / mongod: 2.4.5

      This fix in PYTHON-446 appears to cause some issues.

      Situation:
      I have a replicaset, accessed via a mongos.

      Goal:
      I'm attempting to perform an aggregation against a secondary, using SECONDARY_PREFERRED. Initially, slave_okay was unset (the documentation says it is deprecated)

      Observation:
      Aggregations are performed on the primary, not the secondary. It looks as if the mongos is ignoring the readPreference or the driver is not sending it.

      Change 1:
      After browsing some code, there were indications that setting slave_okay may be required (the interctions between slave_okay and _use_master in collection.aggregate)

      Observation:
      No change in behaviour

      Change 2:

      Going deeper, I found the code from PYTHON-446 that only sets the read preference when connected to a mongos and readpreference is SECONDARY_PREFERRED if there are tags present.

      Observation:
      I short-circuited the check, and reads correctly come to the secondary.

      The comment just before the check states:

      1. For maximum backwards compatibility, don't set $readPreference
      2. for SECONDARY_PREFERRED unless tags are in use. Just rely on
      3. the slaveOkay bit (set automatically if read preference is not
      4. PRIMARY), which has the same behavior.

      This would be fine, but it appears that the slaveOkay bit is not respected (possibly in mongos?)(as I have ensured that it is set)

      This behaviour is pretty unexpected, as is any reliance on the slave_okay param.

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            david.henderson@triggeredmessaging.com David Henderson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: