kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | f1dfa94e09504bade80cd687e58ca5afcbc8920e17cf22673ef1bedd2a03c825 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-08-04 10:56 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-08-05 19:00 +02:00 |
| Parents | 43c0a8985a89 |
7 files changed
modified changelog/README.md +1 −0
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | - [improvement] implement UPDATE ... IF EXISTS in QueryBuilder (JAVA-827) |
| 28 | 28 | - [improvement] Randomize contact points list to prevent hotspots (JAVA-618) |
| 29 | 29 | - [improvement] Surface the coordinator used on query failure (JAVA-720) |
| 30 | +- [bug] Handle contact points removed during init (JAVA-792) | |
| 30 | 31 | |
| 31 | 32 | Merged from 2.0.10_fixes branch: |
| 32 | 33 |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +19 −7
| @@ -30,7 +30,6 @@ | ||
| 30 | 30 | import com.google.common.base.Predicates; |
| 31 | 31 | import com.google.common.collect.*; |
| 32 | 32 | import com.google.common.util.concurrent.*; |
| 33 | - | |
| 34 | 33 | import org.slf4j.Logger; |
| 35 | 34 | import org.slf4j.LoggerFactory; |
| 36 | 35 | |
| @@ -1259,19 +1258,27 @@ | ||
| 1259 | 1258 | try { |
| 1260 | 1259 | while (true) { |
| 1261 | 1260 | try { |
| 1261 | + Collection<Host> allHosts = metadata.allHosts(); | |
| 1262 | + | |
| 1262 | 1263 | // At this stage, metadata.allHosts() only contains the contact points, that's what we want to pass to LBP.init(). |
| 1263 | 1264 | // But the control connection will initialize first and discover more hosts, so make a copy. |
| 1264 | - Set<Host> contactPointHosts = Sets.newHashSet(metadata.allHosts()); | |
| 1265 | + Set<Host> contactPointHosts = Sets.newHashSet(allHosts); | |
| 1265 | 1266 | |
| 1266 | 1267 | controlConnection.connect(); |
| 1267 | 1268 | if (connectionFactory.protocolVersion < 0) |
| 1268 | 1269 | connectionFactory.protocolVersion = 2; |
| 1269 | 1270 | |
| 1270 | - // The control connection can mark hosts down if it failed to connect to them, separate them | |
| 1271 | + // The control connection can mark hosts down if it failed to connect to them, or remove them if they weren't found | |
| 1272 | + // in the control host's system.peers. Separate them: | |
| 1271 | 1273 | Set<Host> downContactPointHosts = Sets.newHashSet(); |
| 1272 | - for (Host host : contactPointHosts) | |
| 1273 | - if (host.state == Host.State.DOWN) | |
| 1274 | + Set<Host> removedContactPointHosts = Sets.newHashSet(); | |
| 1275 | + for (Host host : contactPointHosts) { | |
| 1276 | + if (!allHosts.contains(host)) | |
| 1277 | + removedContactPointHosts.add(host); | |
| 1278 | + else if (host.state == Host.State.DOWN) | |
| 1274 | 1279 | downContactPointHosts.add(host); |
| 1280 | + } | |
| 1281 | + contactPointHosts.removeAll(removedContactPointHosts); | |
| 1275 | 1282 | contactPointHosts.removeAll(downContactPointHosts); |
| 1276 | 1283 | |
| 1277 | 1284 | // Now that the control connection is ready, we have all the information we need about the nodes (datacenter, |
| @@ -1279,13 +1286,18 @@ | ||
| 1279 | 1286 | loadBalancingPolicy().init(Cluster.this, contactPointHosts); |
| 1280 | 1287 | speculativeRetryPolicy().init(Cluster.this); |
| 1281 | 1288 | |
| 1289 | + for (Host host : removedContactPointHosts) { | |
| 1290 | + loadBalancingPolicy().onRemove(host); | |
| 1291 | + for (Host.StateListener listener : listeners) | |
| 1292 | + listener.onRemove(host); | |
| 1293 | + } | |
| 1282 | 1294 | for (Host host : downContactPointHosts) { |
| 1283 | 1295 | loadBalancingPolicy().onDown(host); |
| 1284 | 1296 | for (Host.StateListener listener : listeners) |
| 1285 | 1297 | listener.onDown(host); |
| 1286 | 1298 | } |
| 1287 | 1299 | |
| 1288 | - for (Host host : metadata.allHosts()) { | |
| 1300 | + for (Host host : allHosts) { | |
| 1289 | 1301 | // If the host is down at this stage, it's a contact point that the control connection failed to reach. |
| 1290 | 1302 | // Reconnection attempts are already scheduled, and the LBP and listeners have been notified above. |
| 1291 | 1303 | if (host.state == Host.State.DOWN) continue; |
| @@ -1898,7 +1910,7 @@ | ||
| 1898 | 1910 | |
| 1899 | 1911 | if (metadata.remove(host)) { |
| 1900 | 1912 | if (isInitialConnection) { |
| 1901 | - logger.warn("You listed {} in your contact points, but it could not be reached at startup", host); | |
| 1913 | + logger.warn("You listed {} in your contact points, but it wasn't found in the control host's system.peers at startup", host); | |
| 1902 | 1914 | } else { |
| 1903 | 1915 | logger.info("Cassandra host {} removed", host); |
| 1904 | 1916 | triggerOnRemove(host); |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterAssert.java +11 −2
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import java.net.InetSocketAddress; | |
| 18 | 19 | import java.util.Iterator; |
| 19 | 20 | import java.util.Set; |
| 20 | 21 | import java.util.TreeSet; |
| @@ -44,9 +45,17 @@ | ||
| 44 | 45 | public HostAssert host(int hostNumber) { |
| 45 | 46 | // TODO at some point this won't work anymore if we have assertions that wait for a node to |
| 46 | 47 | // join the cluster, e.g. assertThat(cluster).node(3).comesUp(). |
| 47 | - Host host = TestUtils.findHost(actual, hostNumber); | |
| 48 | + return new HostAssert( | |
| 49 | + TestUtils.findHost(actual, hostNumber), | |
| 50 | + actual); | |
| 51 | + } | |
| 48 | 52 | |
| 49 | - return new HostAssert(host, actual); | |
| 53 | + public HostAssert host(String hostAddress) { | |
| 54 | + // TODO at some point this won't work anymore if we have assertions that wait for a node to | |
| 55 | + // join the cluster, e.g. assertThat(cluster).node(3).comesUp(). | |
| 56 | + return new HostAssert( | |
| 57 | + TestUtils.findHost(actual, hostAddress), | |
| 58 | + actual); | |
| 50 | 59 | } |
| 51 | 60 | |
| 52 | 61 | /** |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +98 −68
| @@ -17,28 +17,36 @@ | ||
| 17 | 17 | |
| 18 | 18 | import java.net.InetAddress; |
| 19 | 19 | import java.net.InetSocketAddress; |
| 20 | +import java.net.UnknownHostException; | |
| 20 | 21 | import java.util.Collections; |
| 21 | 22 | import java.util.List; |
| 23 | +import java.util.Map; | |
| 22 | 24 | import java.util.concurrent.TimeUnit; |
| 23 | 25 | import java.util.concurrent.TimeoutException; |
| 24 | 26 | |
| 27 | +import com.google.common.collect.ImmutableMap; | |
| 28 | +import com.google.common.collect.ImmutableSet; | |
| 25 | 29 | import com.google.common.collect.Lists; |
| 30 | +import org.scassandra.Scassandra; | |
| 31 | +import org.scassandra.http.client.PrimingClient; | |
| 32 | +import org.scassandra.http.client.PrimingRequest; | |
| 26 | 33 | import org.slf4j.Logger; |
| 27 | 34 | import org.slf4j.LoggerFactory; |
| 28 | 35 | import org.testng.annotations.Test; |
| 29 | 36 | |
| 30 | -import static org.assertj.core.api.Assertions.fail; | |
| 37 | +import static org.mockito.Mockito.atLeast; | |
| 38 | +import static org.mockito.Mockito.atMost; | |
| 31 | 39 | import static org.mockito.Mockito.spy; |
| 32 | -import static org.mockito.Mockito.times; | |
| 33 | 40 | import static org.mockito.Mockito.verify; |
| 34 | 41 | |
| 35 | 42 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 36 | 43 | import com.datastax.driver.core.policies.ConstantReconnectionPolicy; |
| 37 | -import com.datastax.driver.core.querybuilder.Insert; | |
| 38 | -import com.datastax.driver.core.utils.UUIDs; | |
| 39 | 44 | |
| 45 | +import static com.datastax.driver.core.Assertions.*; | |
| 40 | 46 | import static com.datastax.driver.core.FakeHost.Behavior.THROWING_CONNECT_TIMEOUTS; |
| 41 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 47 | +import static com.datastax.driver.core.Host.State.DOWN; | |
| 48 | +import static com.datastax.driver.core.Host.State.UP; | |
| 49 | +import static com.datastax.driver.core.HostDistance.LOCAL; | |
| 42 | 50 | |
| 43 | 51 | public class ClusterInitTest { |
| 44 | 52 | private static final Logger logger = LoggerFactory.getLogger(ClusterInitTest.class); |
| @@ -47,44 +55,58 @@ | ||
| 47 | 55 | * Test for JAVA-522: when the cluster and session initialize, if some contact points are behaving badly and |
| 48 | 56 | * causing timeouts, we want to ensure that the driver does not wait multiple times on the same host. |
| 49 | 57 | */ |
| 50 | - | |
| 51 | 58 | @Test(groups = "short") |
| 52 | - public void should_wait_for_each_contact_point_at_most_once() { | |
| 53 | - CCMBridge ccm = null; | |
| 59 | + public void should_handle_failing_or_missing_contact_points() throws UnknownHostException { | |
| 54 | 60 | Cluster cluster = null; |
| 55 | - List<FakeHost> fakeHosts = Lists.newArrayList(); | |
| 61 | + Scassandra scassandra = null; | |
| 62 | + List<FakeHost> failingHosts = Lists.newArrayList(); | |
| 56 | 63 | try { |
| 57 | - // Obtaining connect timeouts is not trivial: we create a 6-host cluster but only start one of them, | |
| 58 | - // then simulate the other 5. | |
| 59 | - ccm = CCMBridge.builder("test").withNodes(6).notStarted().build(); | |
| 60 | - ccm.start(1); | |
| 61 | - | |
| 62 | - for (int i = 0; i < 5; i++) { | |
| 63 | - FakeHost fakeHost = new FakeHost(CCMBridge.ipOfNode(i + 2), 9042, THROWING_CONNECT_TIMEOUTS); | |
| 64 | - fakeHosts.add(fakeHost); | |
| 65 | - fakeHost.start(); | |
| 64 | + // Simulate a cluster of 5 hosts. | |
| 65 | + | |
| 66 | + // - 1 is an actual Scassandra instance that will accept connections: | |
| 67 | + scassandra = TestUtils.createScassandraServer(); | |
| 68 | + scassandra.start(); | |
| 69 | + String realHostAddress = "localhost"; | |
| 70 | + int port = scassandra.getBinaryPort(); | |
| 71 | + | |
| 72 | + // - the remaining 4 are fake servers that will throw connect timeouts: | |
| 73 | + for (int i = 2; i <= 5; i++) { | |
| 74 | + FakeHost failingHost = new FakeHost(CCMBridge.ipOfNode(i), port, THROWING_CONNECT_TIMEOUTS); | |
| 75 | + failingHosts.add(failingHost); | |
| 76 | + failingHost.start(); | |
| 66 | 77 | } |
| 67 | 78 | |
| 68 | - // Our real instance has no rows in its system.peers table. That would cause the driver to ignore our fake | |
| 69 | - // hosts when the control connection refreshes the host list. | |
| 70 | - // So we also insert fake rows in system.peers: | |
| 71 | - fakePeerRowsInNode1(); | |
| 79 | + // - we also have a "missing" contact point, i.e. there's no server listening at this address, | |
| 80 | + // and the address is not listed in the live host's system.peers | |
| 81 | + String missingHostAddress = CCMBridge.ipOfNode(6); | |
| 82 | + | |
| 83 | + primePeerRows(scassandra, failingHosts); | |
| 72 | 84 | |
| 73 | 85 | logger.info("Environment is set up, starting test"); |
| 74 | 86 | long start = System.nanoTime(); |
| 75 | 87 | |
| 76 | - // We want to count how many connections were attempted. For that, we rely on the fact that SocketOptions.getKeepAlive is called in Connection.Factory.newBoostrap() | |
| 77 | - // each time we prepare to open a new connection. This is a bit of a hack, but this is what we have. | |
| 88 | + // We want to count how many connections were attempted. For that, we rely on the fact that SocketOptions.getKeepAlive | |
| 89 | + // is called in Connection.Factory.newBoostrap() each time we prepare to open a new connection. | |
| 78 | 90 | SocketOptions socketOptions = spy(new SocketOptions()); |
| 79 | 91 | |
| 80 | - // Set an enormous delay so that reconnection attempts don't pollute our observations | |
| 92 | + // Set an "infinite" reconnection delay so that reconnection attempts don't pollute our observations | |
| 81 | 93 | ConstantReconnectionPolicy reconnectionPolicy = new ConstantReconnectionPolicy(3600 * 1000); |
| 82 | 94 | |
| 83 | - cluster = Cluster.builder().addContactPoints( | |
| 84 | - CCMBridge.ipOfNode(1), CCMBridge.ipOfNode(2), CCMBridge.ipOfNode(3), | |
| 85 | - CCMBridge.ipOfNode(4), CCMBridge.ipOfNode(5), CCMBridge.ipOfNode(6)) | |
| 95 | + // Force 1 connection per pool. Otherwise we can't distinguish a failed pool creation from multiple connection | |
| 96 | + // attempts, because pools create their connections in parallel (so 1 pool failure equals multiple connection failures). | |
| 97 | + PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(LOCAL, 1, 1); | |
| 98 | + | |
| 99 | + cluster = Cluster.builder() | |
| 100 | + .withPort(scassandra.getBinaryPort()) | |
| 101 | + .addContactPoints( | |
| 102 | + realHostAddress, | |
| 103 | + failingHosts.get(0).address, failingHosts.get(1).address, | |
| 104 | + failingHosts.get(2).address, failingHosts.get(3).address, | |
| 105 | + missingHostAddress | |
| 106 | + ) | |
| 86 | 107 | .withSocketOptions(socketOptions) |
| 87 | 108 | .withReconnectionPolicy(reconnectionPolicy) |
| 109 | + .withPoolingOptions(poolingOptions) | |
| 88 | 110 | .withProtocolVersion(TestUtils.getDesiredProtocolVersion()) |
| 89 | 111 | .build(); |
| 90 | 112 | cluster.connect(); |
| @@ -93,72 +115,80 @@ | ||
| 93 | 115 | long initTimeMs = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); |
| 94 | 116 | logger.info("Cluster and session initialized in {} ms", initTimeMs); |
| 95 | 117 | |
| 96 | - // We have one live host so we expect 1 control connection + core connection count successful connections. | |
| 97 | - // The other 5 hosts are unreachable, we should attempt to connect to each of them only once. | |
| 98 | - int coreConnections = cluster.getConfiguration() | |
| 99 | - .getPoolingOptions() | |
| 100 | - .getCoreConnectionsPerHost(HostDistance.LOCAL); | |
| 101 | - verify(socketOptions, times(1 + coreConnections + 5)).getKeepAlive(); | |
| 118 | + // Expect : | |
| 119 | + // - 2 connections for the live host (1 control connection + 1 pooled connection) | |
| 120 | + // - 1 attempt per failing host (either a control connection attempt or a failed pool creation) | |
| 121 | + // - 0 or 1 for the missing host. We can't know for sure because contact points are randomized. If it's tried | |
| 122 | + // before the live host there will be a connection attempt, otherwise it will be removed directly because | |
| 123 | + // it's not in the live host's system.peers. | |
| 124 | + verify(socketOptions, atLeast(6)).getKeepAlive(); | |
| 125 | + verify(socketOptions, atMost(7)).getKeepAlive(); | |
| 126 | + | |
| 127 | + assertThat(cluster).host(realHostAddress).hasState(UP); | |
| 128 | + for (FakeHost failingHost : failingHosts) | |
| 129 | + assertThat(cluster).host(failingHost.address).hasState(DOWN); | |
| 130 | + assertThat(cluster).host(missingHostAddress).isNull(); | |
| 131 | + | |
| 102 | 132 | } finally { |
| 103 | 133 | if (cluster != null) |
| 104 | 134 | cluster.close(); |
| 105 | - for (FakeHost fakeHost : fakeHosts) | |
| 135 | + for (FakeHost fakeHost : failingHosts) | |
| 106 | 136 | fakeHost.stop(); |
| 107 | - if (ccm != null) | |
| 108 | - ccm.remove(); | |
| 137 | + if (scassandra != null) | |
| 138 | + scassandra.stop(); | |
| 109 | 139 | } |
| 110 | 140 | } |
| 111 | 141 | |
| 112 | 142 | /** |
| 113 | - * <p> | |
| 114 | 143 | * Validates that a Cluster that was never able to successfully establish connection a session can be closed |
| 115 | 144 | * properly. |
| 116 | 145 | * |
| 117 | 146 | * @test_category connection |
| 118 | 147 | * @expected_result Cluster closes within 1 second. |
| 119 | 148 | */ |
| 120 | - @Test(groups="unit") | |
| 149 | + @Test(groups = "unit") | |
| 121 | 150 | public void should_be_able_to_close_cluster_that_never_successfully_connected() throws Exception { |
| 122 | 151 | Cluster cluster = Cluster.builder() |
| 123 | - .addContactPointsWithPorts(Collections.singleton(new InetSocketAddress("127.0.0.1", 65534))) | |
| 124 | - .build(); | |
| 152 | + .addContactPointsWithPorts(Collections.singleton(new InetSocketAddress("127.0.0.1", 65534))) | |
| 153 | + .build(); | |
| 125 | 154 | try { |
| 126 | 155 | cluster.connect(); |
| 127 | 156 | fail("Should not have been able to connect."); |
| 128 | - } catch(NoHostAvailableException e) {} // Expected. | |
| 157 | + } catch (NoHostAvailableException e) { | |
| 158 | + } // Expected. | |
| 129 | 159 | CloseFuture closeFuture = cluster.closeAsync(); |
| 130 | 160 | try { |
| 131 | 161 | closeFuture.get(1, TimeUnit.SECONDS); |
| 132 | - } catch(TimeoutException e) { | |
| 162 | + } catch (TimeoutException e) { | |
| 133 | 163 | fail("Close Future did not complete quickly."); |
| 134 | 164 | } |
| 135 | 165 | } |
| 136 | 166 | |
| 137 | - private void fakePeerRowsInNode1() { | |
| 138 | - Cluster cluster = null; | |
| 139 | - try { | |
| 140 | - cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); | |
| 141 | - Session session = cluster.connect("system"); | |
| 142 | - | |
| 143 | - String releaseVersion = session.execute("SELECT release_version FROM local") | |
| 144 | - .one().getString("release_version"); | |
| 145 | - | |
| 146 | - for (int i = 2; i <= 6; i++) { | |
| 147 | - Insert insertStmt = insertInto("peers") | |
| 148 | - .value("peer", InetAddress.getByName(CCMBridge.ipOfNode(i))) | |
| 149 | - .value("data_center", "datacenter1") | |
| 150 | - .value("host_id", UUIDs.random()) | |
| 151 | - .value("rack", "rack1") | |
| 152 | - .value("release_version", releaseVersion) | |
| 153 | - .value("rpc_address", InetAddress.getByName(CCMBridge.ipOfNode(i))) | |
| 154 | - .value("schema_version", UUIDs.random()); | |
| 155 | - session.execute(insertStmt); | |
| 156 | - } | |
| 157 | - } catch (Exception e) { | |
| 158 | - fail("Error while inserting fake peer rows", e); | |
| 159 | - } finally { | |
| 160 | - if (cluster != null) | |
| 161 | - cluster.close(); | |
| 167 | + private void primePeerRows(Scassandra scassandra, List<FakeHost> otherHosts) throws UnknownHostException { | |
| 168 | + PrimingClient primingClient = PrimingClient.builder() | |
| 169 | + .withHost("localhost").withPort(scassandra.getAdminPort()) | |
| 170 | + .build(); | |
| 171 | + | |
| 172 | + List<Map<String, ?>> rows = Lists.newArrayListWithCapacity(5); | |
| 173 | + | |
| 174 | + int i = 0; | |
| 175 | + for (FakeHost otherHost : otherHosts) { | |
| 176 | + InetAddress address = InetAddress.getByName(otherHost.address); | |
| 177 | + rows.add(ImmutableMap.<String, Object>builder() | |
| 178 | + .put("peer", address) | |
| 179 | + .put("rpc_address", address) | |
| 180 | + .put("data_center", "datacenter1") | |
| 181 | + .put("rack", "rack1") | |
| 182 | + .put("release_version", "2.0.1") | |
| 183 | + .put("tokens", ImmutableSet.of(Long.toString(Long.MIN_VALUE + i++))) | |
| 184 | + .build()); | |
| 162 | 185 | } |
| 186 | + | |
| 187 | + primingClient.prime( | |
| 188 | + PrimingRequest.queryBuilder() | |
| 189 | + .withQuery("SELECT * FROM system.peers") | |
| 190 | + .withColumnTypes(SCassandraCluster.SELECT_PEERS_COLUMN_TYPES) | |
| 191 | + .withRows(rows) | |
| 192 | + .build()); | |
| 163 | 193 | } |
| 164 | 194 | } |
modified driver-core/src/test/java/com/datastax/driver/core/FakeHost.java +1 −1
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | public class FakeHost { |
| 32 | 32 | public enum Behavior {THROWING_CONNECT_TIMEOUTS, THROWING_OPERATION_TIMEOUTS} |
| 33 | 33 | |
| 34 | - private final String address; | |
| 34 | + final String address; | |
| 35 | 35 | private final int port; |
| 36 | 36 | private final Behavior behavior; |
| 37 | 37 | private final ExecutorService executor; |
modified driver-core/src/test/java/com/datastax/driver/core/SCassandraCluster.java +1 −1
| @@ -134,7 +134,7 @@ | ||
| 134 | 134 | .build()); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - private static final ImmutableMap<String, ColumnTypes> SELECT_PEERS_COLUMN_TYPES = | |
| 137 | + static final ImmutableMap<String, ColumnTypes> SELECT_PEERS_COLUMN_TYPES = | |
| 138 | 138 | ImmutableMap.<String, ColumnTypes>builder() |
| 139 | 139 | .put("peer", ColumnTypes.Inet) |
| 140 | 140 | .put("rpc_address", ColumnTypes.Inet) |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +9 −7
| @@ -24,8 +24,6 @@ | ||
| 24 | 24 | import java.nio.ByteBuffer; |
| 25 | 25 | import java.util.*; |
| 26 | 26 | |
| 27 | -import static org.testng.Assert.fail; | |
| 28 | - | |
| 29 | 27 | import org.scassandra.Scassandra; |
| 30 | 28 | import org.scassandra.ScassandraFactory; |
| 31 | 29 | import org.slf4j.Logger; |
| @@ -382,15 +380,19 @@ | ||
| 382 | 380 | } |
| 383 | 381 | } |
| 384 | 382 | |
| 385 | - /** Utility method to find the {@code Host} object corresponding to a node in a cluster. */ | |
| 386 | 383 | public static Host findHost(Cluster cluster, int hostNumber) { |
| 387 | - String address = CCMBridge.ipOfNode(hostNumber); | |
| 388 | - for (Host host : cluster.getMetadata().getAllHosts()) { | |
| 384 | + return findHost(cluster, CCMBridge.ipOfNode(hostNumber)); | |
| 385 | + } | |
| 386 | + | |
| 387 | + public static Host findHost(Cluster cluster, String address) { | |
| 388 | + // Note: we can't rely on ProtocolOptions.getPort() to build an InetSocketAddress and call metadata.getHost, | |
| 389 | + // because the port doesn't have the correct value if addContactPointsWithPorts was used to create the Cluster | |
| 390 | + // (JAVA-860 will solve that) | |
| 391 | + for (Host host : cluster.getMetadata().allHosts()) { | |
| 389 | 392 | if (host.getAddress().getHostAddress().equals(address)) |
| 390 | 393 | return host; |
| 391 | 394 | } |
| 392 | - fail(address + " not found in cluster metadata"); | |
| 393 | - return null; // never reached | |
| 395 | + return null; | |
| 394 | 396 | } |
| 395 | 397 | |
| 396 | 398 | public static int numberOfLocalCoreConnections(Cluster cluster) { |