Skip to content

Commit a82fd4e

Browse files
committed
Make TopologyMonitor.NodeInfo top-level
1 parent 630e36a commit a82fd4e

10 files changed

Lines changed: 114 additions & 63 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
public class AddNodeRefresh extends NodesRefresh {
2525

26-
@VisibleForTesting final TopologyMonitor.NodeInfo newNodeInfo;
26+
@VisibleForTesting final NodeInfo newNodeInfo;
2727

28-
public AddNodeRefresh(DefaultMetadata oldMetadata, TopologyMonitor.NodeInfo newNodeInfo) {
28+
AddNodeRefresh(DefaultMetadata oldMetadata, NodeInfo newNodeInfo) {
2929
super(oldMetadata);
3030
this.newNodeInfo = newNodeInfo;
3131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Optional;
2424
import java.util.Set;
2525

26-
public class DefaultNodeInfo implements TopologyMonitor.NodeInfo {
26+
public class DefaultNodeInfo implements NodeInfo {
2727
public static Builder builder() {
2828
return new Builder();
2929
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class FullNodeListRefresh extends NodesRefresh {
3131

3232
private static final Logger LOG = LoggerFactory.getLogger(FullNodeListRefresh.class);
3333

34-
@VisibleForTesting final Iterable<TopologyMonitor.NodeInfo> nodeInfos;
34+
@VisibleForTesting final Iterable<NodeInfo> nodeInfos;
3535

36-
FullNodeListRefresh(DefaultMetadata current, Iterable<TopologyMonitor.NodeInfo> nodeInfos) {
36+
FullNodeListRefresh(DefaultMetadata current, Iterable<NodeInfo> nodeInfos) {
3737
super(current);
3838
this.nodeInfos = nodeInfos;
3939
}
@@ -45,11 +45,10 @@ protected Map<InetSocketAddress, Node> computeNewNodes() {
4545
Map<InetSocketAddress, Node> added = new HashMap<>();
4646
Set<InetSocketAddress> seen = new HashSet<>();
4747

48-
for (TopologyMonitor.NodeInfo nodeInfo : nodeInfos) {
48+
for (NodeInfo nodeInfo : nodeInfos) {
4949
InetSocketAddress address = nodeInfo.getConnectAddress();
5050
if (address == null) {
51-
// TODO more advanced row validation (see 3.x), here or in TopologyMonitor?
52-
LOG.debug("Ignoring node info with missing connect address");
51+
LOG.warn("Got node info with no connect address, ignoring");
5352
continue;
5453
}
5554
seen.add(address);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.datastax.oss.driver.api.core.metadata.Metadata;
1919
import com.datastax.oss.driver.api.core.metadata.Node;
2020
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
21-
import com.datastax.oss.driver.internal.core.metadata.TopologyMonitor.NodeInfo;
2221
import com.datastax.oss.driver.internal.core.util.concurrent.RunOrSchedule;
2322
import com.google.common.annotations.VisibleForTesting;
2423
import io.netty.util.concurrent.EventExecutor;
@@ -143,9 +142,9 @@ private void addNode(InetSocketAddress address, Optional<NodeInfo> maybeInfo) {
143142
// This would be a bug in the TopologyMonitor, protect against it
144143
LOG.warn(
145144
"Received a request to add a node for {}, "
146-
+ "but the provided info uses the address {}, ignoring it",
145+
+ "but the provided info uses the connect address {}, ignoring it",
147146
address,
148-
info.getBroadcastAddress());
147+
info.getConnectAddress());
149148
} else {
150149
refresh(new AddNodeRefresh(metadata, info));
151150
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (C) 2017-2017 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.oss.driver.internal.core.metadata;
17+
18+
import com.datastax.oss.driver.api.core.addresstranslation.AddressTranslator;
19+
import com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy;
20+
import com.datastax.oss.driver.api.core.loadbalancing.NodeDistance;
21+
import com.datastax.oss.driver.api.core.metadata.Node;
22+
import java.net.InetAddress;
23+
import java.net.InetSocketAddress;
24+
import java.util.Map;
25+
import java.util.Optional;
26+
import java.util.Set;
27+
28+
/**
29+
* Information about a node, returned by the {@link TopologyMonitor}.
30+
*
31+
* <p>This information will be copied to the corresponding {@link Node} in the metadata.
32+
*/
33+
public interface NodeInfo {
34+
/**
35+
* The address that the driver uses to connect to the node. This is the node's broadcast RPC
36+
* address, <b>transformed by the {@link AddressTranslator}</b> if one is configured.
37+
*
38+
* <p>The driver uses this to uniquely identify a node.
39+
*
40+
* <p>This must not be null. If this instance is the reponse to a {@link
41+
* TopologyMonitor#refreshNode(Node) refresh node} request, it must also match the address with
42+
* which the request was made, otherwise the new node will be ignored.
43+
*/
44+
InetSocketAddress getConnectAddress();
45+
46+
/**
47+
* The node's broadcast address. That is, the address that other nodes use to communicate with
48+
* that node.
49+
*
50+
* <p>This is only used by the default topology monitor, so if you are writing a custom one and
51+
* don't need this information, you can leave it empty.
52+
*/
53+
Optional<InetAddress> getBroadcastAddress();
54+
55+
/**
56+
* The node's listen address. That is, the address that the Cassandra process binds to.
57+
*
58+
* <p>This is currently not used anywhere in the driver. If you write a custom topology monitor
59+
* and don't need this information, you can leave it empty.
60+
*/
61+
Optional<InetAddress> getListenAddress();
62+
63+
/**
64+
* The data center that this node belongs to, according to the Cassandra snitch.
65+
*
66+
* <p>This is used by some {@link LoadBalancingPolicy} implementations to compute the {@link
67+
* NodeDistance}.
68+
*/
69+
String getDatacenter();
70+
71+
/**
72+
* The rack that this node belongs to, according to the Cassandra snitch.
73+
*
74+
* <p>This is used by some {@link LoadBalancingPolicy} implementations to compute the {@link
75+
* NodeDistance}.
76+
*/
77+
String getRack();
78+
79+
/**
80+
* The Cassandra version that this node runs.
81+
*
82+
* <p>This is used when parsing the schema (schema tables sometimes change from one version to the
83+
* next, even if the protocol version stays the same). If this is null, schema parsing will use
84+
* the lowest version for the current protocol version, which might lead to inaccuracies.
85+
*/
86+
String getCassandraVersion();
87+
88+
/**
89+
* The tokens that this node owns on the ring.
90+
*
91+
* <p>This is used to compute the driver-side token metadata (in particular, token-aware routing
92+
* relies on this information). If you're not using token metadata in any way, you may return an
93+
* empty set here.
94+
*/
95+
Set<String> getTokens();
96+
97+
/**
98+
* An additional map of free-form properties, that can be used by custom implementations. They
99+
* will be copied as-is into {@link Node#getExtras()}.
100+
*/
101+
Map<String, Object> getExtras();
102+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void compute() {
4242
// TODO recompute token map (even if node list hasn't changed, b/c tokens might have changed)
4343
}
4444

45-
protected static void copyInfos(TopologyMonitor.NodeInfo nodeInfo, DefaultNode node) {
45+
protected static void copyInfos(NodeInfo nodeInfo, DefaultNode node) {
4646
node.broadcastAddress = nodeInfo.getBroadcastAddress();
4747
node.listenAddress = nodeInfo.getListenAddress();
4848
node.datacenter = nodeInfo.getDatacenter();

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

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121
import com.datastax.oss.driver.internal.core.context.EventBus;
2222
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
2323
import com.datastax.oss.driver.internal.core.control.ControlConnection;
24-
import java.net.InetAddress;
2524
import java.net.InetSocketAddress;
26-
import java.util.Map;
2725
import java.util.Optional;
28-
import java.util.Set;
2926
import java.util.concurrent.CompletionStage;
3027

3128
/**
@@ -94,48 +91,4 @@ public interface TopologyMonitor {
9491
* always be returned in a single message (no paging).
9592
*/
9693
CompletionStage<Iterable<NodeInfo>> refreshNodeList();
97-
98-
/**
99-
* Information about a node, as it will be returned by the monitor.
100-
*
101-
* <p>This is distinct from what we expose in the public driver metadata.
102-
*/
103-
interface NodeInfo {
104-
/**
105-
* The address that the driver uses to connect to the node. This is the node's broadcast RPC
106-
* address, <b>transformed by the {@link AddressTranslator}</b> if one is configured.
107-
*/
108-
InetSocketAddress getConnectAddress();
109-
110-
/**
111-
* The node's broadcast address. That is, the address that other nodes use to communicate with
112-
* that node.
113-
*
114-
* <p>This is only used by the default topology monitor, so if you are writing a custom one and
115-
* don't need this information, you can leave it empty.
116-
*/
117-
Optional<InetAddress> getBroadcastAddress();
118-
119-
/**
120-
* The node's listen address. That is, the address that the Cassandra process binds to.
121-
*
122-
* <p>This is currently not used anywhere in the driver. If you write a custom topology monitor
123-
* and don't need this information, you can leave it empty.
124-
*/
125-
Optional<InetAddress> getListenAddress();
126-
127-
String getDatacenter();
128-
129-
String getRack();
130-
131-
String getCassandraVersion();
132-
133-
Set<String> getTokens();
134-
135-
/**
136-
* An additional map of free-form properties, that can be used by custom implementations. They
137-
* will be copied as-is into the driver metadata's {@link Node}.
138-
*/
139-
Map<String, Object> getExtras();
140-
}
14194
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.datastax.oss.driver.internal.core.channel.DriverChannel;
2525
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
2626
import com.datastax.oss.driver.internal.core.control.ControlConnection;
27-
import com.datastax.oss.driver.internal.core.metadata.TopologyMonitor.NodeInfo;
2827
import com.google.common.collect.ImmutableMap;
2928
import com.google.common.collect.ImmutableSet;
3029
import com.google.common.collect.Iterators;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void should_add_and_remove_nodes() {
3737
// Given
3838
DefaultMetadata oldMetadata =
3939
new DefaultMetadata(ImmutableMap.of(ADDRESS1, node1, ADDRESS2, node2));
40-
Iterable<TopologyMonitor.NodeInfo> newInfos =
40+
Iterable<NodeInfo> newInfos =
4141
ImmutableList.of(
4242
DefaultNodeInfo.builder().withConnectAddress(ADDRESS2).build(),
4343
DefaultNodeInfo.builder().withConnectAddress(ADDRESS3).build());
@@ -57,7 +57,7 @@ public void should_update_existing_nodes() {
5757
// Given
5858
DefaultMetadata oldMetadata =
5959
new DefaultMetadata(ImmutableMap.of(ADDRESS1, node1, ADDRESS2, node2));
60-
Iterable<TopologyMonitor.NodeInfo> newInfos =
60+
Iterable<NodeInfo> newInfos =
6161
ImmutableList.of(
6262
DefaultNodeInfo.builder()
6363
.withConnectAddress(ADDRESS1)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.datastax.oss.driver.api.core.metadata.Node;
1919
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
2020
import com.datastax.oss.driver.internal.core.context.NettyOptions;
21-
import com.datastax.oss.driver.internal.core.metadata.TopologyMonitor.NodeInfo;
2221
import com.google.common.collect.ImmutableList;
2322
import com.google.common.collect.ImmutableSet;
2423
import com.google.common.util.concurrent.Uninterruptibles;

0 commit comments

Comments
 (0)