Skip to content

Commit

Permalink
testmaster for single servers on creation JAVA-187
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Oct 27, 2010
1 parent d552e95 commit ac897e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/main/com/mongodb/DBTCPConnector.java
Expand Up @@ -345,6 +345,19 @@ void checkMaster( boolean force , boolean failIfNoMaster )
}
}

void testMaster()
throws MongoException {

DBPort p = null;
try {
p = _curPortPool.get();
p.runCommand( "admin" , new BasicDBObject( "nonce" , 1 ) );
}
finally {
_curPortPool.done( p );
}
}

private boolean _set( ServerAddress addr ){
if ( _curMaster == addr )
return false;
Expand Down
5 changes: 4 additions & 1 deletion src/main/com/mongodb/Mongo.java
Expand Up @@ -138,6 +138,7 @@ public Mongo( ServerAddress addr , MongoOptions options )
_options = options;
_connector = new DBTCPConnector( this , _addr );
_connector.checkMaster( true , true );
_connector.testMaster();
}

/**
Expand All @@ -162,6 +163,7 @@ public Mongo( ServerAddress left , ServerAddress right , MongoOptions options )
_options = options;
_connector = new DBTCPConnector( this , _addrs );
_connector.checkMaster( true , false );
_connector.testMaster();
}

/**
Expand Down Expand Up @@ -199,6 +201,7 @@ public Mongo( MongoURI uri )
_addr = new ServerAddress( uri.getHosts().get(0) );
_addrs = null;
_connector = new DBTCPConnector( this , _addr );
_connector.testMaster();
}
else {
List<ServerAddress> replicaSetSeeds = new ArrayList<ServerAddress>( uri.getHosts().size() );
Expand All @@ -207,9 +210,9 @@ public Mongo( MongoURI uri )
_addr = null;
_addrs = replicaSetSeeds;
_connector = new DBTCPConnector( this , replicaSetSeeds );
_connector.checkMaster( true , true );
}

_connector.checkMaster( true , true );
}

public DB getDB( String dbname ){
Expand Down

0 comments on commit ac897e5

Please sign in to comment.