-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.6.5, 2.7.2
-
Component/s: None
Here is our code to start mongoDB:
for (String hostName : hostNames) { String tmp[] = hostName.split(":"); ServerAddress addr = new ServerAddress(tmp[0], Integer.parseInt(tmp[1])); hosts.add(addr); } mongo = new Mongo(hosts); db = mongo.getDB(dbName); WriteConcern wc = WriteConcern.valueOf(writeConcernName); db.setWriteConcern(wc); if (this.slaveOk) { db.slaveOk(); }
I find that Mongo instance does not check master;
The code of checking master is in Upate class:
_mongo.getConnector().checkMaster(true, false);//the second argument is failIfNoMaster
The checkMaster method code is in DBTcpConnection:
void checkMaster( boolean force , boolean failIfNoMaster ) throws MongoException { if ( _rsStatus != null ){ if ( _masterPortPool == null || force ){ ReplicaSetStatus.Node n = _rsStatus.ensureMaster(); if ( n == null ){ if ( failIfNoMaster ) throw new MongoException( "can't find a master" ); } else { _set( n._addr ); maxBsonObjectSize = _rsStatus.getMaxBsonObjectSize(); } } } else { // single server, may have to obtain max bson size if (maxBsonObjectSize == 0) maxBsonObjectSize = fetchMaxBsonObjectSize(); } }
So,there are two problem:
First is:if I want to check master in staring my web applcation,I just have no choice;
Second is: The Mongo object instance actually represents a pool of connections to the database,this thing is not any valuable if we don't check master;
I suggest that you can make checkMaster method publicly or get us a button is check master.
- is duplicated by
-
JAVA-520 There is no way to chack master in java's client api when new Mongo(serverList)
- Closed