[JAVA-2081] MongoClient does not respect ReadPreference Created: 12/Jan/16 Updated: 13/Jan/16 Resolved: 13/Jan/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Command Operations |
| Affects Version/s: | 3.0.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kay Agahd | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Linux 64 Bit |
||
| Issue Links: |
|
||||||||
| Description |
|
In the API doc is stated:
However, this seems not to apply at least to the follwing methods because they are overriding the actual set ReadPreference by "ReadPreference.primary()":
This is very annoying because we want explicitly get this info from a secondary. |
| Comments |
| Comment by Kay Agahd [ 13/Jan/16 ] | ||||||||||||
|
Great, I confirm that v3.0.1 fixes the bug! So the API doc I've cited is correct too. Thank you! | ||||||||||||
| Comment by Jeffrey Yemin [ 12/Jan/16 ] | ||||||||||||
|
I neglected to look at the Affects Version field. Now that I see you're on 3.0.0, I suspect you're just hitting | ||||||||||||
| Comment by Kay Agahd [ 12/Jan/16 ] | ||||||||||||
We are connecting directly to one secondary (of a replset consisting of 3 members) by calling:
The options contain "readPreference(ReadPreference.secondaryPreferred())".
The reason we want to use a secondary is that we analyze the db schema from time to time to see any degradation of the schema, i.e. if fields are always using the same type, how big they are, how often they occur etc. Since this a very time and resource consuming task we prefer to let it run on a secondary. One of the first commands to achieve this goal is to list all databases and collections. If these two commands require a primary we would need to put (also) the primary in the connection string, which want to avoid in order to be 100% sure that the primary is not being queried or stressed. It seems that this issue had already been fixed in v2.13.2 but it revived in v3.0.
Who is the client? The driver or the user of the driver?
Are you saying that the driver code is ok but only the doc is wrong? If so, why did you say that:
| ||||||||||||
| Comment by Jeffrey Yemin [ 12/Jan/16 ] | ||||||||||||
|
The Java driver is implementing the server selection specification for use of read preference with commands, which states:
As indicated by the last paragraph quoted above, the supported way to use command helpers like these against a secondary is to connect directly to the secondary, e.g.
There is definitely room to improve the documentation of command helpers for read operations to indicate that they don't respect read preference, so thank you for pointing that out. I'd also like to know why you explicitly want to execute these operations against a secondary. Can you let me know? Regards, |