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
    • # 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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

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