[SERVER-28043] mongos does not obey readPreference for queries over views Created: 17/Feb/17  Updated: 29/Jan/18  Resolved: 05/Apr/17

Status: Closed
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: 3.4.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: James Wahlin
Resolution: Duplicate Votes: 0
Labels: read-only-views
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-28040 Fix maxTimeMS/readPref/readConcern fo... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

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
Participants:

 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.



 Comments   
Comment by James Wahlin [ 05/Apr/17 ]

A fix for this issue was delivered under SERVER-28040.

Comment by James Wahlin [ 08/Mar/17 ]

I suspect readConcern is being discarded as well on mongos rewrite. Will confirm and fix under this ticket if it is the case.

Generated at Thu Feb 08 04:16:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.