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

Counts running against secondaries with ReadPreference of PrimaryPreferred

    • Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.2.2
    • Component/s: Sharding
    • None

      Hello,

      I originally filed this issue as relating to the C# driver, but after discussing it with Robert Stam he believes it may be an issue with MongoS and suggested I refile here. The original discussion is filed as CSHARP-640 for your reference.

      Our situation is that since we've upgraded to 2.2 our sharded setup has begun running all of our counts against the secondaries. This is a sharded collection of two replica sets. We have 2 servers and and an arbiter in each set. All the servers involved (config, mongoSes, and mongoDs are running 2.2.2 on Amazon Linux and/or Centos. We're running the 1.7 version of the C# driver specifying a read preference at the connection level of PrimaryPreferred. All of our queries are executing against the primary, but all of our count()'s are running on the secondaries.

      I've enabled Database Profiling on the collection on the secondary and I get about 400 a second of these (and only these!) type of queries which I believe are counts?

      /* 0 */
      {
      "ts" : ISODate("2012-12-07T16:45:27.767Z"),
      "op" : "command",
      "ns" : "ourdb.$cmd",
      "command" : {
      "count" : "OurCollection",
      "query" :

      { "pid" : 1320633, "vi" : true }

      },
      "ntoreturn" : 1,
      "keyUpdates" : 0,
      "numYield" : 0,
      "lockStats" : {
      "timeLockedMicros" :

      { "r" : NumberLong(739), "w" : NumberLong(0) }

      ,
      "timeAcquiringMicros" :

      { "r" : NumberLong(33610), "w" : NumberLong(2) }

      },
      "responseLength" : 48,
      "millis" : 0,
      "client" : "192.168.xx.xxx",
      "user" : ""
      }

      A similar trace on the primary reveals no such counts at all, only 400/s regular get and update queries as expected. If I shutdown the secondary, the counts do move over to the primary, but when both are online I'm unable to get anything but this situation. I've tried reversing the roles of the servers and the load reverses accordingly.

      We also have a non-sharded replica set which I've just checked and it doesn't seem to be exhibiting this behaviour (the primary is handling 200 queries and 200 commands per second. The secondary maybe 10 commands a second and zero queries).

      According to the documentation at http://docs.mongodb.org/manual/applications/replication/: "mongos currently does not route commands using read preferences; clients send all commands to shards’ primaries. See SERVER-7423."

      So, apparently, full support is being worked on for 2.3 and the situation we have now should be impossible as the commands can't go anywhere but primaries? Which leaves me quite confused.

      Have we misunderstood the current expected behaviour or is there an issue here? It's not a critical problem in our environment as our secondaries stay within a second or two of each other, but it's not ideal as the data can sometimes be stale on the counts if they happen quickly enough.

      Any clarification or assistance would be appreciated.

            Assignee:
            Unassigned Unassigned
            Reporter:
            andrew.fladmark@t101.com Andrew Fladmark
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: