aratno commented on code in PR #1913:
URL: 
https://github.com/apache/cassandra-java-driver/pull/1913#discussion_r1491756553


##########
core/src/main/java/com/datastax/oss/driver/internal/core/metadata/DefaultTopologyMonitor.java:
##########
@@ -494,28 +499,50 @@ private void savePort(DriverChannel channel) {
   @Nullable
   protected InetSocketAddress getBroadcastRpcAddress(
       @NonNull AdminRow row, @NonNull EndPoint localEndPoint) {
-    // in system.peers or system.local
-    InetAddress broadcastRpcInetAddress = row.getInetAddress("rpc_address");
-    if (broadcastRpcInetAddress == null) {
-      // in system.peers_v2 (Cassandra >= 4.0)
-      broadcastRpcInetAddress = row.getInetAddress("native_address");
-      if (broadcastRpcInetAddress == null) {
-        // This could only happen if system tables are corrupted, but handle 
gracefully
-        return null;
-      }
-    }
-    // system.local for Cassandra >= 4.0
-    Integer broadcastRpcPort = row.getInteger("rpc_port");
-    if (broadcastRpcPort == null || broadcastRpcPort == 0) {
-      // system.peers_v2
-      broadcastRpcPort = row.getInteger("native_port");
-      if (broadcastRpcPort == null || broadcastRpcPort == 0) {
-        // use the default port if no port information was found in the row;
-        // note that in rare situations, the default port might not be known, 
in which case we
-        // report zero, as advertised in the javadocs of Node and NodeInfo.
-        broadcastRpcPort = port == -1 ? 0 : port;
+
+    InetAddress broadcastRpcInetAddress = null;
+    Iterator<String> addrCandidates =
+        Iterators.forArray(
+            // in system.peers_v2 (Cassandra >= 4.0)
+            "native_address",
+            // DSE 6.8 introduced native_transport_address and 
native_transport_port for the
+            // listen address.
+            "native_transport_address",
+            // in system.peers or system.local
+            "rpc_address");
+
+    while (broadcastRpcInetAddress == null && addrCandidates.hasNext())
+      broadcastRpcInetAddress = row.getInetAddress(addrCandidates.next());
+    // This could only happen if system tables are corrupted, but handle 
gracefully
+    if (broadcastRpcInetAddress == null) return null;
+
+    Integer broadcastRpcPort = null;
+    Iterator<String> portCandidates =
+        Iterators.forArray(
+            // in system.peers_v2 (Cassandra >= 4.0)
+            NATIVE_PORT,
+            // DSE 6.8 introduced native_transport_address and 
native_transport_port for the
+            // listen address.
+            NATIVE_TRANSPORT_PORT,
+            // system.local for Cassandra >= 4.0
+            "rpc_port");
+
+    while ((broadcastRpcPort == null || broadcastRpcPort == 0) && 
portCandidates.hasNext()) {

Review Comment:
   Is there any expected path where one of these columns would set 
broadcastRpcPort to 0?



##########
core/src/main/java/com/datastax/oss/driver/internal/core/metadata/DefaultTopologyMonitor.java:
##########
@@ -494,28 +499,50 @@ private void savePort(DriverChannel channel) {
   @Nullable
   protected InetSocketAddress getBroadcastRpcAddress(
       @NonNull AdminRow row, @NonNull EndPoint localEndPoint) {
-    // in system.peers or system.local
-    InetAddress broadcastRpcInetAddress = row.getInetAddress("rpc_address");
-    if (broadcastRpcInetAddress == null) {
-      // in system.peers_v2 (Cassandra >= 4.0)
-      broadcastRpcInetAddress = row.getInetAddress("native_address");
-      if (broadcastRpcInetAddress == null) {
-        // This could only happen if system tables are corrupted, but handle 
gracefully
-        return null;
-      }
-    }
-    // system.local for Cassandra >= 4.0
-    Integer broadcastRpcPort = row.getInteger("rpc_port");
-    if (broadcastRpcPort == null || broadcastRpcPort == 0) {
-      // system.peers_v2
-      broadcastRpcPort = row.getInteger("native_port");
-      if (broadcastRpcPort == null || broadcastRpcPort == 0) {
-        // use the default port if no port information was found in the row;
-        // note that in rare situations, the default port might not be known, 
in which case we
-        // report zero, as advertised in the javadocs of Node and NodeInfo.
-        broadcastRpcPort = port == -1 ? 0 : port;
+
+    InetAddress broadcastRpcInetAddress = null;
+    Iterator<String> addrCandidates =
+        Iterators.forArray(
+            // in system.peers_v2 (Cassandra >= 4.0)
+            "native_address",
+            // DSE 6.8 introduced native_transport_address and 
native_transport_port for the
+            // listen address.
+            "native_transport_address",
+            // in system.peers or system.local
+            "rpc_address");
+
+    while (broadcastRpcInetAddress == null && addrCandidates.hasNext())
+      broadcastRpcInetAddress = row.getInetAddress(addrCandidates.next());
+    // This could only happen if system tables are corrupted, but handle 
gracefully
+    if (broadcastRpcInetAddress == null) return null;
+
+    Integer broadcastRpcPort = null;
+    Iterator<String> portCandidates =
+        Iterators.forArray(
+            // in system.peers_v2 (Cassandra >= 4.0)
+            NATIVE_PORT,
+            // DSE 6.8 introduced native_transport_address and 
native_transport_port for the
+            // listen address.
+            NATIVE_TRANSPORT_PORT,
+            // system.local for Cassandra >= 4.0
+            "rpc_port");
+
+    while ((broadcastRpcPort == null || broadcastRpcPort == 0) && 
portCandidates.hasNext()) {
+
+      String colName = portCandidates.next();
+      broadcastRpcPort = row.getInteger(colName);
+      // Support override for SSL port (if enabled) in DSE
+      if (NATIVE_TRANSPORT_PORT.equals(colName) && 
context.getSslEngineFactory().isPresent()) {
+
+        String sslColName = colName + "_ssl";
+        broadcastRpcPort = row.getInteger(sslColName);
       }
     }
+    // use the default port if no port information was found in the row;
+    // note that in rare situations, the default port might not be known, in 
which case we
+    // report zero, as advertised in the javadocs of Node and NodeInfo.
+    if (broadcastRpcPort == null || broadcastRpcPort == 0) broadcastRpcPort = 
port == -1 ? 0 : port;

Review Comment:
   Same comment as above - let's log a warning if we fallback to the default 
port



##########
core/src/main/java/com/datastax/oss/driver/internal/core/metadata/DefaultTopologyMonitor.java:
##########
@@ -494,28 +499,50 @@ private void savePort(DriverChannel channel) {
   @Nullable
   protected InetSocketAddress getBroadcastRpcAddress(
       @NonNull AdminRow row, @NonNull EndPoint localEndPoint) {
-    // in system.peers or system.local
-    InetAddress broadcastRpcInetAddress = row.getInetAddress("rpc_address");
-    if (broadcastRpcInetAddress == null) {
-      // in system.peers_v2 (Cassandra >= 4.0)
-      broadcastRpcInetAddress = row.getInetAddress("native_address");
-      if (broadcastRpcInetAddress == null) {
-        // This could only happen if system tables are corrupted, but handle 
gracefully
-        return null;
-      }
-    }
-    // system.local for Cassandra >= 4.0
-    Integer broadcastRpcPort = row.getInteger("rpc_port");
-    if (broadcastRpcPort == null || broadcastRpcPort == 0) {
-      // system.peers_v2
-      broadcastRpcPort = row.getInteger("native_port");
-      if (broadcastRpcPort == null || broadcastRpcPort == 0) {
-        // use the default port if no port information was found in the row;
-        // note that in rare situations, the default port might not be known, 
in which case we
-        // report zero, as advertised in the javadocs of Node and NodeInfo.
-        broadcastRpcPort = port == -1 ? 0 : port;
+
+    InetAddress broadcastRpcInetAddress = null;
+    Iterator<String> addrCandidates =
+        Iterators.forArray(
+            // in system.peers_v2 (Cassandra >= 4.0)
+            "native_address",
+            // DSE 6.8 introduced native_transport_address and 
native_transport_port for the
+            // listen address.
+            "native_transport_address",
+            // in system.peers or system.local
+            "rpc_address");
+
+    while (broadcastRpcInetAddress == null && addrCandidates.hasNext())
+      broadcastRpcInetAddress = row.getInetAddress(addrCandidates.next());
+    // This could only happen if system tables are corrupted, but handle 
gracefully
+    if (broadcastRpcInetAddress == null) return null;

Review Comment:
   Can you add some logging here? This could happen if system tables are 
corrupted, or if one of the "Cassandra compatible" databases (mainly Scylla and 
AWS Keyspaces) that the driver claims to work with doesn't behave as we expect. 
Including extra debug information here could really help those users.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to