Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JAVA-2165: Abstract node connection information
Motivation: Until now, the only information used to connect to a node was its socket address (host+port). Internally, the driver also used this address as a unique node identifier (it was the key in the Metadata.nodes map). However, there are more complex deployment scenarios where the address might not be sufficient: for example, if nodes are accessed through a proxy that uses SNI routing, the connection information becomes host+port+sni_server_name, and the host+port part is no longer unique. We need to support those alternative connection methods, and use a different unique node identifier. Modifications: - Introduce EndPoint as an abstract wrapper around connection information. EndPoint.resolve() returns the socket address that will be used to open connections, but an endpoint may also contain additional pieces of information that will be used in other places (for example a custom SslHandlerFactory). - Add Node.getEndPoint(), and modify DefaultTopologyMonitor to fill it. Allow contact points to be specified as EndPoints (preserving legacy methods). - Replace InetSocketAddress by EndPoint everywhere that it was used to identify a node. - Index Metadata.nodes by the true unique node identifier: host_id from system tables. This has two consequences: - we can't put contact points in Metadata.nodes directly, because we don't know their host_id yet. Store them separately (MetadataManager.contactPoints) and transfer them during the first node list refresh. - when we receive a status event, we can't use a simple map lookup anymore, so do a linear traversal to find the node with a matching broadcast_rpc_address (side effect: we don't need to translate it). Result: We no longer depend on nodes having a unique socket address. We can plug in custom EndPoint implementations.
- Loading branch information
Showing
94 changed files
with
1,632 additions
and
1,056 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/main/java/com/datastax/oss/driver/api/core/metadata/EndPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.datastax.oss.driver.api.core.metadata; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.net.SocketAddress; | ||
|
||
/** | ||
* Encapsulates the information needed to open connections to a node. | ||
* | ||
* <p>By default, the driver assumes plain TCP connections, and this is just a wrapper around an | ||
* {@link InetSocketAddress}. However, more complex deployment scenarios might use a custom | ||
* implementation that contains additional information; for example, if the nodes are accessed | ||
* through a proxy with SNI routing, an SNI server name is needed in addition to the proxy address. | ||
*/ | ||
public interface EndPoint { | ||
|
||
/** | ||
* Resolves this instance to a socket address. | ||
* | ||
* <p>This will be called each time the driver opens a new connection to the node. The returned | ||
* address cannot be null. | ||
*/ | ||
SocketAddress resolve(); | ||
|
||
/** | ||
* Returns an alternate string representation for use in node-level metric names. | ||
* | ||
* <p>Because metrics names are path-like, dot-separated strings, raw IP addresses don't make very | ||
* good identifiers. So this method will typically replace the dots by another character, for | ||
* example {@code 127_0_0_1_9042}. | ||
*/ | ||
String asMetricPrefix(); | ||
} |
Oops, something went wrong.