kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 36b017dc4f86c09db01c18f69ed661976aee6359047496c6fa6bbce6f1ddffd0 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-01-27 19:11 +01:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-05 14:33 -06:00 |
| Parents | 12fbb1df3cfc |
6 files changed
modified driver-core/CHANGELOG.rst +1 −0
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | - [improvement] Add connection heartbeat (JAVA-533) |
| 9 | 9 | - [improvement] Reduce level of logs on missing rpc_address (JAVA-568) |
| 10 | 10 | - [improvement] Expose node token and range information (JAVA-312) |
| 11 | +- [bug] Fix cluster name mismatch check at startup (JAVA-595) | |
| 11 | 12 | - [bug] Fix guava dependency when using OSGI (JAVA-620) |
| 12 | 13 | - [bug] Fix handling of DROP events when ks name is case-sensitive (JAVA-678) |
| 13 | 14 |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +12 −12
| @@ -1351,8 +1351,8 @@ | ||
| 1351 | 1351 | |
| 1352 | 1352 | void logClusterNameMismatch(Host host, String expectedClusterName, String actualClusterName) { |
| 1353 | 1353 | logger.warn("Detected added or restarted Cassandra host {} but ignoring it since its cluster name '{}' does not match the one " |
| 1354 | - + "currently known ({})", | |
| 1355 | - host, actualClusterName, expectedClusterName); | |
| 1354 | + + "currently known ({})", | |
| 1355 | + host, actualClusterName, expectedClusterName); | |
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | public ListenableFuture<?> triggerOnUp(final Host host) { |
| @@ -1469,15 +1469,15 @@ | ||
| 1469 | 1469 | } |
| 1470 | 1470 | } |
| 1471 | 1471 | |
| 1472 | - public ListenableFuture<?> triggerOnDown(final Host host) { | |
| 1473 | - return triggerOnDown(host, false); | |
| 1472 | + public ListenableFuture<?> triggerOnDown(final Host host, boolean startReconnection) { | |
| 1473 | + return triggerOnDown(host, false, startReconnection); | |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | - public ListenableFuture<?> triggerOnDown(final Host host, final boolean isHostAddition) { | |
| 1476 | + public ListenableFuture<?> triggerOnDown(final Host host, final boolean isHostAddition, final boolean startReconnection) { | |
| 1477 | 1477 | return executor.submit(new ExceptionCatchingRunnable() { |
| 1478 | 1478 | @Override |
| 1479 | 1479 | public void runMayThrow() throws InterruptedException, ExecutionException { |
| 1480 | - onDown(host, isHostAddition, false); | |
| 1480 | + onDown(host, isHostAddition, false, startReconnection); | |
| 1481 | 1481 | } |
| 1482 | 1482 | }); |
| 1483 | 1483 | } |
| @@ -1492,7 +1492,7 @@ | ||
| 1492 | 1492 | // connected to one in the first place, but if we ever do, simply hand it |
| 1493 | 1493 | // off to onDown |
| 1494 | 1494 | if (loadBalancingPolicy().distance(host) == HostDistance.IGNORED) { |
| 1495 | - triggerOnDown(host); | |
| 1495 | + triggerOnDown(host, true); | |
| 1496 | 1496 | return; |
| 1497 | 1497 | } |
| 1498 | 1498 | |
| @@ -1532,7 +1532,7 @@ | ||
| 1532 | 1532 | success = false; |
| 1533 | 1533 | } |
| 1534 | 1534 | if (!success) |
| 1535 | - onDown(host, false, true); | |
| 1535 | + onDown(host, false, true, true); | |
| 1536 | 1536 | } |
| 1537 | 1537 | })); |
| 1538 | 1538 | |
| @@ -1548,7 +1548,7 @@ | ||
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | // Use triggerOnDown unless you're sure you want to run this on the current thread. |
| 1551 | - private void onDown(final Host host, final boolean isHostAddition, final boolean isSuspectedVerification) throws InterruptedException, ExecutionException { | |
| 1551 | + private void onDown(final Host host, final boolean isHostAddition, final boolean isSuspectedVerification, boolean startReconnection) throws InterruptedException, ExecutionException { | |
| 1552 | 1552 | logger.debug("Host {} is DOWN", host); |
| 1553 | 1553 | |
| 1554 | 1554 | if (isClosed()) |
| @@ -1601,7 +1601,7 @@ | ||
| 1601 | 1601 | } |
| 1602 | 1602 | |
| 1603 | 1603 | // Don't start a reconnection if we ignore the node anyway (JAVA-314) |
| 1604 | - if (distance == HostDistance.IGNORED) | |
| 1604 | + if (distance == HostDistance.IGNORED || !startReconnection) | |
| 1605 | 1605 | return; |
| 1606 | 1606 | |
| 1607 | 1607 | // Note: we basically waste the first successful reconnection, but it's probably not a big deal |
| @@ -1861,7 +1861,7 @@ | ||
| 1861 | 1861 | boolean isDown = host.signalConnectionFailure(exception); |
| 1862 | 1862 | if (isDown) { |
| 1863 | 1863 | if (isHostAddition || !markSuspected) { |
| 1864 | - triggerOnDown(host, isHostAddition); | |
| 1864 | + triggerOnDown(host, isHostAddition, true); | |
| 1865 | 1865 | } else { |
| 1866 | 1866 | // Note that we do want to call onSuspected on the current thread, as the whole point is |
| 1867 | 1867 | // that by the time this method return, the host initialReconnectionAttempt will have been |
| @@ -2114,7 +2114,7 @@ | ||
| 2114 | 2114 | // right away, so we favor the detection to make the Host.isUp method more reliable. |
| 2115 | 2115 | Host hostDown = metadata.getHost(stAddr); |
| 2116 | 2116 | if (hostDown != null) |
| 2117 | - triggerOnDown(hostDown); | |
| 2117 | + triggerOnDown(hostDown, true); | |
| 2118 | 2118 | break; |
| 2119 | 2119 | } |
| 2120 | 2120 | break; |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +8 −0
| @@ -308,6 +308,14 @@ | ||
| 308 | 308 | return true; |
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | + } catch (UnsupportedProtocolVersionException e) { | |
| 312 | + cluster.manager.logUnsupportedVersionProtocol(host); | |
| 313 | + cluster.manager.triggerOnDown(host, false); | |
| 314 | + return false; | |
| 315 | + } catch (ClusterNameMismatchException e) { | |
| 316 | + cluster.manager.logClusterNameMismatch(host, e.expectedClusterName, e.actualClusterName); | |
| 317 | + cluster.manager.triggerOnDown(host, false); | |
| 318 | + return false; | |
| 311 | 319 | } catch (Exception e) { |
| 312 | 320 | logger.error("Error creating pool to " + host, e); |
| 313 | 321 | return false; |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterAssert.java +5 −0
| @@ -21,6 +21,11 @@ | ||
| 21 | 21 | return this; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | + public ClusterAssert hasClosedControlConnection() { | |
| 25 | + assertThat(actual.manager.controlConnection.isOpen()).isFalse(); | |
| 26 | + return this; | |
| 27 | + } | |
| 28 | + | |
| 24 | 29 | public HostAssert host(int hostNumber) { |
| 25 | 30 | // TODO at some point this won't work anymore if we have assertions that wait for a node to |
| 26 | 31 | // join the cluster, e.g. assertThat(cluster).node(3).comesUp(). |
modified driver-core/src/test/java/com/datastax/driver/core/HostAssert.java +13 −0
| @@ -32,6 +32,19 @@ | ||
| 32 | 32 | return this; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | + public HostAssert isNotReconnectingFromDown() { | |
| 36 | + assertThat(actual.getReconnectionAttemptFuture() != null && !actual.getReconnectionAttemptFuture().isDone()) | |
| 37 | + .isFalse(); | |
| 38 | + return this; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public HostAssert isNotReconnectingFromSuspected() { | |
| 42 | + assertThat(actual.getInitialReconnectionAttemptFuture() != null && !actual.getInitialReconnectionAttemptFuture().isDone()) | |
| 43 | + .isFalse(); | |
| 44 | + return this; | |
| 45 | + | |
| 46 | + } | |
| 47 | + | |
| 35 | 48 | public HostAssert comesUpWithin(long duration, TimeUnit unit) { |
| 36 | 49 | final CountDownLatch upSignal = new CountDownLatch(1); |
| 37 | 50 | StateListener upListener = new StateListenerBase() { |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionnedNodeTest.java +38 −13
| @@ -6,7 +6,11 @@ | ||
| 6 | 6 | import org.slf4j.LoggerFactory; |
| 7 | 7 | import org.testng.annotations.AfterMethod; |
| 8 | 8 | import org.testng.annotations.Test; |
| 9 | -import static org.testng.Assert.*; | |
| 9 | + | |
| 10 | +import static com.datastax.driver.core.Assertions.*; | |
| 11 | +import static com.datastax.driver.core.Host.State.ADDED; | |
| 12 | +import static com.datastax.driver.core.Host.State.DOWN; | |
| 13 | +import static com.datastax.driver.core.Host.State.UP; | |
| 10 | 14 | |
| 11 | 15 | /** |
| 12 | 16 | * Due to C* gossip bugs, system.peers may report nodes that are gone from the cluster. |
| @@ -20,18 +24,15 @@ | ||
| 20 | 24 | CCMBridge mainCcm, otherCcm; |
| 21 | 25 | Cluster mainCluster; |
| 22 | 26 | |
| 23 | - /** | |
| 24 | - * Tests the case when trying to reconnect to the foreign node results from a scheduled reconnection attempt. | |
| 25 | - */ | |
| 26 | 27 | @Test(groups = "long") |
| 27 | - public void testReconnectionToRegularNode() throws Exception { | |
| 28 | + public void should_ignore_recommissionned_node_on_reconnection_attempt() throws Exception { | |
| 28 | 29 | mainCcm = CCMBridge.create("main", 3); |
| 29 | 30 | // node1 will be our "recommissionned" node, for now we just stop it so that it stays in the peers table. |
| 30 | 31 | mainCcm.stop(1); |
| 31 | 32 | mainCcm.waitForDown(1); |
| 32 | 33 | |
| 33 | 34 | // Now start the driver that will connect to node2 and node3, and consider node1 down |
| 34 | - Cluster mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 35 | + mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 35 | 36 | mainCluster.connect(); |
| 36 | 37 | waitForCountUpHosts(mainCluster, 2); |
| 37 | 38 | // From that point, reconnections to node1 have been scheduled. |
| @@ -43,20 +44,17 @@ | ||
| 43 | 44 | // Give the driver the time to notice the node is back up and try to connect to it. |
| 44 | 45 | TimeUnit.SECONDS.sleep(32); |
| 45 | 46 | |
| 46 | - assertEquals(countUpHosts(mainCluster), 2); | |
| 47 | + assertThat(countUpHosts(mainCluster)).isEqualTo(2); | |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | - /** | |
| 50 | - * Tests the case when trying to reconnect to the foreign node results from a scheduled reconnection attempt. | |
| 51 | - */ | |
| 52 | 50 | @Test(groups = "long") |
| 53 | - public void testControlConnection() throws Exception { | |
| 51 | + public void should_ignore_recommissionned_node_on_control_connection_reconnect() throws Exception { | |
| 54 | 52 | mainCcm = CCMBridge.create("main", 2); |
| 55 | 53 | mainCcm.stop(1); |
| 56 | 54 | mainCcm.waitForDown(1); |
| 57 | 55 | |
| 58 | 56 | // Start the driver, the control connection will be on node2 |
| 59 | - Cluster mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 57 | + mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 60 | 58 | mainCluster.connect(); |
| 61 | 59 | waitForCountUpHosts(mainCluster, 1); |
| 62 | 60 | |
| @@ -69,7 +67,34 @@ | ||
| 69 | 67 | TimeUnit.SECONDS.sleep(32); |
| 70 | 68 | |
| 71 | 69 | // The driver should not try to reconnect the control connection to node1 |
| 72 | - assertFalse(mainCluster.manager.controlConnection.isOpen()); | |
| 70 | + assertThat(mainCluster).hasClosedControlConnection(); | |
| 71 | + } | |
| 72 | + | |
| 73 | + @Test(groups = "long") | |
| 74 | + public void should_ignore_recommissionned_node_on_session_init() throws Exception { | |
| 75 | + // Simulate the bug before starting the cluster | |
| 76 | + mainCcm = CCMBridge.create("main", 2); | |
| 77 | + mainCcm.stop(1); | |
| 78 | + mainCcm.waitForDown(1); | |
| 79 | + | |
| 80 | + otherCcm = CCMBridge.create("other", 1); | |
| 81 | + otherCcm.waitForUp(1); | |
| 82 | + | |
| 83 | + // Start the driver, it should only connect to node 2 | |
| 84 | + mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 85 | + | |
| 86 | + // When we first initialize the Cluster, all hosts are marked UP | |
| 87 | + assertThat(mainCluster).host(2).hasState(UP); | |
| 88 | + assertThat(mainCluster).host(1).hasState(UP); | |
| 89 | + | |
| 90 | + // Create a session. This will try to open a pool to node 1 and find out that the cluster name doesn't match. | |
| 91 | + mainCluster.connect(); | |
| 92 | + | |
| 93 | + // Node 1 should now be DOWN with no reconnection attempt | |
| 94 | + assertThat(mainCluster).host(1) | |
| 95 | + .hasState(DOWN) | |
| 96 | + .isNotReconnectingFromDown() | |
| 97 | + .isNotReconnectingFromSuspected(); | |
| 73 | 98 | } |
| 74 | 99 | |
| 75 | 100 | @AfterMethod(groups = "long") |