@@ -407,39 +407,23 @@ private static InetSocketAddress addressToUseForPeerHost(Row peersRow, InetSocke
407407 return cluster .translateAddress (addr );
408408 }
409409
410- private Row fetchNodeInfo (Host host , Connection c ) {
411- try {
412- boolean isConnectedHost = c .address .equals (host .getSocketAddress ());
413- if (isConnectedHost || host .listenAddress != null ) {
414- DefaultResultSetFuture future = isConnectedHost
415- ? new DefaultResultSetFuture (null , cluster .protocolVersion (), new Requests .Query (SELECT_LOCAL ))
416- : new DefaultResultSetFuture (null , cluster .protocolVersion (), new Requests .Query (SELECT_PEERS + " WHERE peer='" + host .listenAddress .getHostAddress () + '\'' ));
417- c .write (future );
418- return future .get ().one ();
419- }
420-
421- // We have to fetch the whole peers table and find the host we're looking for
422- DefaultResultSetFuture future = new DefaultResultSetFuture (null , cluster .protocolVersion (), new Requests .Query (SELECT_PEERS ));
410+ private Row fetchNodeInfo (Host host , Connection c ) throws ConnectionException , BusyConnectionException , ExecutionException , InterruptedException {
411+ boolean isConnectedHost = c .address .equals (host .getSocketAddress ());
412+ if (isConnectedHost || host .listenAddress != null ) {
413+ DefaultResultSetFuture future = isConnectedHost
414+ ? new DefaultResultSetFuture (null , cluster .protocolVersion (), new Requests .Query (SELECT_LOCAL ))
415+ : new DefaultResultSetFuture (null , cluster .protocolVersion (), new Requests .Query (SELECT_PEERS + " WHERE peer='" + host .listenAddress .getHostAddress () + '\'' ));
423416 c .write (future );
424- for (Row row : future .get ()) {
425- InetSocketAddress addr = addressToUseForPeerHost (row , c .address , cluster , true );
426- if (addr != null && addr .equals (host .getSocketAddress ()))
427- return row ;
428- }
429- } catch (ConnectionException e ) {
430- logger .debug ("[Control connection] Connection error while refreshing node info ({})" , e .getMessage ());
431- signalError ();
432- } catch (ExecutionException e ) {
433- // If we're being shutdown during refresh, this can happen. That's fine so don't scare the user.
434- if (!isShutdown )
435- logger .debug ("[Control connection] Unexpected error while refreshing node info" , e );
436- signalError ();
437- } catch (BusyConnectionException e ) {
438- logger .debug ("[Control connection] Connection is busy, reconnecting" );
439- signalError ();
440- } catch (InterruptedException e ) {
441- Thread .currentThread ().interrupt ();
442- logger .debug ("[Control connection] Interrupted while refreshing node list and token map, skipping it." );
417+ return future .get ().one ();
418+ }
419+
420+ // We have to fetch the whole peers table and find the host we're looking for
421+ DefaultResultSetFuture future = new DefaultResultSetFuture (null , cluster .protocolVersion (), new Requests .Query (SELECT_PEERS ));
422+ c .write (future );
423+ for (Row row : future .get ()) {
424+ InetSocketAddress addr = addressToUseForPeerHost (row , c .address , cluster , true );
425+ if (addr != null && addr .equals (host .getSocketAddress ()))
426+ return row ;
443427 }
444428 return null ;
445429 }
@@ -455,26 +439,49 @@ public boolean refreshNodeInfo(Host host) {
455439 return true ;
456440
457441 logger .debug ("[Control connection] Refreshing node info on {}" , host );
458- Row row = fetchNodeInfo (host , c );
459- if (row == null ) {
460- if (c .isDefunct ()) {
461- logger .debug ("Control connection is down, could not refresh node info" );
462- // Keep going with what we currently know about the node, otherwise we will ignore all nodes
463- // until the control connection is back up (which leads to a catch-22 if there is only one)
464- return true ;
465- } else {
466- logger .error ("No row found for host {} in {}'s peers system table. {} will be ignored." , host .getAddress (), c .address , host .getAddress ());
442+ try {
443+ Row row = fetchNodeInfo (host , c );
444+ if (row == null ) {
445+ if (c .isDefunct ()) {
446+ logger .debug ("Control connection is down, could not refresh node info" );
447+ // Keep going with what we currently know about the node, otherwise we will ignore all nodes
448+ // until the control connection is back up (which leads to a catch-22 if there is only one)
449+ return true ;
450+ } else {
451+ logger .error ("No row found for host {} in {}'s peers system table. {} will be ignored." , host .getAddress (), c .address , host .getAddress ());
452+ return false ;
453+ }
454+ // Ignore hosts with a null rpc_address, as this is most likely a phantom row in system.peers (JAVA-428).
455+ // Don't test this for the control host since we're already connected to it anyway, and we read the info from system.local
456+ // which doesn't have an rpc_address column (JAVA-546).
457+ } else if (!c .address .equals (host .getSocketAddress ()) && row .getInet ("rpc_address" ) == null ) {
458+ logger .error ("No rpc_address found for host {} in {}'s peers system table. {} will be ignored." , host .getAddress (), c .address , host .getAddress ());
467459 return false ;
468460 }
469- // Ignore hosts with a null rpc_address, as this is most likely a phantom row in system.peers (JAVA-428).
470- // Don't test this for the control host since we're already connected to it anyway, and we read the info from system.local
471- // which doesn't have an rpc_address column (JAVA-546).
472- } else if (!c .address .equals (host .getSocketAddress ()) && row .getInet ("rpc_address" ) == null ) {
473- logger .error ("No rpc_address found for host {} in {}'s peers system table. {} will be ignored." , host .getAddress (), c .address , host .getAddress ());
474- return false ;
475- }
476461
477- updateInfo (host , row , cluster );
462+ updateInfo (host , row , cluster );
463+ return true ;
464+
465+ } catch (ConnectionException e ) {
466+ logger .debug ("[Control connection] Connection error while refreshing node info ({})" , e .getMessage ());
467+ signalError ();
468+ } catch (ExecutionException e ) {
469+ // If we're being shutdown during refresh, this can happen. That's fine so don't scare the user.
470+ if (!isShutdown )
471+ logger .debug ("[Control connection] Unexpected error while refreshing node info" , e );
472+ signalError ();
473+ } catch (BusyConnectionException e ) {
474+ logger .debug ("[Control connection] Connection is busy, reconnecting" );
475+ signalError ();
476+ } catch (InterruptedException e ) {
477+ Thread .currentThread ().interrupt ();
478+ logger .debug ("[Control connection] Interrupted while refreshing node info, skipping it." );
479+ } catch (Exception e ) {
480+ logger .debug ("[Control connection] Unexpected error while refreshing node info" , e );
481+ signalError ();
482+ }
483+ // If we got an exception, always return true. Otherwise a faulty control connection would cause
484+ // reconnected hosts to be ignored permanently.
478485 return true ;
479486 }
480487
0 commit comments