Elffuss BraidHub

kikocis/java-driver public

Don't use notification lock for onSuspected.
Changeset5ae6590a9129b7982eb2704276a657b9fbd19a1e553886bbf2b08be62b5c69b2
Authorolim7t <omichallat+github@gmail.com> · 2014-12-20 16:23 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-12-20 16:26 +01:00
Parents700f2fff0c89

Browse the files at this changeset

1 file changed

modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +16 −33
@@ -1478,7 +1478,7 @@
14781478 });
14791479 }
14801480
1481- public void onSuspected(final Host host) throws InterruptedException {
1481+ public void onSuspected(final Host host) {
14821482 logger.debug("Host {} is Suspected", host);
14831483
14841484 if (isClosed())
@@ -1492,10 +1492,6 @@
14921492 return;
14931493 }
14941494
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-
14991495 // We need to
15001496 // 1) mark the node suspect if no-one has bitten us to it
15011497 // 2) start the reconnection attempt
@@ -1506,15 +1502,10 @@
15061502 // If multiple threads get there, we want to start reconnection attempts only
15071503 // once, but we also don't want said threads to return from this method before
15081504 // 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)
15181509 return;
15191510
15201511 // Start the initial initial reconnection attempt
@@ -1542,17 +1533,14 @@
15421533 }));
15431534
15441535 loadBalancingPolicy().onSuspected(host);
1536+ }
15451537
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);
15521541
1553- } finally {
1554- host.notificationsLock.unlock();
1555- }
1542+ for (Host.StateListener listener : listeners)
1543+ listener.onSuspected(host);
15561544 }
15571545
15581546 // Use triggerOnDown unless you're sure you want to run this on the current thread.
@@ -1871,16 +1859,11 @@
18711859 if (isHostAddition || !markSuspected) {
18721860 triggerOnDown(host, isHostAddition);
18731861 } 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);
18841867 }
18851868 }
18861869 return isDown;