Elffuss BraidHub

kikocis/java-driver public

Prevent faulty control connection from ignoring reconnecting hosts (JAVA-587).
Changeset211e9f833429223e2588398d46c9f594ae2d7d3baae6e318fd1a7a169e0b3ee5
Authorolim7t <omichallat+github@gmail.com> · 2014-12-14 19:31 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-12-14 20:57 +01:00
Parentse4b963e48dcf

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -14,6 +14,8 @@
1414 - [improvement] Make shuffle=true the default for TokenAwarePolicy (JAVA-504)
1515 - [bug] Fix bug when SUSPECT reconnection succeeds, but one of the pooled
1616 connections fails while bringing the node back up (JAVA-577)
17+- [bug] Prevent faulty control connection from ignoring reconnecting hosts
18+ (JAVA-587)
1719
1820
1921 2.0.8:
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +56 −49
@@ -382,39 +382,23 @@
382382 return cluster.translateAddress(addr);
383383 }
384384
385- private Row fetchNodeInfo(Host host, Connection c) {
386- try {
387- boolean isConnectedHost = c.address.equals(host.getSocketAddress());
388- if (isConnectedHost || host.listenAddress != null) {
389- DefaultResultSetFuture future = isConnectedHost
390- ? new DefaultResultSetFuture(null, new Requests.Query(SELECT_LOCAL))
391- : new DefaultResultSetFuture(null, new Requests.Query(SELECT_PEERS + " WHERE peer='" + host.listenAddress.getHostAddress() + '\''));
392- c.write(future);
393- return future.get().one();
394- }
395-
396- // We have to fetch the whole peers table and find the host we're looking for
397- DefaultResultSetFuture future = new DefaultResultSetFuture(null, new Requests.Query(SELECT_PEERS));
385+ private Row fetchNodeInfo(Host host, Connection c) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException {
386+ boolean isConnectedHost = c.address.equals(host.getSocketAddress());
387+ if (isConnectedHost || host.listenAddress != null) {
388+ DefaultResultSetFuture future = isConnectedHost
389+ ? new DefaultResultSetFuture(null, new Requests.Query(SELECT_LOCAL))
390+ : new DefaultResultSetFuture(null, new Requests.Query(SELECT_PEERS + " WHERE peer='" + host.listenAddress.getHostAddress() + '\''));
398391 c.write(future);
399- for (Row row : future.get()) {
400- InetSocketAddress addr = addressToUseForPeerHost(row, c.address, cluster, true);
401- if (addr != null && addr.equals(host.getSocketAddress()))
402- return row;
403- }
404- } catch (ConnectionException e) {
405- logger.debug("[Control connection] Connection error while refreshing node info ({})", e.getMessage());
406- signalError();
407- } catch (ExecutionException e) {
408- // If we're being shutdown during refresh, this can happen. That's fine so don't scare the user.
409- if (!isShutdown)
410- logger.debug("[Control connection] Unexpected error while refreshing node info", e);
411- signalError();
412- } catch (BusyConnectionException e) {
413- logger.debug("[Control connection] Connection is busy, reconnecting");
414- signalError();
415- } catch (InterruptedException e) {
416- Thread.currentThread().interrupt();
417- logger.debug("[Control connection] Interrupted while refreshing node list and token map, skipping it.");
392+ return future.get().one();
393+ }
394+
395+ // We have to fetch the whole peers table and find the host we're looking for
396+ DefaultResultSetFuture future = new DefaultResultSetFuture(null, new Requests.Query(SELECT_PEERS));
397+ c.write(future);
398+ for (Row row : future.get()) {
399+ InetSocketAddress addr = addressToUseForPeerHost(row, c.address, cluster, true);
400+ if (addr != null && addr.equals(host.getSocketAddress()))
401+ return row;
418402 }
419403 return null;
420404 }
@@ -430,26 +414,49 @@
430414 return true;
431415
432416 logger.debug("[Control connection] Refreshing node info on {}", host);
433- Row row = fetchNodeInfo(host, c);
434- if (row == null) {
435- if (c.isDefunct()) {
436- logger.debug("Control connection is down, could not refresh node info");
437- // Keep going with what we currently know about the node, otherwise we will ignore all nodes
438- // until the control connection is back up (which leads to a catch-22 if there is only one)
439- return true;
440- } else {
441- logger.error("No row found for host {} in {}'s peers system table. {} will be ignored.", host.getAddress(), c.address, host.getAddress());
417+ try {
418+ Row row = fetchNodeInfo(host, c);
419+ if (row == null) {
420+ if (c.isDefunct()) {
421+ logger.debug("Control connection is down, could not refresh node info");
422+ // Keep going with what we currently know about the node, otherwise we will ignore all nodes
423+ // until the control connection is back up (which leads to a catch-22 if there is only one)
424+ return true;
425+ } else {
426+ logger.error("No row found for host {} in {}'s peers system table. {} will be ignored.", host.getAddress(), c.address, host.getAddress());
427+ return false;
428+ }
429+ // Ignore hosts with a null rpc_address, as this is most likely a phantom row in system.peers (JAVA-428).
430+ // Don't test this for the control host since we're already connected to it anyway, and we read the info from system.local
431+ // which doesn't have an rpc_address column (JAVA-546).
432+ } else if (!c.address.equals(host.getSocketAddress()) && row.getInet("rpc_address") == null) {
433+ logger.error("No rpc_address found for host {} in {}'s peers system table. {} will be ignored.", host.getAddress(), c.address, host.getAddress());
442434 return false;
443435 }
444- // Ignore hosts with a null rpc_address, as this is most likely a phantom row in system.peers (JAVA-428).
445- // Don't test this for the control host since we're already connected to it anyway, and we read the info from system.local
446- // which doesn't have an rpc_address column (JAVA-546).
447- } else if (!c.address.equals(host.getSocketAddress()) && row.getInet("rpc_address") == null) {
448- logger.error("No rpc_address found for host {} in {}'s peers system table. {} will be ignored.", host.getAddress(), c.address, host.getAddress());
449- return false;
450- }
451436
452- updateInfo(host, row, cluster);
437+ updateInfo(host, row, cluster);
438+ return true;
439+
440+ } catch (ConnectionException e) {
441+ logger.debug("[Control connection] Connection error while refreshing node info ({})", e.getMessage());
442+ signalError();
443+ } catch (ExecutionException e) {
444+ // If we're being shutdown during refresh, this can happen. That's fine so don't scare the user.
445+ if (!isShutdown)
446+ logger.debug("[Control connection] Unexpected error while refreshing node info", e);
447+ signalError();
448+ } catch (BusyConnectionException e) {
449+ logger.debug("[Control connection] Connection is busy, reconnecting");
450+ signalError();
451+ } catch (InterruptedException e) {
452+ Thread.currentThread().interrupt();
453+ logger.debug("[Control connection] Interrupted while refreshing node info, skipping it.");
454+ } catch (Exception e) {
455+ logger.debug("[Control connection] Unexpected error while refreshing node info", e);
456+ signalError();
457+ }
458+ // If we got an exception, always return true. Otherwise a faulty control connection would cause
459+ // reconnected hosts to be ignored permanently.
453460 return true;
454461 }
455462