Skip to content

Commit bbc972c

Browse files
committed
fix: resolve merge conflicts from apache/cassandra-java-driver 4.19.2
- BasicLoadBalancingPolicy: add missing closing brace for getLocalRack() - DefaultLoadBalancingPolicy: remove unused ThreadLocalRandom import - OptionalLocalDcHelper: add missing LinkedHashSet import; restore correct checkLocalDatacenterCompatibility implementation from upstream - InitialNodeListRefresh: add missing Set import; add contactPoints field and constructor arg; restore upstream compute() logic - InitialNodeListRefreshTest: replace bad merge artifact with upstream 4.19.2 version (contactPoint1/contactPoint2 setup + ImmutableSet args) - CqlRequestHandler: rename logPrefix -> handlerLogPrefix in sendRequest() calls to session.getChannel() - manual/core/README.md: add request_id/* to toctree
1 parent 25c08fe commit bbc972c

17 files changed

Lines changed: 97 additions & 130 deletions

File tree

core/src/main/java/com/datastax/oss/driver/api/core/config/DefaultDriverOption.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ public enum DefaultDriverOption implements DriverOption {
11541154
* }
11551155
* </pre>
11561156
*
1157-
* Note: subnets must be represented as prefix blocks, see {@link
1157+
* Note: subnets must be represented as prefix blocks, see {@code
11581158
* inet.ipaddr.Address#isPrefixBlock()}.
11591159
*
11601160
* <p>Value type: {@link java.util.Map Map}&#60;{@link String},{@link String}&#62;

core/src/main/java/com/datastax/oss/driver/internal/core/cql/CqlPrepareAsyncProcessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ public CompletionStage<PreparedStatement> process(
162162
});
163163
}
164164
}
165+
// If the future is already completed, return it directly to maintain a strong reference
166+
// in the cache and avoid premature GC with weakValues() (ScyllaDB PR #892).
167+
if (result.isDone()) {
168+
return result;
169+
}
165170
// Return a defensive copy. So if a client cancels its request, the cache won't be impacted
166171
// nor a potential concurrent request.
167172
return result.thenApply(x -> x); // copy() is available only since Java 9

core/src/main/java/com/datastax/oss/driver/internal/core/cql/CqlRequestHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ private void sendRequest(
384384
|| (channel =
385385
session.getChannel(
386386
node,
387-
logPrefix,
387+
handlerLogPrefix,
388388
getRoutingToken(statement),
389389
getShardFromTabletMap(statement, node, getRoutingToken(statement))))
390390
== null) {
391391
while (!result.isDone() && (node = queryPlan.poll()) != null) {
392392
channel =
393393
session.getChannel(
394394
node,
395-
logPrefix,
395+
handlerLogPrefix,
396396
getRoutingToken(statement),
397397
getShardFromTabletMap(statement, node, getRoutingToken(statement)));
398398
if (channel != null) {
@@ -672,7 +672,7 @@ private NodeResponseCallback(
672672
this.execution = execution;
673673
this.retryCount = retryCount;
674674
this.scheduleNextExecution = scheduleNextExecution;
675-
this.logPrefix = logPrefix + "|" + execution;
675+
this.logPrefix = logPrefix;
676676
}
677677

678678
// this gets invoked once the write completes.

core/src/main/java/com/datastax/oss/driver/internal/core/loadbalancing/BasicLoadBalancingPolicy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ public BasicLoadBalancingPolicy(@NonNull DriverContext context, @NonNull String
174174
private RequestRoutingMethod parseLwtRequestRoutingMethod() {
175175
String methodString =
176176
profile.getString(DefaultDriverOption.LOAD_BALANCING_DEFAULT_LWT_REQUEST_ROUTING_METHOD);
177+
if (methodString == null) {
178+
return RequestRoutingMethod.PRESERVE_REPLICA_ORDER;
179+
}
177180
try {
178181
return RequestRoutingMethod.valueOf(methodString.toUpperCase());
179182
} catch (IllegalArgumentException e) {
@@ -240,6 +243,7 @@ public String getLocalDatacenter() {
240243
@Nullable
241244
protected String getLocalRack() {
242245
return localRack;
246+
}
243247

244248
@NonNull
245249
@Override

core/src/main/java/com/datastax/oss/driver/internal/core/loadbalancing/DefaultLoadBalancingPolicy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import java.util.UUID;
4949
import java.util.concurrent.ConcurrentHashMap;
5050
import java.util.concurrent.ConcurrentMap;
51-
import java.util.concurrent.ThreadLocalRandom;
5251
import java.util.concurrent.atomic.AtomicLongArray;
5352
import net.jcip.annotations.ThreadSafe;
5453
import org.slf4j.Logger;

core/src/main/java/com/datastax/oss/driver/internal/core/loadbalancing/helper/OptionalLocalDcHelper.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import edu.umd.cs.findbugs.annotations.NonNull;
2727
import java.util.ArrayList;
2828
import java.util.HashSet;
29+
import java.util.LinkedHashSet;
2930
import java.util.List;
3031
import java.util.Map;
3132
import java.util.Objects;
@@ -71,6 +72,24 @@ public Optional<String> discoverLocalDc(@NonNull Map<UUID, Node> nodes) {
7172
if (localDc.isPresent()) {
7273
checkLocalDatacenterCompatibility(
7374
localDc.get(), context.getMetadataManager().getContactPoints());
75+
// Also warn if the configured DC doesn't match any node in the cluster
76+
if (!nodes.isEmpty()) {
77+
boolean found = false;
78+
for (Node node : nodes.values()) {
79+
if (localDc.get().equals(node.getDatacenter())) {
80+
found = true;
81+
break;
82+
}
83+
}
84+
if (!found) {
85+
LOG.warn(
86+
"[{}] Configured local DC '{}' does not match any node's datacenter"
87+
+ " (available DCs: {}); please verify your configuration",
88+
logPrefix,
89+
localDc.get(),
90+
formatDcs(nodes.values()));
91+
}
92+
}
7493
} else {
7594
LOG.debug("[{}] Local DC not set, DC awareness will be disabled", logPrefix);
7695
}
@@ -96,16 +115,15 @@ protected void checkLocalDatacenterCompatibility(
96115
badContactPoints.add(node);
97116
}
98117
}
99-
if (!found) {
118+
if (!badContactPoints.isEmpty()) {
100119
LOG.warn(
101-
"[{}] Configured local DC '{}' does not match any node's datacenter"
102-
+ " (available DCs: {}); please verify your configuration",
120+
"[{}] You specified {} as the local DC, but some contact points are from a different DC: {}; "
121+
+ "please provide the correct local DC, or check your contact points",
103122
logPrefix,
104123
localDc,
105-
formatDcs(nodes.values()));
124+
formatNodesAndDcs(badContactPoints));
106125
}
107126
}
108-
return Optional.of(localDc);
109127
}
110128

111129
/**

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/InitialNodeListRefresh.java

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@
1717
*/
1818
package com.datastax.oss.driver.internal.core.metadata;
1919

20-
import com.datastax.oss.driver.api.core.metadata.EndPoint;
20+
import com.datastax.oss.driver.api.core.metadata.Node;
2121
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
2222
import com.datastax.oss.driver.internal.core.metadata.token.TokenFactory;
2323
import com.datastax.oss.driver.internal.core.metadata.token.TokenFactoryRegistry;
2424
import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting;
2525
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList;
2626
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
27-
import java.util.ArrayList;
2827
import java.util.HashMap;
29-
import java.util.HashSet;
30-
import java.util.List;
3128
import java.util.Map;
3229
import java.util.UUID;
3330
import net.jcip.annotations.ThreadSafe;
@@ -65,10 +62,7 @@ public Result compute(
6562
}
6663

6764
Map<UUID, DefaultNode> newNodes = new HashMap<>();
68-
// Contact point nodes don't have host ID as well as other info yet, so we fill them with node
69-
// info found on first match by endpoint
70-
Set<EndPoint> matchedContactPoints = new HashSet<>();
71-
List<DefaultNode> addedNodes = new ArrayList<>();
65+
ImmutableList.Builder<Object> eventsBuilder = ImmutableList.builder();
7266

7367
for (NodeInfo nodeInfo : nodeInfos) {
7468
UUID hostId = nodeInfo.getHostId();
@@ -80,17 +74,15 @@ public Result compute(
8074
hostId,
8175
newNodes.get(hostId));
8276
} else {
83-
EndPoint endPoint = nodeInfo.getEndPoint();
84-
DefaultNode contactPointNode = findContactPointNode(endPoint);
8577
DefaultNode node;
86-
if (contactPointNode == null || matchedContactPoints.contains(endPoint)) {
87-
node = new DefaultNode(endPoint, context);
88-
addedNodes.add(node);
89-
LOG.debug("[{}] Adding new node {}", logPrefix, node);
78+
DefaultNode existing = existingByHostId.get(hostId);
79+
if (existing != null) {
80+
node = existing;
81+
LOG.debug("[{}] Reusing existing node {}", logPrefix, node);
9082
} else {
91-
matchedContactPoints.add(contactPointNode.getEndPoint());
92-
node = contactPointNode;
93-
LOG.debug("[{}] Copying contact point {}", logPrefix, node);
83+
node = new DefaultNode(nodeInfo.getEndPoint(), context);
84+
LOG.debug("[{}] Adding new node {}", logPrefix, node);
85+
eventsBuilder.add(NodeStateEvent.added(node));
9486
}
9587
if (tokenMapEnabled && tokenFactory == null && nodeInfo.getPartitioner() != null) {
9688
tokenFactory = tokenFactoryRegistry.tokenFactoryFor(nodeInfo.getPartitioner());
@@ -100,13 +92,13 @@ public Result compute(
10092
}
10193
}
10294

103-
ImmutableList.Builder<Object> eventsBuilder = ImmutableList.builder();
104-
for (DefaultNode addedNode : addedNodes) {
105-
eventsBuilder.add(NodeStateEvent.added(addedNode));
106-
}
107-
for (DefaultNode contactPoint : contactPoints) {
108-
if (!matchedContactPoints.contains(contactPoint.getEndPoint())) {
109-
eventsBuilder.add(NodeStateEvent.removed(contactPoint));
95+
for (Map.Entry<UUID, DefaultNode> entry : existingByHostId.entrySet()) {
96+
if (!newNodes.containsKey(entry.getKey())) {
97+
LOG.warn(
98+
"[{}] Pre-registered node {} was not found in the node list refresh",
99+
logPrefix,
100+
entry.getValue());
101+
eventsBuilder.add(NodeStateEvent.removed(entry.getValue()));
110102
}
111103
}
112104

@@ -115,13 +107,4 @@ public Result compute(
115107
ImmutableMap.copyOf(newNodes), tokenMapEnabled, true, tokenFactory, context),
116108
eventsBuilder.build());
117109
}
118-
119-
private DefaultNode findContactPointNode(EndPoint endPoint) {
120-
for (DefaultNode node : contactPoints) {
121-
if (node.getEndPoint().equals(endPoint)) {
122-
return node;
123-
}
124-
}
125-
return null;
126-
}
127110
}

core/src/test/java/com/datastax/oss/driver/internal/core/context/MockedDriverContextFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public static DriverExecutionProfile createProfile(String name, String localDc)
119119
.thenReturn("DefaultMetricsFactory");
120120
when(defaultProfile.getString(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER))
121121
.thenReturn(localDc);
122+
when(defaultProfile.getString(
123+
DefaultDriverOption.LOAD_BALANCING_DEFAULT_LWT_REQUEST_ROUTING_METHOD))
124+
.thenReturn("PRESERVE_REPLICA_ORDER");
122125
return defaultProfile;
123126
}
124127

core/src/test/java/com/datastax/oss/driver/internal/core/metadata/InitialNodeListRefreshTest.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void setup() {
6969
}
7070

7171
@Test
72-
public void should_copy_contact_points_on_first_endpoint_match_only() {
72+
public void should_create_new_nodes_for_all_endpoints() {
7373
// Given
7474
Iterable<NodeInfo> newInfos =
7575
ImmutableList.of(
@@ -81,16 +81,6 @@ public void should_copy_contact_points_on_first_endpoint_match_only() {
8181
.withEndPoint(endPoint2)
8282
.withHostId(hostId4)
8383
.build(),
84-
DefaultNodeInfo.builder()
85-
.withEndPoint(contactPoint2.getEndPoint())
86-
.withHostId(hostId2)
87-
.build(),
88-
DefaultNodeInfo.builder().withEndPoint(endPoint3).withHostId(hostId3).build(),
89-
DefaultNodeInfo.builder()
90-
// address translator can translate node addresses to the same endpoints
91-
.withEndPoint(contactPoint2.getEndPoint())
92-
.withHostId(hostId4)
93-
.build(),
9484
DefaultNodeInfo.builder()
9585
// address translator can translate node addresses to the same endpoints
9686
.withEndPoint(endPoint3)
@@ -104,22 +94,20 @@ public void should_copy_contact_points_on_first_endpoint_match_only() {
10494
// Then
10595
Map<UUID, Node> newNodes = result.newMetadata.getNodes();
10696
assertThat(newNodes).containsOnlyKeys(hostId1, hostId2, hostId3, hostId4, hostId5);
107-
assertThat(newNodes.get(hostId1)).isEqualTo(contactPoint1);
108-
assertThat(contactPoint1.getHostId()).isEqualTo(hostId1);
109-
assertThat(newNodes.get(hostId2)).isEqualTo(contactPoint2);
110-
assertThat(contactPoint2.getHostId()).isEqualTo(hostId2);
111-
// And
112-
// node has been added for the new endpoint
97+
assertThat(newNodes.get(hostId1).getEndPoint()).isEqualTo(endPoint1);
98+
assertThat(newNodes.get(hostId1).getHostId()).isEqualTo(hostId1);
99+
assertThat(newNodes.get(hostId2).getEndPoint()).isEqualTo(endPoint2);
100+
assertThat(newNodes.get(hostId2).getHostId()).isEqualTo(hostId2);
113101
assertThat(newNodes.get(hostId3).getEndPoint()).isEqualTo(endPoint3);
114102
assertThat(newNodes.get(hostId3).getHostId()).isEqualTo(hostId3);
115-
// And
116-
// nodes have been added for duplicated endpoints
117-
assertThat(newNodes.get(hostId4).getEndPoint()).isEqualTo(contactPoint2.getEndPoint());
103+
assertThat(newNodes.get(hostId4).getEndPoint()).isEqualTo(endPoint2);
118104
assertThat(newNodes.get(hostId4).getHostId()).isEqualTo(hostId4);
119105
assertThat(newNodes.get(hostId5).getEndPoint()).isEqualTo(endPoint3);
120106
assertThat(newNodes.get(hostId5).getHostId()).isEqualTo(hostId5);
121107
assertThat(result.events)
122108
.containsExactlyInAnyOrder(
109+
NodeStateEvent.added((DefaultNode) newNodes.get(hostId1)),
110+
NodeStateEvent.added((DefaultNode) newNodes.get(hostId2)),
123111
NodeStateEvent.added((DefaultNode) newNodes.get(hostId3)),
124112
NodeStateEvent.added((DefaultNode) newNodes.get(hostId4)),
125113
NodeStateEvent.added((DefaultNode) newNodes.get(hostId5)));

integration-tests/src/test/java/com/datastax/oss/driver/core/tracker/RequestIdGeneratorIT.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,32 @@
2929
import com.datastax.oss.driver.api.core.session.Request;
3030
import com.datastax.oss.driver.api.core.tracker.RequestIdGenerator;
3131
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
32+
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
33+
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
3234
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
3335
import com.datastax.oss.driver.categories.ParallelizableTests;
3436
import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap;
3537
import edu.umd.cs.findbugs.annotations.NonNull;
3638
import java.nio.ByteBuffer;
3739
import java.nio.charset.StandardCharsets;
3840
import java.util.Map;
39-
import org.junit.Rule;
41+
import org.junit.ClassRule;
4042
import org.junit.Test;
4143
import org.junit.experimental.categories.Category;
4244
import org.junit.rules.RuleChain;
4345
import org.junit.rules.TestRule;
4446

47+
// Scylla does not support custom payload (RequestIdGenerator writes request IDs into the custom
48+
// payload); Scylla returns a truncated-frame protocol error when custom payload entries are
49+
// present.
50+
@BackendRequirement(
51+
type = BackendType.CASSANDRA,
52+
description = "Custom payload (request ID) not supported on Scylla")
4553
@Category(ParallelizableTests.class)
4654
public class RequestIdGeneratorIT {
47-
private CcmRule ccmRule = CcmRule.getInstance();
55+
private static CcmRule ccmRule = CcmRule.getInstance();
4856

49-
@Rule public TestRule chain = RuleChain.outerRule(ccmRule);
57+
@ClassRule public static TestRule chain = RuleChain.outerRule(ccmRule);
5058

5159
@Test
5260
public void should_write_uuid_to_custom_payload_with_key() {

0 commit comments

Comments
 (0)