Skip to content

Commit

Permalink
JAVA-334: too much exception logging from updater thread when a serve…
Browse files Browse the repository at this point in the history
…r is down

JAVA-347: in case all servers are down do not retry reads
  • Loading branch information
agirbal committed May 5, 2011
1 parent 4338530 commit ee7543a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
15 changes: 10 additions & 5 deletions src/main/com/mongodb/DBTCPConnector.java
Expand Up @@ -277,11 +277,11 @@ public String getConnectPoint(){

boolean _error( Throwable t, boolean slaveOk )
throws MongoException {
if ( _allHosts != null ){
_logger.log( Level.WARNING , "replica set mode, switching master" , t );
if ( _rsStatus.hasServerUp() ){
// the replset has at least 1 server up, try to see if should switch master
checkMaster( true , !slaveOk );
}
return true;
return _rsStatus.hasServerUp();
}

class MyPort {
Expand Down Expand Up @@ -346,7 +346,7 @@ void done( DBPort p ){
void error( DBPort p , Exception e ){
p.close();
_requestPort = null;
_logger.log( Level.SEVERE , "MyPort.error called" , e );
// _logger.log( Level.SEVERE , "MyPort.error called" , e );
}

void requestEnsureConnection(){
Expand Down Expand Up @@ -437,7 +437,12 @@ void testMaster()
}

private boolean _set( ServerAddress addr ){
_masterPortPool = _portHolder.get( addr );
DBPortPool newPool = _portHolder.get( addr );
if (newPool == _masterPortPool)
return false;

_logger.log(Level.WARNING, "Master switching from " + (_masterPortPool != null ? _masterPortPool.getServerAddress() : "null") + " to " + addr);
_masterPortPool = newPool;
return true;
}

Expand Down
29 changes: 19 additions & 10 deletions src/main/com/mongodb/ReplicaSetStatus.java
Expand Up @@ -118,6 +118,16 @@ ServerAddress getASecondary(){
return best._addr;
}

boolean hasServerUp() {
for (int i = 0; i < _all.size(); i++) {
Node n = _all.get(i);
if (n._ok) {
return true;
}
}
return false;
}

class Node {

Node( ServerAddress addr ){
Expand Down Expand Up @@ -151,10 +161,12 @@ synchronized void update(Set<Node> seenNodes){
_pingTime = _lastCheck - start;

if ( res == null ){
_ok = false;
return;
throw new MongoInternalException("Invalid null value returned from isMaster");
}

if (!_ok) {
_logger.log( Level.WARNING , "Server seen up: " + _addr );
}
_ok = true;
_isMaster = res.getBoolean( "ismaster" , false );
_isSecondary = res.getBoolean( "secondary" , false );
Expand Down Expand Up @@ -199,15 +211,12 @@ else if ( !_setName.equals( setName ) ){
}

}
catch ( MongoException e ){
Throwable root = e;
if ( e.getCause() != null )
root = e.getCause();
_logger.log( Level.FINE , "node down: " + _addr + " " + root );
_ok = false;
}
catch ( Exception e ){
_logger.log( Level.SEVERE , "can't update node: " + _addr , e );
if (_ok == true) {
_logger.log( Level.WARNING , "Server seen down: " + _addr, e );
} else if (Math.random() < 0.1) {

This comment has been minimized.

Copy link
@pyricau

pyricau May 30, 2013

💌

This comment has been minimized.

Copy link
@trnl

trnl May 30, 2013

Contributor

May be just decrease the Level to INFO?

_logger.log( Level.WARNING , "Server seen down: " + _addr );
}
_ok = false;
}

Expand Down

0 comments on commit ee7543a

Please sign in to comment.