kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | d2bae80385ee0e408a0338a3b85b28784d9b085fb93b1e0f7b00d54dd5ac5702 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-03-10 20:59 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-04-01 17:57 +02:00 |
| Parents | ab0e361a4951 |
7 files changed
modified changelog/README.md +1 −0
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | - [bug] JAVA-1070: The Mapper should not prepare queries synchronously. |
| 19 | 19 | - [new feature] JAVA-982: Introduce new method ConsistencyLevel.isSerial(). |
| 20 | 20 | - [bug] JAVA-764: Retry with the normal consistency level (not the serial one) when a write times out on the Paxos phase. |
| 21 | +- [improvement] JAVA-852: Ignore peers with null entries during discovery. | |
| 21 | 22 | |
| 22 | 23 | |
| 23 | 24 | ### 3.0.0 |
modified driver-core/pom.xml +30 −25
| @@ -15,7 +15,8 @@ | ||
| 15 | 15 | limitations under the License. |
| 16 | 16 | |
| 17 | 17 | --> |
| 18 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 19 | 20 | <modelVersion>4.0.0</modelVersion> |
| 20 | 21 | <parent> |
| 21 | 22 | <groupId>com.datastax.cassandra</groupId> |
| @@ -225,7 +226,8 @@ | ||
| 225 | 226 | </relocation> |
| 226 | 227 | </relocations> |
| 227 | 228 | <transformers> |
| 228 | - <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> | |
| 229 | + <transformer | |
| 230 | + implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> | |
| 229 | 231 | <resources> |
| 230 | 232 | <resource>META-INF/MANIFEST.MF</resource> |
| 231 | 233 | <resource>META-INF/io.netty.versions.properties</resource> |
| @@ -242,7 +244,8 @@ | ||
| 242 | 244 | </resources> |
| 243 | 245 | </transformer> |
| 244 | 246 | <!-- Pick up the alternate manifest that was generated by the alternate execution of the bundle plugin --> |
| 245 | - <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> | |
| 247 | + <transformer | |
| 248 | + implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> | |
| 246 | 249 | <resource>META-INF/MANIFEST.MF</resource> |
| 247 | 250 | <file>${project.build.directory}/META-INF-shaded/MANIFEST.MF</file> |
| 248 | 251 | </transformer> |
| @@ -273,7 +276,7 @@ | ||
| 273 | 276 | </goals> |
| 274 | 277 | </pluginExecutionFilter> |
| 275 | 278 | <action> |
| 276 | - <ignore /> | |
| 279 | + <ignore/> | |
| 277 | 280 | </action> |
| 278 | 281 | </pluginExecution> |
| 279 | 282 | </pluginExecutions> |
| @@ -358,27 +361,29 @@ | ||
| 358 | 361 | </build> |
| 359 | 362 | </profile> |
| 360 | 363 | |
| 361 | - <profile> | |
| 362 | - <id>isolated</id> | |
| 363 | - <properties> | |
| 364 | - <env>default</env> | |
| 365 | - </properties> | |
| 366 | - <build> | |
| 367 | - <plugins> | |
| 368 | - <plugin> | |
| 369 | - <groupId>org.apache.maven.plugins</groupId> | |
| 370 | - <artifactId>maven-surefire-plugin</artifactId> | |
| 371 | - <version>2.16</version> | |
| 372 | - <configuration> | |
| 373 | - <skip>false</skip> | |
| 374 | - <includes> | |
| 375 | - <include>**/SSL*Test.java</include> | |
| 376 | - </includes> | |
| 377 | - </configuration> | |
| 378 | - </plugin> | |
| 379 | - </plugins> | |
| 380 | - </build> | |
| 381 | - </profile> | |
| 364 | + <profile> | |
| 365 | + <id>isolated</id> | |
| 366 | + <properties> | |
| 367 | + <env>default</env> | |
| 368 | + </properties> | |
| 369 | + <build> | |
| 370 | + <plugins> | |
| 371 | + <plugin> | |
| 372 | + <groupId>org.apache.maven.plugins</groupId> | |
| 373 | + <artifactId>maven-surefire-plugin</artifactId> | |
| 374 | + <version>2.16</version> | |
| 375 | + <configuration> | |
| 376 | + <skip>false</skip> | |
| 377 | + <includes> | |
| 378 | + <include>**/SSL*Test.java</include> | |
| 379 | + <include>**/ControlConnectionTest.java</include> | |
| 380 | + <include>**/ExtendedPeerCheckDisabledTest.java</include> | |
| 381 | + </includes> | |
| 382 | + </configuration> | |
| 383 | + </plugin> | |
| 384 | + </plugins> | |
| 385 | + </build> | |
| 386 | + </profile> | |
| 382 | 387 | |
| 383 | 388 | <profile> |
| 384 | 389 | <id>long</id> |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +53 −14
| @@ -36,6 +36,8 @@ | ||
| 36 | 36 | |
| 37 | 37 | private static final Logger logger = LoggerFactory.getLogger(ControlConnection.class); |
| 38 | 38 | |
| 39 | + private static final boolean EXTENDED_PEER_CHECK = SystemProperties.getBoolean("com.datastax.driver.EXTENDED_PEER_CHECK", true); | |
| 40 | + | |
| 39 | 41 | private static final InetAddress bindAllAddress; |
| 40 | 42 | |
| 41 | 43 | static { |
| @@ -273,7 +275,7 @@ | ||
| 273 | 275 | // We need to refresh the node list again; |
| 274 | 276 | // We want that because the token map was not properly initialized by the first call above, |
| 275 | 277 | // since it requires the list of keyspaces to be loaded. |
| 276 | - refreshNodeListAndTokenMap(connection, cluster, false, true); | |
| 278 | + refreshNodeListAndTokenMap(connection, cluster, false, false); | |
| 277 | 279 | |
| 278 | 280 | return connection; |
| 279 | 281 | } catch (BusyConnectionException e) { |
| @@ -368,7 +370,7 @@ | ||
| 368 | 370 | } |
| 369 | 371 | } |
| 370 | 372 | |
| 371 | - private static InetSocketAddress rpcAddressForPeerHost(Row peersRow, InetSocketAddress connectedHost, Cluster.Manager cluster, boolean logMissingRpcAddresses) { | |
| 373 | + private static InetSocketAddress rpcAddressForPeerHost(Row peersRow, InetSocketAddress connectedHost, Cluster.Manager cluster) { | |
| 372 | 374 | |
| 373 | 375 | // after CASSANDRA-9436, system.peers contains the following inet columns: |
| 374 | 376 | // - peer: this is actually broadcast_address |
| @@ -379,15 +381,13 @@ | ||
| 379 | 381 | InetAddress broadcastAddress = peersRow.getInet("peer"); |
| 380 | 382 | InetAddress rpcAddress = peersRow.getInet("rpc_address"); |
| 381 | 383 | |
| 382 | - if (broadcastAddress.equals(connectedHost.getAddress()) || (rpcAddress != null && rpcAddress.equals(connectedHost.getAddress()))) { | |
| 384 | + if (broadcastAddress == null) { | |
| 385 | + return null; | |
| 386 | + } else if (broadcastAddress.equals(connectedHost.getAddress()) || rpcAddress.equals(connectedHost.getAddress())) { | |
| 383 | 387 | // Some DSE versions were inserting a line for the local node in peers (with mostly null values). This has been fixed, but if we |
| 384 | 388 | // detect that's the case, ignore it as it's not really a big deal. |
| 385 | 389 | logger.debug("System.peers on node {} has a line for itself. This is not normal but is a known problem of some DSE version. Ignoring the entry.", connectedHost); |
| 386 | 390 | return null; |
| 387 | - } else if (rpcAddress == null) { | |
| 388 | - if (logMissingRpcAddresses) | |
| 389 | - logger.warn("No rpc_address found for host {} in {}'s peers system table. {} will be ignored.", broadcastAddress, connectedHost, broadcastAddress); | |
| 390 | - return null; | |
| 391 | 391 | } else if (rpcAddress.equals(bindAllAddress)) { |
| 392 | 392 | logger.warn("Found host with 0.0.0.0 as rpc_address, using broadcast_address ({}) to contact it instead. If this is incorrect you should avoid the use of 0.0.0.0 server side.", broadcastAddress); |
| 393 | 393 | rpcAddress = broadcastAddress; |
| @@ -409,7 +409,7 @@ | ||
| 409 | 409 | DefaultResultSetFuture future = new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_PEERS)); |
| 410 | 410 | c.write(future); |
| 411 | 411 | for (Row row : future.get()) { |
| 412 | - InetSocketAddress addr = rpcAddressForPeerHost(row, c.address, cluster, true); | |
| 412 | + InetSocketAddress addr = rpcAddressForPeerHost(row, c.address, cluster); | |
| 413 | 413 | if (addr != null && addr.equals(host.getSocketAddress())) |
| 414 | 414 | return row; |
| 415 | 415 | } |
| @@ -442,8 +442,7 @@ | ||
| 442 | 442 | // Ignore hosts with a null rpc_address, as this is most likely a phantom row in system.peers (JAVA-428). |
| 443 | 443 | // Don't test this for the control host since we're already connected to it anyway, and we read the info from system.local |
| 444 | 444 | // which didn't have an rpc_address column (JAVA-546) until CASSANDRA-9436 |
| 445 | - } else if (!c.address.equals(host.getSocketAddress()) && row.getInet("rpc_address") == null) { | |
| 446 | - logger.warn("No rpc_address found for host {} in {}'s peers system table. {} will be ignored.", host.getAddress(), c.address, host.getAddress()); | |
| 445 | + } else if (!c.address.equals(host.getSocketAddress()) && !isValidPeer(row, true)) { | |
| 447 | 446 | return false; |
| 448 | 447 | } |
| 449 | 448 | |
| @@ -527,7 +526,7 @@ | ||
| 527 | 526 | cluster.loadBalancingPolicy().onAdd(host); |
| 528 | 527 | } |
| 529 | 528 | |
| 530 | - private static void refreshNodeListAndTokenMap(Connection connection, Cluster.Manager cluster, boolean isInitialConnection, boolean logMissingRpcAddresses) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { | |
| 529 | + private static void refreshNodeListAndTokenMap(Connection connection, Cluster.Manager cluster, boolean isInitialConnection, boolean logInvalidPeers) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { | |
| 531 | 530 | logger.debug("[Control connection] Refreshing node list and token map"); |
| 532 | 531 | |
| 533 | 532 | boolean metadataEnabled = cluster.configuration.getQueryOptions().isMetadataEnabled(); |
| @@ -579,10 +578,10 @@ | ||
| 579 | 578 | List<String> dseWorkloads = new ArrayList<String>(); |
| 580 | 579 | |
| 581 | 580 | for (Row row : peersFuture.get()) { |
| 582 | - InetSocketAddress rpcAddress = rpcAddressForPeerHost(row, connection.address, cluster, logMissingRpcAddresses); | |
| 583 | - if (rpcAddress == null) | |
| 581 | + if (!isValidPeer(row, logInvalidPeers)) | |
| 584 | 582 | continue; |
| 585 | 583 | |
| 584 | + InetSocketAddress rpcAddress = rpcAddressForPeerHost(row, connection.address, cluster); | |
| 586 | 585 | foundHosts.add(rpcAddress); |
| 587 | 586 | dcs.add(row.getString("data_center")); |
| 588 | 587 | racks.add(row.getString("rack")); |
| @@ -645,6 +644,46 @@ | ||
| 645 | 644 | cluster.metadata.rebuildTokenMap(partitioner, tokenMap); |
| 646 | 645 | } |
| 647 | 646 | |
| 647 | + private static boolean isValidPeer(Row peerRow, boolean logIfInvalid) { | |
| 648 | + boolean isValid = peerRow.getColumnDefinitions().contains("rpc_address") | |
| 649 | + && !peerRow.isNull("rpc_address"); | |
| 650 | + if (EXTENDED_PEER_CHECK) { | |
| 651 | + isValid &= peerRow.getColumnDefinitions().contains("host_id") | |
| 652 | + && !peerRow.isNull("host_id") | |
| 653 | + && peerRow.getColumnDefinitions().contains("data_center") | |
| 654 | + && !peerRow.isNull("data_center") | |
| 655 | + && peerRow.getColumnDefinitions().contains("rack") | |
| 656 | + && !peerRow.isNull("rack") | |
| 657 | + && peerRow.getColumnDefinitions().contains("tokens") | |
| 658 | + && !peerRow.isNull("tokens"); | |
| 659 | + } | |
| 660 | + if (!isValid && logIfInvalid) | |
| 661 | + logger.warn("Found invalid row in system.peers: {}. " + | |
| 662 | + "This is likely a gossip or snitch issue, this host will be ignored.", formatInvalidPeer(peerRow)); | |
| 663 | + return isValid; | |
| 664 | + } | |
| 665 | + | |
| 666 | + // Custom formatting to avoid spamming the logs if 'tokens' is present and contains a gazillion tokens | |
| 667 | + private static String formatInvalidPeer(Row peerRow) { | |
| 668 | + StringBuilder sb = new StringBuilder("[peer=" + peerRow.getInet("peer")); | |
| 669 | + formatMissingOrNullColumn(peerRow, "rpc_address", sb); | |
| 670 | + if (EXTENDED_PEER_CHECK) { | |
| 671 | + formatMissingOrNullColumn(peerRow, "host_id", sb); | |
| 672 | + formatMissingOrNullColumn(peerRow, "data_center", sb); | |
| 673 | + formatMissingOrNullColumn(peerRow, "rack", sb); | |
| 674 | + formatMissingOrNullColumn(peerRow, "tokens", sb); | |
| 675 | + } | |
| 676 | + sb.append("]"); | |
| 677 | + return sb.toString(); | |
| 678 | + } | |
| 679 | + | |
| 680 | + private static void formatMissingOrNullColumn(Row peerRow, String columnName, StringBuilder sb) { | |
| 681 | + if (!peerRow.getColumnDefinitions().contains(columnName)) | |
| 682 | + sb.append(", missing ").append(columnName); | |
| 683 | + else if (peerRow.isNull(columnName)) | |
| 684 | + sb.append(", ").append(columnName).append("=null"); | |
| 685 | + } | |
| 686 | + | |
| 648 | 687 | boolean waitForSchemaAgreement() throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { |
| 649 | 688 | long start = System.nanoTime(); |
| 650 | 689 | long elapsed = 0; |
| @@ -681,7 +720,7 @@ | ||
| 681 | 720 | |
| 682 | 721 | for (Row row : peersFuture.get()) { |
| 683 | 722 | |
| 684 | - InetSocketAddress addr = rpcAddressForPeerHost(row, connection.address, cluster, true); | |
| 723 | + InetSocketAddress addr = rpcAddressForPeerHost(row, connection.address, cluster); | |
| 685 | 724 | if (addr == null || row.isNull("schema_version")) |
| 686 | 725 | continue; |
| 687 | 726 |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +3 −2
| @@ -34,6 +34,7 @@ | ||
| 34 | 34 | import java.net.UnknownHostException; |
| 35 | 35 | import java.util.List; |
| 36 | 36 | import java.util.Map; |
| 37 | +import java.util.UUID; | |
| 37 | 38 | import java.util.concurrent.TimeUnit; |
| 38 | 39 | import java.util.concurrent.TimeoutException; |
| 39 | 40 | |
| @@ -139,8 +140,7 @@ | ||
| 139 | 140 | } |
| 140 | 141 | assertThat(cluster).host(failingHost.address).isReconnectingFromDown(); |
| 141 | 142 | } |
| 142 | - assertThat(cluster).host(missingHostAddress).isNull(); | |
| 143 | - | |
| 143 | + assertThat(TestUtils.findHost(cluster, missingHostAddress)).isNull(); | |
| 144 | 144 | } finally { |
| 145 | 145 | if (cluster != null) |
| 146 | 146 | cluster.close(); |
| @@ -276,6 +276,7 @@ | ||
| 276 | 276 | .put("rack", "rack1") |
| 277 | 277 | .put("release_version", "2.0.1") |
| 278 | 278 | .put("tokens", ImmutableSet.of(Long.toString(Long.MIN_VALUE + i++))) |
| 279 | + .put("host_id", UUID.randomUUID()) | |
| 279 | 280 | .build()); |
| 280 | 281 | } |
| 281 | 282 |
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +108 −0
| @@ -20,8 +20,10 @@ | ||
| 20 | 20 | import com.google.common.base.Function; |
| 21 | 21 | import com.google.common.collect.HashMultiset; |
| 22 | 22 | import com.google.common.collect.Maps; |
| 23 | +import org.apache.log4j.Level; | |
| 23 | 24 | import org.slf4j.Logger; |
| 24 | 25 | import org.slf4j.LoggerFactory; |
| 26 | +import org.testng.annotations.DataProvider; | |
| 25 | 27 | import org.testng.annotations.Test; |
| 26 | 28 | |
| 27 | 29 | import java.net.InetAddress; |
| @@ -199,7 +201,113 @@ | ||
| 199 | 201 | } finally { |
| 200 | 202 | scassandras.stop(); |
| 201 | 203 | } |
| 204 | + } | |
| 205 | + | |
| 206 | + @DataProvider | |
| 207 | + public static Object[][] disallowedNullColumnsInPeerData() { | |
| 208 | + return new Object[][]{ | |
| 209 | + {"host_id"}, | |
| 210 | + {"data_center"}, | |
| 211 | + {"rack"}, | |
| 212 | + {"tokens"}, | |
| 213 | + {"host_id,data_center,rack,tokens"} | |
| 214 | + }; | |
| 215 | + } | |
| 216 | + | |
| 217 | + /** | |
| 218 | + * Validates that if the com.datastax.driver.EXTENDED_PEER_CHECK system property is set to true that a peer | |
| 219 | + * with null values for host_id, data_center, rack, or tokens is ignored. | |
| 220 | + * | |
| 221 | + * @test_category host:metadata | |
| 222 | + * @jira_ticket JAVA-852 | |
| 223 | + * @since 2.1.10 | |
| 224 | + */ | |
| 225 | + @Test(groups = "isolated", dataProvider = "disallowedNullColumnsInPeerData") | |
| 226 | + @CCMConfig(createCcm = false) | |
| 227 | + public void should_ignore_peer_if_extended_peer_check_is_enabled(String columns) { | |
| 228 | + System.setProperty("com.datastax.driver.EXTENDED_PEER_CHECK", "true"); | |
| 229 | + run_with_null_peer_info(columns, false); | |
| 230 | + } | |
| 231 | + | |
| 232 | + /** | |
| 233 | + * Validates that a peer with null values for host_id, data_center, rack, or tokens is ignored. | |
| 234 | + * | |
| 235 | + * @test_category host:metadata | |
| 236 | + * @jira_ticket JAVA-852 | |
| 237 | + * @since 2.1.10 | |
| 238 | + */ | |
| 239 | + @Test(groups = "short", dataProvider = "disallowedNullColumnsInPeerData") | |
| 240 | + @CCMConfig(createCcm = false) | |
| 241 | + public void should_ignore_and_warn_peers_with_null_entries_by_default(String columns) { | |
| 242 | + run_with_null_peer_info(columns, false); | |
| 243 | + } | |
| 244 | + | |
| 245 | + static void run_with_null_peer_info(String columns, boolean expectPeer2) { | |
| 246 | + // given: A cluster with peer 2 having a null rack. | |
| 247 | + ScassandraCluster.ScassandraClusterBuilder builder = ScassandraCluster.builder() | |
| 248 | + .withNodes(3); | |
| 249 | + | |
| 250 | + StringBuilder columnDataBuilder = new StringBuilder(); | |
| 251 | + for (String column : columns.split(",")) { | |
| 252 | + builder = builder.forcePeerInfo(1, 2, column, null); | |
| 253 | + columnDataBuilder.append(String.format("%s=null, ", column)); | |
| 254 | + } | |
| 255 | + | |
| 256 | + String columnData = columnDataBuilder.toString(); | |
| 257 | + if (columnData.endsWith(", ")) { | |
| 258 | + columnData = columnData.substring(0, columnData.length() - 2); | |
| 259 | + } | |
| 260 | + | |
| 261 | + ScassandraCluster scassandraCluster = builder.build(); | |
| 262 | + | |
| 263 | + Cluster cluster = Cluster.builder() | |
| 264 | + .addContactPoints(scassandraCluster.address(1).getAddress()) | |
| 265 | + .withPort(scassandraCluster.getBinaryPort()) | |
| 266 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 267 | + .build(); | |
| 268 | + | |
| 269 | + // Capture logs to ensure appropriate warnings are logged. | |
| 270 | + org.apache.log4j.Logger cLogger = org.apache.log4j.Logger.getLogger("com.datastax.driver.core"); | |
| 271 | + Level originalLevel = cLogger.getLevel(); | |
| 272 | + if (originalLevel != null && !originalLevel.isGreaterOrEqual(Level.WARN)) { | |
| 273 | + cLogger.setLevel(Level.WARN); | |
| 274 | + } | |
| 275 | + MemoryAppender logs = new MemoryAppender(); | |
| 276 | + cLogger.addAppender(logs); | |
| 202 | 277 | |
| 278 | + try { | |
| 279 | + scassandraCluster.init(); | |
| 280 | + | |
| 281 | + // when: Initializing a cluster instance and grabbing metadata. | |
| 282 | + cluster.init(); | |
| 283 | + | |
| 284 | + InetAddress node2Address = scassandraCluster.address(2).getAddress(); | |
| 285 | + String expectedError = String.format("Found invalid row in system.peers: [peer=%s, %s]. " + | |
| 286 | + "This is likely a gossip or snitch issue, this host will be ignored.", node2Address, columnData); | |
| 287 | + String log = logs.get(); | |
| 288 | + // then: A peer with a null rack should not show up in host metadata, unless allowed via system property. | |
| 289 | + if (expectPeer2) { | |
| 290 | + assertThat(cluster.getMetadata().getAllHosts()) | |
| 291 | + .hasSize(3) | |
| 292 | + .extractingResultOf("getAddress") | |
| 293 | + .contains(node2Address); | |
| 294 | + | |
| 295 | + assertThat(log).doesNotContain(expectedError); | |
| 296 | + } else { | |
| 297 | + assertThat(cluster.getMetadata().getAllHosts()) | |
| 298 | + .hasSize(2) | |
| 299 | + .extractingResultOf("getAddress") | |
| 300 | + .doesNotContain(node2Address); | |
| 301 | + | |
| 302 | + assertThat(log) | |
| 303 | + .containsOnlyOnce(expectedError); | |
| 304 | + } | |
| 305 | + } finally { | |
| 306 | + cLogger.removeAppender(logs); | |
| 307 | + cLogger.setLevel(originalLevel); | |
| 308 | + cluster.close(); | |
| 309 | + scassandraCluster.stop(); | |
| 310 | + } | |
| 203 | 311 | } |
| 204 | 312 | |
| 205 | 313 | static class QueryPlanCountingPolicy extends DelegatingLoadBalancingPolicy { |
added driver-core/src/test/java/com/datastax/driver/core/ExtendedPeerCheckDisabledTest.java +36 −0
| @@ -0,0 +1,36 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core; | |
| 17 | + | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 20 | +public class ExtendedPeerCheckDisabledTest { | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * Validates that if the com.datastax.driver.EXTENDED_PEER_CHECK system property is set to false that a peer | |
| 24 | + * with null values for host_id, data_center, rack, tokens is not ignored. | |
| 25 | + * | |
| 26 | + * @test_category host:metadata | |
| 27 | + * @jira_ticket JAVA-852 | |
| 28 | + * @since 2.1.10 | |
| 29 | + */ | |
| 30 | + @Test(groups = "isolated", dataProvider = "disallowedNullColumnsInPeerData", dataProviderClass = ControlConnectionTest.class) | |
| 31 | + @CCMConfig(createCcm = false) | |
| 32 | + public void should_use_peer_if_extended_peer_check_is_disabled(String columns) { | |
| 33 | + System.setProperty("com.datastax.driver.EXTENDED_PEER_CHECK", "false"); | |
| 34 | + ControlConnectionTest.run_with_null_peer_info(columns, true); | |
| 35 | + } | |
| 36 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +52 −41
| @@ -15,11 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.beust.jcommander.internal.Lists; | |
| 19 | -import com.beust.jcommander.internal.Maps; | |
| 20 | -import com.google.common.collect.ImmutableList; | |
| 21 | -import com.google.common.collect.ImmutableMap; | |
| 22 | -import com.google.common.collect.ImmutableSet; | |
| 18 | +import com.datastax.driver.core.utils.UUIDs; | |
| 19 | +import com.google.common.collect.*; | |
| 23 | 20 | import org.scassandra.Scassandra; |
| 24 | 21 | import org.scassandra.ScassandraFactory; |
| 25 | 22 | import org.scassandra.http.client.PrimingClient; |
| @@ -55,6 +52,8 @@ | ||
| 55 | 52 | |
| 56 | 53 | private final List<Map<String, ?>> keyspaceRows; |
| 57 | 54 | |
| 55 | + private static final java.util.UUID schemaVersion = UUIDs.random(); | |
| 56 | + | |
| 58 | 57 | |
| 59 | 58 | private final Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos; |
| 60 | 59 | |
| @@ -263,7 +262,7 @@ | ||
| 263 | 262 | // Offset DCs by dc * 100 to ensure unique tokens. |
| 264 | 263 | int offset = (dc - 1) * 100; |
| 265 | 264 | int dcNodeCount = nodes(dc).size(); |
| 266 | - List<Long> tokens = Lists.newArrayList(dcNodeCount); | |
| 265 | + List<Long> tokens = Lists.newArrayListWithExpectedSize(dcNodeCount); | |
| 267 | 266 | for (int i = 0; i < dcNodeCount; i++) { |
| 268 | 267 | tokens.add((i * ((long) Math.pow(2, 64) / dcNodeCount) + offset)); |
| 269 | 268 | } |
| @@ -287,42 +286,43 @@ | ||
| 287 | 286 | if (node == peer) { // prime system.local. |
| 288 | 287 | metadata = SELECT_LOCAL; |
| 289 | 288 | query = "SELECT * FROM system.local WHERE key='local'"; |
| 290 | - ImmutableMap.Builder<String, Object> rowBuilder = ImmutableMap.<String, Object>builder() | |
| 291 | - .put("key", "local") | |
| 292 | - .put("bootstrapped", "COMPLETED") | |
| 293 | - .put("broadcast_address", address) | |
| 294 | - .put("cluster_name", "scassandra") | |
| 295 | - .put("cql_version", "3.2.0") | |
| 296 | - .put("data_center", datacenter(dc)) | |
| 297 | - .put("listen_address", getPeerInfo(dc, n + 1, "listen_address", address)) | |
| 298 | - .put("partitioner", "org.apache.cassandra.dht.Murmur3Partitioner") | |
| 299 | - .put("rack", "rack1") | |
| 300 | - .put("release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8")) | |
| 301 | - .put("tokens", ImmutableSet.of(tokens.get(n))); | |
| 289 | + | |
| 290 | + row = Maps.newHashMap(); | |
| 291 | + addPeerInfo(row, dc, n + 1, "key", "local"); | |
| 292 | + addPeerInfo(row, dc, n + 1, "bootstrapped", "COMPLETED"); | |
| 293 | + addPeerInfo(row, dc, n + 1, "broadcast_address", address); | |
| 294 | + addPeerInfo(row, dc, n + 1, "cluster_name", "scassandra"); | |
| 295 | + addPeerInfo(row, dc, n + 1, "cql_version", "3.2.0"); | |
| 296 | + addPeerInfo(row, dc, n + 1, "data_center", datacenter(dc)); | |
| 297 | + addPeerInfo(row, dc, n + 1, "listen_address", getPeerInfo(dc, n + 1, "listen_address", address)); | |
| 298 | + addPeerInfo(row, dc, n + 1, "partitioner", "org.apache.cassandra.dht.Murmur3Partitioner"); | |
| 299 | + addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1")); | |
| 300 | + addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8")); | |
| 301 | + addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n))); | |
| 302 | + addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion); | |
| 302 | 303 | |
| 303 | 304 | // These columns might not always be present, we don't have to specify them in the scassandra |
| 304 | 305 | // column metadata as it will default them to text columns. |
| 305 | - rowBuilder = addInfoIfExists(rowBuilder, dc, n + 1, "dse_version"); | |
| 306 | - rowBuilder = addInfoIfExists(rowBuilder, dc, n + 1, "workload"); | |
| 307 | - | |
| 308 | - row = rowBuilder.build(); | |
| 306 | + addPeerInfoIfExists(row, dc, n + 1, "dse_version"); | |
| 307 | + addPeerInfoIfExists(row, dc, n + 1, "workload"); | |
| 309 | 308 | } else { // prime system.peers. |
| 310 | 309 | query = "SELECT * FROM system.peers WHERE peer='" + address + "'"; |
| 311 | 310 | metadata = SELECT_PEERS; |
| 312 | - ImmutableMap.Builder<String, Object> rowBuilder = ImmutableMap.<String, Object>builder() | |
| 313 | - .put("peer", address) | |
| 314 | - .put("rpc_address", address) | |
| 315 | - .put("data_center", datacenter(dc)) | |
| 316 | - .put("rack", "rack1") | |
| 317 | - .put("release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8")) | |
| 318 | - .put("tokens", ImmutableSet.of(Long.toString(tokens.get(n)))); | |
| 319 | - | |
| 320 | - rowBuilder = addInfoIfExists(rowBuilder, dc, n + 1, "listen_address"); | |
| 321 | - rowBuilder = addInfoIfExists(rowBuilder, dc, n + 1, "dse_version"); | |
| 322 | - rowBuilder = addInfoIfExists(rowBuilder, dc, n + 1, "workload"); | |
| 323 | - | |
| 324 | - row = rowBuilder.build(); | |
| 325 | - rows.add(rowBuilder.build()); | |
| 311 | + row = Maps.newHashMap(); | |
| 312 | + addPeerInfo(row, dc, n + 1, "peer", address); | |
| 313 | + addPeerInfo(row, dc, n + 1, "rpc_address", address); | |
| 314 | + addPeerInfo(row, dc, n + 1, "data_center", datacenter(dc)); | |
| 315 | + addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1")); | |
| 316 | + addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8")); | |
| 317 | + addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n)))); | |
| 318 | + addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random()); | |
| 319 | + addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion); | |
| 320 | + | |
| 321 | + addPeerInfoIfExists(row, dc, n + 1, "listen_address"); | |
| 322 | + addPeerInfoIfExists(row, dc, n + 1, "dse_version"); | |
| 323 | + addPeerInfoIfExists(row, dc, n + 1, "workload"); | |
| 324 | + | |
| 325 | + rows.add(row); | |
| 326 | 326 | } |
| 327 | 327 | client.prime(PrimingRequest.queryBuilder() |
| 328 | 328 | .withQuery(query) |
| @@ -364,16 +364,24 @@ | ||
| 364 | 364 | .build()); |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - private ImmutableMap.Builder<String, Object> addInfoIfExists(ImmutableMap.Builder<String, Object> builder, int dc, int node, String property) { | |
| 367 | + private void addPeerInfo(Map<String, Object> input, int dc, int node, String property, Object defaultValue) { | |
| 368 | + Object peerInfo = getPeerInfo(dc, node, property, defaultValue); | |
| 369 | + if (peerInfo != null) { | |
| 370 | + input.put(property, peerInfo); | |
| 371 | + } | |
| 372 | + } | |
| 373 | + | |
| 374 | + private void addPeerInfoIfExists(Map<String, Object> input, int dc, int node, String property) { | |
| 368 | 375 | Map<Integer, Map<String, Object>> forDc = forcedPeerInfos.get(dc); |
| 369 | 376 | if (forDc == null) |
| 370 | - return builder; | |
| 377 | + return; | |
| 371 | 378 | |
| 372 | 379 | Map<String, Object> forNode = forDc.get(node); |
| 373 | 380 | if (forNode == null) |
| 374 | - return builder; | |
| 381 | + return; | |
| 375 | 382 | |
| 376 | - return (forNode.containsKey(property)) ? builder.put(property, forNode.get(property)) : builder; | |
| 383 | + if (forNode.containsKey(property)) | |
| 384 | + input.put(property, forNode.get(property)); | |
| 377 | 385 | } |
| 378 | 386 | |
| 379 | 387 | private Object getPeerInfo(int dc, int node, String property, Object defaultValue) { |
| @@ -397,7 +405,9 @@ | ||
| 397 | 405 | column("rack", TEXT), |
| 398 | 406 | column("release_version", TEXT), |
| 399 | 407 | column("tokens", set(TEXT)), |
| 400 | - column("listen_address", INET) | |
| 408 | + column("listen_address", INET), | |
| 409 | + column("host_id", UUID), | |
| 410 | + column("schema_version", UUID) | |
| 401 | 411 | }; |
| 402 | 412 | |
| 403 | 413 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_LOCAL = { |
| @@ -412,6 +422,7 @@ | ||
| 412 | 422 | column("rack", TEXT), |
| 413 | 423 | column("release_version", TEXT), |
| 414 | 424 | column("tokens", set(TEXT)), |
| 425 | + column("schema_version", UUID) | |
| 415 | 426 | }; |
| 416 | 427 | |
| 417 | 428 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_CLUSTER_NAME = { |