[JAVA-848] "can't find a master" exception even with secondary readPref on a command Created: 07/Jun/13  Updated: 07/Jun/13  Resolved: 07/Jun/13

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

Type: Bug Priority: Major - P3
Reporter: Antoine Girbal Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I have 1 secondary up and running.
Running following code:

            try {
                CommandResult res = db.command(new BasicDBObject("isMaster", 1), 0, ReadPreference.secondaryPreferred());
            } catch (Exception e) {
                getLogger().log(Level.INFO, e.getMessage(), e);
            }

This errors with following:

INFO: can't find a master
com.mongodb.MongoException: can't find a master
	at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:503)
	at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:236)
	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
	at com.mongodb.DB.command(DB.java:261)
	at com.mongodb.DB.command(DB.java:243)

It also fails with:

  • ReadPreference.primaryPreferred()
  • ReadPreference.secondaryPreferred()

But it works fine using slaveOk:

CommandResult res = node.getServerDB().command(new BasicDBObject("isMaster", 1), Bytes.QUERYOPTION_SLAVEOK);



 Comments   
Comment by Jeffrey Yemin [ 07/Jun/13 ]

This is due to the read preferences spec. isMaster is not on the list of commands that obey read preference, and so it's sent to the primary. Try a command like dbStats, and it should work just fine.

See http://docs.mongodb.org/manual/core/read-preference/#database-commands for details.

Comment by Scott Hernandez (Inactive) [ 07/Jun/13 ]

How did you connect? (How did you create the MongoClient instance?)

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