[JAVA-602] Setting ReadPreference.PRIMARY on a find has no effect if slaveOk=true has been set in the connection string Created: 13/Jul/12 Updated: 12/Aug/12 Resolved: 12/Aug/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Connection Management |
| Affects Version/s: | 2.7.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Chris Barrett | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | connection, java, replicaset | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
When the connection string contains slaveOk=true as an option then the following line of (groovy) code may read from a secondary server in a replica set: collection.findOne(new BasicDBObject([_id: key]),null, ReadPreference.PRIMARY) I believe that this may well affect all find methods. This appears to be due to the code in OutMethod.appendQuery() which ORs in Bytes.QUERYOPTION_SLAVEOK if the read preference is NOT primary but does nothing if the read preference is primary. |
| Comments |
| Comment by Jeffrey Yemin [ 12/Aug/12 ] |
|
In 2.9.0 you can specify read preference in the connection string. |
| Comment by Chris Barrett [ 13/Jul/12 ] |
|
No problem. Chris. |
| Comment by Jeffrey Yemin [ 13/Jul/12 ] |
|
Chris, Thinking about this a bit more, I'm not convinced it's a bug. Read preferences supercedes slaveOk (slaveOk is now deprecated), so the idea is that applications should use one or the other, but not both. I think what we'll be doing soon is to allow you to set the default read preference in the connection string, and then it should work properly if you use that. |
| Comment by Jeffrey Yemin [ 13/Jul/12 ] |
|
Chris, let's hold off on that since we have some code in flight that's not yet pushed. Thanks for the offer though. Ordinarily we welcome pull requests. |
| Comment by Chris Barrett [ 13/Jul/12 ] |
|
Thanks for responding. If it helps I'm happy to look into it to see I'd I Chris |
| Comment by Jeffrey Yemin [ 13/Jul/12 ] |
|
Thanks for the report. We're doing some work on read preferences in 2.9.0 and perhaps will be able to address this as part of it. |