kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | afbf07e123a03155f7f909160bf3ed335a108189538f2a9be06d6bfb81d663e0 |
|---|---|
| Author | wy96f <wy96fyw@gmail.com> · 2015-12-05 16:44 +08:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-06-16 19:44 -07:00 |
| Parents | 5a43c6822d54 |
4 files changed
modified changelog/README.md +52 −0
| @@ -1,5 +1,57 @@ | ||
| 1 | 1 | ## Changelog |
| 2 | 2 | |
| 3 | +### 3.1.0 (in progress) | |
| 4 | + | |
| 5 | +Merged from 3.0.x branch: | |
| 6 | + | |
| 7 | +- [bug] JAVA-1179: Request objects should be copied when executed. | |
| 8 | +- [improvement] JAVA-1182: Throw error when synchronous call made on I/O thread. | |
| 9 | +- [bug] JAVA-1184: Unwrap StatementWrappers when extracting column definitions. | |
| 10 | +- [bug] JAVA-1132: Executing bound statement with no variables results in exception with protocol v1. | |
| 11 | +- [improvement] JAVA-1040: SimpleStatement parameters support in QueryLogger. | |
| 12 | +- [improvement] JAVA-1151: Fail fast if HdrHistogram is not in the classpath. | |
| 13 | +- [improvement] JAVA-1154: Allow individual Statement to cancel the read timeout. | |
| 14 | +- [bug] JAVA-1074: Fix documentation around default timestamp generator. | |
| 15 | +- [improvement] JAVA-1109: Document SSLOptions changes in upgrade guide. | |
| 16 | +- [improvement] JAVA-1065: Add method to create token from partition key values. | |
| 17 | +- [improvement] JAVA-1136: Enable JDK signature check in module driver-extras. | |
| 18 | +- [improvement] JAVA-866: Support tuple notation in QueryBuilder.eq/in. | |
| 19 | +- [bug] JAVA-1140: Use same connection to check for schema agreement after a DDL query. | |
| 20 | +- [improvement] JAVA-1113: Support Cassandra 3.4 LIKE operator in QueryBuilder. | |
| 21 | +- [improvement] JAVA-1086: Support Cassandra 3.2 CAST function in QueryBuilder. | |
| 22 | +- [bug] JAVA-1095: Check protocol version for custom payload before sending the query. | |
| 23 | +- [improvement] JAVA-1133: Add OSGi headers to cassandra-driver-extras. | |
| 24 | +- [bug] JAVA-1137: Incorrect string returned by DataType.asFunctionParameterString() for collections and tuples. | |
| 25 | +- [bug] JAVA-1046: (Dynamic)CompositeTypes need to be parsed as string literal, not blob. | |
| 26 | +- [improvement] JAVA-1164: Clarify documentation on Host.listenAddress and broadcastAddress. | |
| 27 | +- [improvement] JAVA-1171: Add Host method to determine if DSE Graph is enabled. | |
| 28 | +- [improvement] JAVA-1069: Bootstrap driver-examples module. | |
| 29 | +- [documentation] JAVA-1150: Add example and FAQ entry about ByteBuffer/BLOB. | |
| 30 | +- [improvement] JAVA-1011: Expose PoolingOptions default values. | |
| 31 | +- [improvement] JAVA-630: Don't process DOWN events for nodes that have active connections. | |
| 32 | +- [improvement] JAVA-851: Improve UUIDs javadoc with regard to user-provided timestamps. | |
| 33 | +- [improvement] JAVA-979: Update javadoc for RegularStatement toString() and getQueryString() to indicate that consistency level and other parameters are not maintained in the query string. | |
| 34 | +- [bug] JAVA-1068: Unwrap StatementWrappers when hashing the paging state. | |
| 35 | +- [improvement] JAVA-1021: Improve error message when connect() is called with an invalid keyspace name. | |
| 36 | +- [improvement] JAVA-879: Mapper.map() accepts mapper-generated and user queries. | |
| 37 | +- [bug] JAVA-1100: Exception when connecting with shaded java driver in OSGI | |
| 38 | +- [bug] JAVA-1064: getTable create statement doesn't properly handle quotes in primary key. | |
| 39 | +- [bug] JAVA-1089: Set LWT made from BuiltStatements to non-idempotent. | |
| 40 | +- [improvement] JAVA-923: Position idempotent flag on object mapper queries. | |
| 41 | +- [bug] JAVA-1070: The Mapper should not prepare queries synchronously. | |
| 42 | +- [new feature] JAVA-982: Introduce new method ConsistencyLevel.isSerial(). | |
| 43 | +- [bug] JAVA-764: Retry with the normal consistency level (not the serial one) when a write times out on the Paxos phase. | |
| 44 | +- [improvement] JAVA-852: Ignore peers with null entries during discovery. | |
| 45 | +- [bug] JAVA-1005: DowngradingConsistencyRetryPolicy does not work with EACH_QUORUM when 1 DC is down. | |
| 46 | +- [bug] JAVA-1002: Avoid deadlock when re-preparing a statement on other hosts. | |
| 47 | +- [bug] JAVA-1072: Ensure defunct connections are properly evicted from the pool. | |
| 48 | +- [bug] JAVA-1152: Fix NPE at ControlConnection.refreshNodeListAndTokenMap(). | |
| 49 | + | |
| 50 | +Merged from 2.1 branch: | |
| 51 | + | |
| 52 | +- [improvement] JAVA-1038: Fetch node info by rpc_address if its broadcast_address is not in system.peers. | |
| 53 | + | |
| 54 | + | |
| 3 | 55 | ### 3.0.2 |
| 4 | 56 | |
| 5 | 57 | Merged from 2.1 branch: |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +8 −1
| @@ -402,7 +402,14 @@ | ||
| 402 | 402 | ? new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_LOCAL)) |
| 403 | 403 | : new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_PEERS + " WHERE peer='" + host.getBroadcastAddress().getHostAddress() + '\'')); |
| 404 | 404 | c.write(future); |
| 405 | - return future.get().one(); | |
| 405 | + Row row = future.get().one(); | |
| 406 | + if (row != null) { | |
| 407 | + return row; | |
| 408 | + } else { | |
| 409 | + logger.debug("Could not find peer with broadcast address {}, " + | |
| 410 | + "falling back to a full system.peers scan to fetch info for {} " + | |
| 411 | + "(this can happen if the broadcast address changed)", host.getBroadcastAddress(), host); | |
| 412 | + } | |
| 406 | 413 | } |
| 407 | 414 | |
| 408 | 415 | // We have to fetch the whole peers table and find the host we're looking for |
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +99 −0
| @@ -19,8 +19,11 @@ | ||
| 19 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 20 | 20 | import com.google.common.base.Function; |
| 21 | 21 | import com.google.common.collect.HashMultiset; |
| 22 | +import com.google.common.collect.ImmutableMap; | |
| 23 | +import com.google.common.collect.ImmutableSet; | |
| 22 | 24 | import com.google.common.collect.Maps; |
| 23 | 25 | import org.apache.log4j.Level; |
| 26 | +import org.scassandra.http.client.PrimingRequest; | |
| 24 | 27 | import org.slf4j.Logger; |
| 25 | 28 | import org.slf4j.LoggerFactory; |
| 26 | 29 | import org.testng.annotations.DataProvider; |
| @@ -28,17 +31,22 @@ | ||
| 28 | 31 | |
| 29 | 32 | import java.net.InetAddress; |
| 30 | 33 | import java.net.InetSocketAddress; |
| 34 | +import java.net.UnknownHostException; | |
| 31 | 35 | import java.util.Collection; |
| 32 | 36 | import java.util.Iterator; |
| 33 | 37 | import java.util.Map; |
| 38 | +import java.util.UUID; | |
| 34 | 39 | import java.util.concurrent.TimeUnit; |
| 35 | 40 | import java.util.concurrent.atomic.AtomicInteger; |
| 36 | 41 | |
| 37 | 42 | import static com.datastax.driver.core.Assertions.assertThat; |
| 38 | 43 | import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; |
| 44 | +import static com.datastax.driver.core.ScassandraCluster.SELECT_PEERS; | |
| 45 | +import static com.datastax.driver.core.ScassandraCluster.datacenter; | |
| 39 | 46 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 40 | 47 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 41 | 48 | import static com.google.common.collect.Lists.newArrayList; |
| 49 | +import static org.scassandra.http.client.PrimingRequest.then; | |
| 42 | 50 | |
| 43 | 51 | @CreateCCM(PER_METHOD) |
| 44 | 52 | @CCMConfig(dirtiesContext = true, createCluster = false) |
| @@ -310,6 +318,97 @@ | ||
| 310 | 318 | } |
| 311 | 319 | } |
| 312 | 320 | |
| 321 | + /** | |
| 322 | + * Ensures that when a node changes its broadcast address (for example, after | |
| 323 | + * a shutdown and startup on EC2 and its public IP has changed), | |
| 324 | + * the driver will be able to detect that change and recognize the host | |
| 325 | + * in the system.peers table in spite of that change. | |
| 326 | + * | |
| 327 | + * @jira_ticket JAVA-1038 | |
| 328 | + * @expected_result The driver should be able to detect that a host has changed its broadcast address | |
| 329 | + * and update its metadata accordingly. | |
| 330 | + * @test_category control_connection | |
| 331 | + * @since 2.1.10 | |
| 332 | + */ | |
| 333 | + @SuppressWarnings("unchecked") | |
| 334 | + @Test(groups = "short") | |
| 335 | + @CCMConfig(createCcm = false) | |
| 336 | + public void should_fetch_whole_peers_table_if_broadcast_address_changed() throws UnknownHostException { | |
| 337 | + ScassandraCluster scassandras = ScassandraCluster.builder().withNodes(2).build(); | |
| 338 | + scassandras.init(); | |
| 339 | + | |
| 340 | + InetSocketAddress node2RpcAddress = scassandras.address(2); | |
| 341 | + | |
| 342 | + Cluster cluster = Cluster.builder() | |
| 343 | + .addContactPoints(scassandras.address(1).getAddress()) | |
| 344 | + .withPort(scassandras.getBinaryPort()) | |
| 345 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 346 | + .build(); | |
| 347 | + | |
| 348 | + try { | |
| 349 | + | |
| 350 | + cluster.init(); | |
| 351 | + | |
| 352 | + Host host2 = cluster.getMetadata().getHost(node2RpcAddress); | |
| 353 | + assertThat(host2).isNotNull(); | |
| 354 | + | |
| 355 | + InetAddress node2OldBroadcastAddress = host2.getBroadcastAddress(); | |
| 356 | + InetAddress node2NewBroadcastAddress = InetAddress.getByName("1.2.3.4"); | |
| 357 | + | |
| 358 | + // host 2 has the old broadcast_address (which is identical to its rpc_broadcast_address) | |
| 359 | + assertThat(host2.getAddress()) | |
| 360 | + .isEqualTo(node2OldBroadcastAddress); | |
| 361 | + | |
| 362 | + // simulate a change in host 2 public IP | |
| 363 | + Map<String, ?> rows = ImmutableMap.<String, Object>builder() | |
| 364 | + .put("peer", node2NewBroadcastAddress) // new broadcast address for host 2 | |
| 365 | + .put("rpc_address", host2.getAddress()) // rpc_broadcast_address remains unchanged | |
| 366 | + .put("host_id", UUID.randomUUID()) | |
| 367 | + .put("data_center", datacenter(1)) | |
| 368 | + .put("rack", "rack1") | |
| 369 | + .put("release_version", "2.1.8") | |
| 370 | + .put("tokens", ImmutableSet.of(Long.toString(scassandras.getTokensForDC(1).get(1)))) | |
| 371 | + .build(); | |
| 372 | + | |
| 373 | + scassandras.node(1).primingClient().clearAllPrimes(); | |
| 374 | + | |
| 375 | + // the driver will attempt to locate host2 in system.peers by its old broadcast address, and that will fail | |
| 376 | + scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 377 | + .withQuery("SELECT * FROM system.peers WHERE peer='" + node2OldBroadcastAddress + "'") | |
| 378 | + .withThen(then() | |
| 379 | + .withColumnTypes(SELECT_PEERS) | |
| 380 | + .build()) | |
| 381 | + .build()); | |
| 382 | + | |
| 383 | + // the driver will then attempt to fetch the whole system.peers | |
| 384 | + scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 385 | + .withQuery("SELECT * FROM system.peers") | |
| 386 | + .withThen(then() | |
| 387 | + .withColumnTypes(SELECT_PEERS) | |
| 388 | + .withRows(rows) | |
| 389 | + .build()) | |
| 390 | + .build()); | |
| 391 | + | |
| 392 | + assertThat(cluster.manager.controlConnection.refreshNodeInfo(host2)).isTrue(); | |
| 393 | + | |
| 394 | + host2 = cluster.getMetadata().getHost(node2RpcAddress); | |
| 395 | + | |
| 396 | + // host2 should now have a new broadcast address | |
| 397 | + assertThat(host2).isNotNull(); | |
| 398 | + assertThat(host2.getBroadcastAddress()) | |
| 399 | + .isEqualTo(node2NewBroadcastAddress); | |
| 400 | + | |
| 401 | + // host 2 should keep its old rpc broadcast address | |
| 402 | + assertThat(host2.getSocketAddress()) | |
| 403 | + .isEqualTo(node2RpcAddress); | |
| 404 | + | |
| 405 | + } finally { | |
| 406 | + cluster.close(); | |
| 407 | + scassandras.stop(); | |
| 408 | + } | |
| 409 | + | |
| 410 | + } | |
| 411 | + | |
| 313 | 412 | static class QueryPlanCountingPolicy extends DelegatingLoadBalancingPolicy { |
| 314 | 413 | |
| 315 | 414 | final AtomicInteger counter = new AtomicInteger(); |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +3 −3
| @@ -258,7 +258,7 @@ | ||
| 258 | 258 | start(cluster, ipSuffix(dc, node)); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - private List<Long> getTokensForDC(int dc) { | |
| 261 | + public List<Long> getTokensForDC(int dc) { | |
| 262 | 262 | // Offset DCs by dc * 100 to ensure unique tokens. |
| 263 | 263 | int offset = (dc - 1) * 100; |
| 264 | 264 | int dcNodeCount = nodes(dc).size(); |
| @@ -400,7 +400,7 @@ | ||
| 400 | 400 | : defaultValue; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_PEERS = { | |
| 403 | + public static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_PEERS = { | |
| 404 | 404 | column("peer", INET), |
| 405 | 405 | column("rpc_address", INET), |
| 406 | 406 | column("data_center", TEXT), |
| @@ -413,7 +413,7 @@ | ||
| 413 | 413 | column("schema_version", UUID) |
| 414 | 414 | }; |
| 415 | 415 | |
| 416 | - static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_LOCAL = { | |
| 416 | + public static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_LOCAL = { | |
| 417 | 417 | column("key", TEXT), |
| 418 | 418 | column("bootstrapped", TEXT), |
| 419 | 419 | column("broadcast_address", INET), |