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


##########
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:
   Honestly I'm not sure what happens if you set native_transport_port to zero 
(or a negative value for that matter), but I would expect one of three 
reasonable outcomes:
   
   * Try the default
   * Fail startup and log an error
   * Pick a random port
   
   And... I guess I'd be wrong?
   
   ```
   INFO  [main] 2024-02-21 20:34:15,019 PipelineConfigurator.java:125 - 
Starting listening for CQL clients on /127.0.0.1:0 (unencrypted)...
   INFO  [main] 2024-02-21 20:34:15,023 CassandraDaemon.java:782 - Startup 
complete
   ```
   
   That is from C* 4.0.2.  It looks like in this case the server just... 
doesn't open a listening port at all:
   
   ```
   $ ps auxw | grep -i CassandraDaemon | grep -n grep | awk '{ print $2 }'
   1231772
   $ sudo lsof -nP -iTCP -sTCP:LISTEN | grep java | grep 1231772
   $
   ```
   
   And if that's the case it's actually okay since we're dealing with client 
code here and the client obviously won't be able to connect if there's no 
listening port.



-- 
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