kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 5ae6590a9129b7982eb2704276a657b9fbd19a1e553886bbf2b08be62b5c69b2 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-12-20 16:23 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-12-20 16:26 +01:00 |
| Parents | 700f2fff0c89 |
1 file changed
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +16 −33
| @@ -1478,7 +1478,7 @@ | ||
| 1478 | 1478 | }); |
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | - public void onSuspected(final Host host) throws InterruptedException { | |
| 1481 | + public void onSuspected(final Host host) { | |
| 1482 | 1482 | logger.debug("Host {} is Suspected", host); |
| 1483 | 1483 | |
| 1484 | 1484 | if (isClosed()) |
| @@ -1492,10 +1492,6 @@ | ||
| 1492 | 1492 | return; |
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | - // If we've already mark the node down/suspected, ignore this | |
| 1496 | - if (host.state == Host.State.SUSPECT || host.reconnectionAttempt.get() != null) | |
| 1497 | - return; | |
| 1498 | - | |
| 1499 | 1495 | // We need to |
| 1500 | 1496 | // 1) mark the node suspect if no-one has bitten us to it |
| 1501 | 1497 | // 2) start the reconnection attempt |
| @@ -1506,15 +1502,10 @@ | ||
| 1506 | 1502 | // If multiple threads get there, we want to start reconnection attempts only |
| 1507 | 1503 | // once, but we also don't want said threads to return from this method before |
| 1508 | 1504 | // the loadbalancing policy has been informed (otherwise those threads won't |
| 1509 | - // consider the host suspect but simply ignore it). So we lock. | |
| 1510 | - boolean locked = host.notificationsLock.tryLock(NOTIF_LOCK_TIMEOUT_SECONDS, TimeUnit.SECONDS); | |
| 1511 | - if (!locked) { | |
| 1512 | - logger.warn("Could not acquire notifications lock within {} seconds, ignoring SUSPECTED notification for {}", NOTIF_LOCK_TIMEOUT_SECONDS, host); | |
| 1513 | - return; | |
| 1514 | - } | |
| 1515 | - try { | |
| 1516 | - // Again, exit if someone beat us to suspecting the host | |
| 1517 | - if (!host.setSuspected() || host.reconnectionAttempt.get() != null) | |
| 1505 | + // consider the host suspect but simply ignore it). So we synchronize. | |
| 1506 | + synchronized (host) { | |
| 1507 | + // If we've already marked the node down/suspected, ignore this | |
| 1508 | + if (!host.setSuspected() || host.reconnectionAttempt.get() != null) | |
| 1518 | 1509 | return; |
| 1519 | 1510 | |
| 1520 | 1511 | // Start the initial initial reconnection attempt |
| @@ -1542,17 +1533,14 @@ | ||
| 1542 | 1533 | })); |
| 1543 | 1534 | |
| 1544 | 1535 | loadBalancingPolicy().onSuspected(host); |
| 1536 | + } | |
| 1545 | 1537 | |
| 1546 | - controlConnection.onSuspected(host); | |
| 1547 | - for (SessionManager s : sessions) | |
| 1548 | - s.onSuspected(host); | |
| 1549 | - | |
| 1550 | - for (Host.StateListener listener : listeners) | |
| 1551 | - listener.onSuspected(host); | |
| 1538 | + controlConnection.onSuspected(host); | |
| 1539 | + for (SessionManager s : sessions) | |
| 1540 | + s.onSuspected(host); | |
| 1552 | 1541 | |
| 1553 | - } finally { | |
| 1554 | - host.notificationsLock.unlock(); | |
| 1555 | - } | |
| 1542 | + for (Host.StateListener listener : listeners) | |
| 1543 | + listener.onSuspected(host); | |
| 1556 | 1544 | } |
| 1557 | 1545 | |
| 1558 | 1546 | // Use triggerOnDown unless you're sure you want to run this on the current thread. |
| @@ -1871,16 +1859,11 @@ | ||
| 1871 | 1859 | if (isHostAddition || !markSuspected) { |
| 1872 | 1860 | triggerOnDown(host, isHostAddition); |
| 1873 | 1861 | } else { |
| 1874 | - try { | |
| 1875 | - // Note that we do want to call onSuspected on the current thread, as the whole point is | |
| 1876 | - // that by the time this method return, the host initialReconnectionAttempt will have been | |
| 1877 | - // set and the load balancing policy informed of the suspection. We know that onSuspected | |
| 1878 | - // does little work (and non blocking one) itself however. | |
| 1879 | - onSuspected(host); | |
| 1880 | - } catch (InterruptedException e) { | |
| 1881 | - // This is most likely due to shutdown | |
| 1882 | - logger.warn("Interrupted while trying to set host SUSPECT, aborting"); | |
| 1883 | - } | |
| 1862 | + // Note that we do want to call onSuspected on the current thread, as the whole point is | |
| 1863 | + // that by the time this method return, the host initialReconnectionAttempt will have been | |
| 1864 | + // set and the load balancing policy informed of the suspection. We know that onSuspected | |
| 1865 | + // does little work (and non blocking one) itself however. | |
| 1866 | + onSuspected(host); | |
| 1884 | 1867 | } |
| 1885 | 1868 | } |
| 1886 | 1869 | return isDown; |