Skip to content

Commit 02ede69

Browse files
committed
Merge pull request apache#621 from datastax/java852-fix
Fix checkSchemaAgreement bug introduced in JAVA-852
2 parents fab60c9 + 499ce9d commit 02ede69

File tree

5 files changed

+49
-24
lines changed

5 files changed

+49
-24
lines changed

driver-core/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@
381381
<include>**/SSL*Test.java</include>
382382
<include>**/UUIDsPID*.java</include>
383383
<include>**/ControlConnectionTest.java</include>
384+
<include>**/ExtendedPeerCheckDisabledTest.java</include>
384385
</includes>
385386
</configuration>
386387
</plugin>

driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,9 @@ private static InetSocketAddress addressToUseForPeerHost(Row peersRow, InetSocke
427427
InetAddress peer = peersRow.getInet("peer");
428428
InetAddress addr = peersRow.getInet("rpc_address");
429429

430-
// We've already called isValid on the row, which checks this
431-
assert addr != null;
432-
433-
if (peer.equals(connectedHost.getAddress()) || addr.equals(connectedHost.getAddress())) {
430+
if (addr == null) {
431+
return null;
432+
} else if (peer.equals(connectedHost.getAddress()) || addr.equals(connectedHost.getAddress())) {
434433
// Some DSE versions were inserting a line for the local node in peers (with mostly null values). This has been fixed, but if we
435434
// detect that's the case, ignore it as it's not really a big deal.
436435
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);
@@ -733,9 +732,6 @@ boolean checkSchemaAgreement() throws ConnectionException, BusyConnectionExcepti
733732

734733
for (Row row : peersFuture.get()) {
735734

736-
if (!isValidPeer(row, false))
737-
continue;
738-
739735
InetSocketAddress addr = addressToUseForPeerHost(row, connection.address, cluster);
740736
if (addr == null || row.isNull("schema_version"))
741737
continue;

driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public Integer apply(InetAddress input) {
225225
}
226226

227227
@DataProvider
228-
public Object[][] disallowedNullColumnsInPeerData() {
228+
public static Object[][] disallowedNullColumnsInPeerData() {
229229
return new Object[][]{
230230
{"host_id"},
231231
{"data_center"},
@@ -325,20 +325,6 @@ public void should_fetch_whole_peers_table_if_broadcast_address_changed() throws
325325
}
326326
}
327327

328-
/**
329-
* Validates that if the com.datastax.driver.EXTENDED_PEER_CHECK system property is set to false that a peer
330-
* with null values for host_id, data_center, rack, tokens is not ignored.
331-
*
332-
* @test_category host:metadata
333-
* @jira_ticket JAVA-852
334-
* @since 2.1.10
335-
*/
336-
@Test(groups = "isolated", dataProvider = "disallowedNullColumnsInPeerData")
337-
@CCMConfig(createCcm = false)
338-
public void should_use_peer_if_extended_peer_check_is_disabled(String columns) {
339-
System.setProperty("com.datastax.driver.EXTENDED_PEER_CHECK", "false");
340-
run_with_null_peer_info(columns, true);
341-
}
342328

343329
/**
344330
* Validates that if the com.datastax.driver.EXTENDED_PEER_CHECK system property is set to true that a peer
@@ -368,7 +354,7 @@ public void should_ignore_and_warn_peers_with_null_entries_by_default(String col
368354
run_with_null_peer_info(columns, false);
369355
}
370356

371-
private void run_with_null_peer_info(String columns, boolean expectPeer2) {
357+
static void run_with_null_peer_info(String columns, boolean expectPeer2) {
372358
// given: A cluster with peer 2 having a null rack.
373359
ScassandraCluster.ScassandraClusterBuilder builder = ScassandraCluster.builder()
374360
.withNodes(3);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class ScassandraCluster {
5252

5353
private final List<Map<String, ?>> keyspaceRows;
5454

55+
private static final java.util.UUID schemaVersion = UUIDs.random();
56+
5557

5658
private final Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos;
5759

@@ -297,6 +299,7 @@ private void primeMetadata(Scassandra node) {
297299
addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1"));
298300
addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8"));
299301
addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n)));
302+
addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
300303
} else { // prime system.peers.
301304
query = "SELECT * FROM system.peers WHERE peer='" + address + "'";
302305
metadata = SELECT_PEERS;
@@ -308,6 +311,7 @@ private void primeMetadata(Scassandra node) {
308311
addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8"));
309312
addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n))));
310313
addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random());
314+
addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
311315
rows.add(row);
312316
}
313317
client.prime(PrimingRequest.queryBuilder()
@@ -379,7 +383,8 @@ private Object getPeerInfo(int dc, int node, String property, Object defaultValu
379383
column("rack", TEXT),
380384
column("release_version", TEXT),
381385
column("tokens", set(TEXT)),
382-
column("host_id", UUID)
386+
column("host_id", UUID),
387+
column("schema_version", UUID)
383388
};
384389

385390
public static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_LOCAL = {
@@ -394,6 +399,7 @@ private Object getPeerInfo(int dc, int node, String property, Object defaultValu
394399
column("rack", TEXT),
395400
column("release_version", TEXT),
396401
column("tokens", set(TEXT)),
402+
column("schema_version", UUID)
397403
};
398404

399405
static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_CLUSTER_NAME = {

0 commit comments

Comments
 (0)