Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-477

Read from primary server in replica set fails when using TaggedReadPreference

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.2
    • Component/s: Cluster Management
    • None
    • Environment:
      All components running on OS X 10.7.2. MongoDB version 2.0.1. Java driver version 2.7.2.

      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" }


      }
      ]

            Assignee:
            brendan Brendan W. McAdams
            Reporter:
            bhunt Bryan Hunt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: