[JAVA-656] Don't checkMaster on slaveOk queries Created: 01/Oct/12  Updated: 08/Jan/13  Resolved: 26/Oct/12

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: None
Fix Version/s: 2.9.2, 2.10.0

Type: Improvement Priority: Major - P3
Reporter: Scott Hernandez (Inactive) Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to JAVA-680 Secondary reads on lists of mongos fa... Closed

 Description   

Disable checkMaster for slaveOk queries.



 Comments   
Comment by auto [ 08/Jan/13 ]

Author:

{u'date': u'2012-10-01T16:31:45Z', u'email': u'scotthernandez@gmail.com', u'name': u'Scott Hernandez'}

Message: JAVA-656: Don't checkMaster on slaveOk queries
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/1228cfec63214064c03b0e3ca779ec804d98cb22

Comment by auto [ 08/Jan/13 ]

Author:

{u'date': u'2012-10-01T16:31:45Z', u'email': u'scotthernandez@gmail.com', u'name': u'Scott Hernandez'}

Message: JAVA-656: Don't checkMaster on slaveOk queries
Branch: 2.10.x
https://github.com/mongodb/mongo-java-driver/commit/1228cfec63214064c03b0e3ca779ec804d98cb22

Comment by Jeffrey Yemin [ 26/Oct/12 ]

Closing this again. Fix for the regression will be done in scope of a new issue: JAVA-680

Comment by Jeffrey Yemin [ 25/Oct/12 ]

The fix for this 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

Comment by auto [ 02/Oct/12 ]

Author:

{u'date': u'2012-10-01T09:31:45-07:00', u'email': u'scotthernandez@gmail.com', u'name': u'Scott Hernandez'}

Message: JAVA-656: Don't checkMaster on slaveOk queries
Branch: release-2.9.x
https://github.com/mongodb/mongo-java-driver/commit/1228cfec63214064c03b0e3ca779ec804d98cb22

Comment by auto [ 02/Oct/12 ]

Author:

{u'date': u'2012-10-01T09:31:45-07:00', u'email': u'scotthernandez@gmail.com', u'name': u'Scott Hernandez'}

Message: JAVA-656: Don't checkMaster on slaveOk queries
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/cf02c8eee69fe941f266c5af267a905d0a14718f

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