[JAVA-477] Read from primary server in replica set fails when using TaggedReadPreference Created: 27/Nov/11  Updated: 12/Aug/12  Resolved: 12/Aug/12

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: 2.7.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bryan Hunt Assignee: Brendan W. McAdams
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All components running on OS X 10.7.2. MongoDB version 2.0.1. Java driver version 2.7.2.


Issue Links:
Duplicate
duplicates JAVA-474 Enhance read preference support Closed

 Description   

I'm trying to use the TaggedReadPreference with the Java driver when
reading from a replica set. It seems to work as long as I specify a
secondary tag. When I specify the primary tag, I get the following
exception:

com.mongodb.MongoException: Could not find any valid secondaries with
the supplied tags ('

{ "locale" : "sc"}

'
at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:358)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:212)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305)
at com.mongodb.DBCollection.findOne(DBCollection.java:647)
at com.mongodb.DBCollection.findOne(DBCollection.java:626)

I also tested reading from the secondary and killing the primary. When
the secondary is elected the primary, the read fails with the same
exception above (just with a different locale).

My code looks like:

HashMap<String, String> tags = new HashMap<String, String>(1);
tags.put("locale", "sc");
...
dbCollection.setReadPreference(new
ReadPreference.TaggedReadPreference(tags));

My replica set is configured as:

PRIMARY> rs.conf()
{
"_id" : "test",
"version" : 3,
"members" : [
{
"_id" : 0,
"host" : "localhost:27020",
"priority" : 2,
"tags" :

{ "locale" : "sc" }


},
{
"_id" : 1,
"host" : "localhost:27021",
"tags" :

{ "locale" : "in" }


},
{
"_id" : 2,
"host" : "localhost:27022",
"tags" :

{ "locale" : "de" }


}
]



 Comments   
Comment by Jeffrey Yemin [ 12/Aug/12 ]

this will be fixed in 2.9.0

Comment by Brendan W. McAdams [ 14/Dec/11 ]

Fix depends on next major release of MongoDB which supports Tagged Read Preferencing in mongos.

Comment by Scott Hernandez (Inactive) [ 28/Nov/11 ]

It is currently enabled in master in github so if you build from source you can test it.

As Eliot said, it will not be in 2.7.x

Comment by Eliot Horowitz (Inactive) [ 28/Nov/11 ]

Its supposed to be in 2.8 (or whatever the next version of the driver is called).
Not sure if its status in the code there.

Comment by Bryan Hunt [ 28/Nov/11 ]

Doh! I was hoping to use this feature to help make my case for MongoDB with management. My use case is probably typical in that we need to deploy servers in multiple countries. Write propagation is not critical, but local reads are.

Any chance you would consider fixing the non-sharding case in 2.7.3 and then remove the feature in 2.7.4 so I could at least try a demo for my management?

Any ETA on when this feature will be fully released?

Comment by Brendan W. McAdams [ 28/Nov/11 ]

Inner Static class for Tagged Read Preference should be disabled to prevent user access to this not-yet-enabled feature.

Comment by Brendan W. McAdams [ 28/Nov/11 ]

Reading by tags is not currently supported and should have been disabled in the driver; it seems that the class stub for future support was left exposed in this release and shouldn't have been.

Until mongos supports reading by tags we are not adding support for that to our drivers to provide consistent support of features across sharded and unsharded setups.

Generated at Thu Feb 08 08:52:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.