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

mongos does not obey readPreference for queries over views

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 3.4.2
    • Fix Version/s: None
    • Component/s: Querying, Sharding
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Start a one-shard cluster consisting of a two-node replica set:

      var st = new ShardingTest({shards: {rs: {nodes: 2}}});
      

      Observe which node becomes the primary of the replica set. Then connect to mongos and create both a collection and a view on that collection:

      db.c.drop();
      db.createCollection("c");
      db.v.drop();
      db.createView("v", "c", []);
      

      Examine the logs to determine which node is targeted for the following queries:

      db.c.find().readPref("secondary").itcount();
      db.v.find().readPref("secondary").itcount();
      

      The query on c correctly targets the secondary, whereas the query on v incorrectly targets the primary.

      Show
      Start a one-shard cluster consisting of a two-node replica set: var st = new ShardingTest({shards: {rs: {nodes: 2}}}); Observe which node becomes the primary of the replica set. Then connect to mongos and create both a collection and a view on that collection: db.c.drop(); db.createCollection("c"); db.v.drop(); db.createView("v", "c", []); Examine the logs to determine which node is targeted for the following queries: db.c.find().readPref("secondary").itcount(); db.v.find().readPref("secondary").itcount(); The query on c correctly targets the secondary, whereas the query on v incorrectly targets the primary.
    • Sprint:
      Query 2017-03-27, Query 2017-04-17

      Description

      When mongos rewrites a query over a view as a query over the view's backing collection, it discards the readPreference. The result is that reads over views will always target the primary node of all involved shards, even if the application specified a read preference such as "secondary" or "secondaryPreferred".

      Note that mongos will always forward a query over a view to the primary shard in order to obtain the view definition, since it does not currently store view catalog information. This initial query will respect the readPreference. It is only as mongos rewrites the query given the view definition that we erroneously discard the server selection metadata.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              james.wahlin James Wahlin
              Reporter:
              david.storch David Storch
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: