[SERVER-4464] drivers and mongos should support 5 read preferences Created: 09/Dec/11 Updated: 29/Aug/14 Resolved: 19/Oct/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying, Sharding |
| Affects Version/s: | None |
| Fix Version/s: | 2.3.1 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Daniel Crosta | Assignee: | Randolph Tan |
| Resolution: | Done | Votes: | 3 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||
| Description |
|
There are five read preferences that drivers and mongos should support when routing queries and getmores: 1. PRIMARY – all reads are directed to the replica set (or shard) primary; if there is no primary, reads are rejected Drivers, and mongos, currently support option #1 (when slave_okay is false), and most drivers support option #3 (when slave_okay is true); old versions of some drivers do not direct reads to secondaries even when slave_okay is true, and so implement #2. Both drivers and mongos should allow for setting a default read preference and overriding the read preference on a per-request basis, as is currently the case with slave_okay. For backwards compatibility, the slave_okay bit should be set for modes 3, 4, and 5. EDIT: Renamed "PRIMARY_ONLY" => "PRIMARY"; "PRIMARY" => "PRIMARY_FIRST"; at least Java driver and Pymongo use ReadPreference.PRIMARY to mean what I had initially called "PRIMARY_ONLY". I think the particular names are less important than the behaviors they encapsulate. |
| Comments |
| Comment by Azat Khuzhin [ 05/Dec/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
And this is normal. I have php-fpm. With max workers = 60. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Randolph Tan [ 04/Dec/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi, I just discussed this with our PHP driver engineer. The PHP driver does have a connection pool, but the ratio between host/port/auth to the connection used is always 1:1. This means that you will always end up using the same mongos connection if you perform queries to the mongos on the same PHP process. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Azat Khuzhin [ 04/Dec/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I use PHP driver for connection to mongos. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Randolph Tan [ 04/Dec/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
nearest is the all option. Assuming that the ping time of all the nodes are within --localThreshold and no tags, nearest would pick any members that are reachable. However, be aware that a connection to mongos is not stateless. It will use the same connection to the shards as much as possible. So if you are using only one connection to mongos to test this, you will always get the same node. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Azat Khuzhin [ 04/Dec/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
> A primary can also be chosen as long as the ping time is not too high. You can also check out more of the details in our docs here: It works as "nearest". Not as "ALL" (as described in issue head). Do you planning for "ALL" read preference? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Randolph Tan [ 19/Oct/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Resolving ticket -> stuff that still needs to be done are split into smaller tickets linked to this ticket. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Richard Kreuter (Inactive) [ 09/Sep/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Shell support for ReadPreferences doesn't yet match drivers'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Randolph Tan [ 07/Aug/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi, A primary can also be chosen as long as the ping time is not too high. You can also check out more of the details in our docs here: http://docs.mongodb.org/manual/applications/replication/#nearest We are also working on the PHP driver implementation which would hopefully make it when we release 2.2 version of the server. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Azat Khuzhin [ 31/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Also I have a question about "nearest" Doesn't this new feature work, so that drivers will use only "primary" if it will be "nearest" ? Thanks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Azat Khuzhin [ 31/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Randolph, thanks. Unfortunately i don't use mongo shell When this feature will be available in it? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Randolph Tan [ 30/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Azat, The original slaveOk corresponds to the secondaryPreferred read preference mode. So even before this was implemented, slaveOk actually meant use secondaries unless they cannot be reached. If you want the primary to also server the requests, you can use the nearest mode. This is a new feature for the upcoming 2.2 release and we are still working on the documentation for it. If you are using the mongo shell, you can do something like this:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Azat Khuzhin [ 29/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Is because of this issue, clients (specifically mongos) will be route READ requests only to SECONDARY? I use 5665ee8b85d600c0720cb1e12774f5a660afa456 commit.
node6 and node5 - have READONLY shard, that updated by mapreduce only. Thanks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by auto [ 05/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {u'date': u'2012-06-14T09:58:05-07:00', u'email': u'randolph@10gen.com', u'name': u'Randolph Tan'}Message: Step#3 Integration to mongos and added helpers for mongo shell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Randolph Tan [ 03/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Note: if a driver sends to mongos with $readPreference without the slaveOk bit, old versioned mongod would complain "not master and slaveOk=false". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by auto [ 11/Jun/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {u'login': u'', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}Message: Step#2 Implement facility for selecting nodes given the read preference and tags. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Randolph Tan [ 07/Jun/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {u'login': u'', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}Message: Fixed buildbot failure on assertion failure when Node::toString() is called Branch: master | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by auto [ 07/Jun/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {u'login': u'', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}Message: Step#1 Added checker for matching tags. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 25/Feb/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In addition all non-primary-only ReadPref modes should support a no-older-than option to cut off reads from stale/replication-delayed nodes. |