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

mongos does not obey readPreference for queries over views

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.4.2
    • Component/s: Querying, Sharding
    • Fully Compatible
    • ALL
    • 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.
    • Query 2017-03-27, Query 2017-04-17

      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.

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

              Created:
              Updated:
              Resolved: