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

Secondary reads on lists of mongos fail until first write

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.9.2
    • Fix Version/s: 2.9.3, 2.10.0
    • Component/s: Connection Management
    • Labels:
      None
    • Operating System:
      ALL
    • # Replies:
      5
    • Last comment by Customer:
      true

      Description

      The fix for JAVA-656 introduced a regression. In the case where you have use the Mongo constructor that takes a list of ServerAddress, or a MongoURI with a list of server addresses, _masterPortPool starts as null. Before this change, the checkMaster call would block until an initial master was found. Now that it no longer does, there is a race between the background thread and application threads. If an application only does non-primary reads, and the list of servers is a list of mongos, until a write is done, then ensureMaster will never be called and you will keep getting this exception:

      10-25-2012 17:01:00 [Thread-427] ERROR com.xgen.svc.mms.svc.ping.BatchPrePopulationSvc [run:136] - Rare case where master=null, probably all servers are down
      com.mongodb.MongoException: Rare case where master=null, probably all servers are down
      	at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:434) ~[mongo.jar:na]
      	at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:276) ~[mongo.jar:na]
      	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:256) ~[mongo.jar:na]
      	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:289) ~[mongo.jar:na]
      	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:274) ~[mongo.jar:na]
      	at com.mongodb.DBCursor._check(DBCursor.java:368) ~[mongo.jar:na]
      	at com.mongodb.DBCursor._hasNext(DBCursor.java:459) ~[mongo.jar:na]
      	at com.mongodb.DBCursor.hasNext(DBCursor.java:484) ~[mongo.jar:na]

      This test demonstrates the problem.

      public class JAVA656Test {
          public static void main(String[] args) throws UnknownHostException {
              Mongo mongo = new Mongo(Arrays.asList(new ServerAddress("localhost:30999")));
              mongo.setReadPreference(ReadPreference.secondary());
              DBCollection collection = mongo.getDB("test").getCollection("JAVA656Test");
              for (int i = 0; i < 5; i++) {
                  try {
                      collection.findOne();
                  } catch (MongoException e) {
                      System.out.println(e.getMessage());
                  }
              }
       
              System.out.println("Inserting");
              collection.insert(new BasicDBObject());
       
              System.out.println("Trying again");
              collection.findOne();
              System.out.println("Done");
          }
      }

      Output is:

      Rare case where master=null, probably all servers are down
      Rare case where master=null, probably all servers are down
      Rare case where master=null, probably all servers are down
      Rare case where master=null, probably all servers are down
      Rare case where master=null, probably all servers are down
      Inserting
      Trying again
      Done

        Issue Links

          Activity

          Hide
          jeff.yemin Jeff Yemin added a comment -

          This is a regression introduced by JAVA-656

          Show
          jeff.yemin Jeff Yemin added a comment - This is a regression introduced by JAVA-656
          Hide
          auto auto (Inactive) added a comment -

          Author:

          {u'date': u'2012-10-25T15:15:13-07:00', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'}

          Message: JAVA-680: Fixing a regression introduced in the previous commit for this issue. In the case where the driver
          is not connected to a replica set, like in mongos HA, still may need to ensure there is a master
          Branch: release-2.9.x
          https://github.com/mongodb/mongo-java-driver/commit/356a633be8ad38760caf165a15045936a08e0a31

          Show
          auto auto (Inactive) added a comment - Author: {u'date': u'2012-10-25T15:15:13-07:00', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'} Message: JAVA-680 : Fixing a regression introduced in the previous commit for this issue. In the case where the driver is not connected to a replica set, like in mongos HA, still may need to ensure there is a master Branch: release-2.9.x https://github.com/mongodb/mongo-java-driver/commit/356a633be8ad38760caf165a15045936a08e0a31
          Hide
          auto auto (Inactive) added a comment -

          Author:

          {u'date': u'2012-10-25T15:15:13-07:00', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'}

          Message: JAVA-680: Fixing a regression introduced in the previous commit for this issue. In the case where the driver
          is not connected to a replica set, like in mongos HA, still may need to ensure there is a master
          Branch: master
          https://github.com/mongodb/mongo-java-driver/commit/af8066db002fea54854fe96bb240bb7b7501fb96

          Show
          auto auto (Inactive) added a comment - Author: {u'date': u'2012-10-25T15:15:13-07:00', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'} Message: JAVA-680 : Fixing a regression introduced in the previous commit for this issue. In the case where the driver is not connected to a replica set, like in mongos HA, still may need to ensure there is a master Branch: master https://github.com/mongodb/mongo-java-driver/commit/af8066db002fea54854fe96bb240bb7b7501fb96
          Hide
          auto auto (Inactive) added a comment -

          Author:

          {u'date': u'2012-10-25T22:15:13Z', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'}

          Message: JAVA-680: Fixing a regression introduced in the previous commit for this issue. In the case where the driver
          is not connected to a replica set, like in mongos HA, still may need to ensure there is a master
          Branch: 2.10.x
          https://github.com/mongodb/mongo-java-driver/commit/356a633be8ad38760caf165a15045936a08e0a31

          Show
          auto auto (Inactive) added a comment - Author: {u'date': u'2012-10-25T22:15:13Z', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'} Message: JAVA-680 : Fixing a regression introduced in the previous commit for this issue. In the case where the driver is not connected to a replica set, like in mongos HA, still may need to ensure there is a master Branch: 2.10.x https://github.com/mongodb/mongo-java-driver/commit/356a633be8ad38760caf165a15045936a08e0a31
          Hide
          auto auto (Inactive) added a comment -

          Author:

          {u'date': u'2012-10-25T22:15:13Z', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'}

          Message: JAVA-680: Fixing a regression introduced in the previous commit for this issue. In the case where the driver
          is not connected to a replica set, like in mongos HA, still may need to ensure there is a master
          Branch: master
          https://github.com/mongodb/mongo-java-driver/commit/356a633be8ad38760caf165a15045936a08e0a31

          Show
          auto auto (Inactive) added a comment - Author: {u'date': u'2012-10-25T22:15:13Z', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'} Message: JAVA-680 : Fixing a regression introduced in the previous commit for this issue. In the case where the driver is not connected to a replica set, like in mongos HA, still may need to ensure there is a master Branch: master https://github.com/mongodb/mongo-java-driver/commit/356a633be8ad38760caf165a15045936a08e0a31

            People

            • Assignee:
              Unassigned
              Reporter:
              jeff.yemin Jeff Yemin
              Participants:
              Last commenter:
              Barrie Segal
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                2 years, 19 weeks, 3 days ago
                Date of 1st Reply: