manish-m-pillai commented on code in PR #3733:
URL: https://github.com/apache/cassandra/pull/3733#discussion_r1879570155


##########
src/java/org/apache/cassandra/tools/nodetool/Status.java:
##########
@@ -108,15 +156,32 @@ public void execute(NodeProbe probe)
             TableBuilder tableBuilder = sharedTable.next();
             addNodesHeader(hasEffectiveOwns, tableBuilder);
 
-            ArrayListMultimap<String, HostStatWithPort> hostToTokens = 
ArrayListMultimap.create();
+            ArrayListMultimap<InetAddressAndPort, HostStatWithPort> 
hostToTokens = ArrayListMultimap.create();
             for (HostStatWithPort stat : dc.getValue())
-                
hostToTokens.put(stat.endpointWithPort.getHostAddressAndPort(), stat);
+                hostToTokens.put(stat.endpointWithPort, stat);
 
-            for (String endpoint : hostToTokens.keySet())
+            Map<String, List<Object>> data = new HashMap<>();
+            for (InetAddressAndPort endpoint : hostToTokens.keySet())
             {
-                Float owns = ownerships.get(endpoint);
+                Float owns = ownerships.get(endpoint.getHostAddressAndPort());
                 List<HostStatWithPort> tokens = hostToTokens.get(endpoint);
-                addNode(endpoint, owns, tokens.get(0), tokens.size(), 
hasEffectiveOwns, tableBuilder);
+
+                HostStatWithPort hostStatWithPort = tokens.get(0);
+                String epDns = hostStatWithPort.ipOrDns(printPort);
+                List<Object> nodeData = addNode(epDns, endpoint, owns, 
hostStatWithPort, tokens.size(), hasEffectiveOwns);
+                data.put(epDns, nodeData);
+            }
+
+            data = sort(data);
+
+            for (Map.Entry<String, List<Object>> entry : data.entrySet())
+            {
+                List<Object> values = entry.getValue();
+                List<String> row = new ArrayList<>();
+                for (int i = 1; i < values.size(); i++)

Review Comment:
   We skip the first value (index 0) in the row because it is used solely for 
sorting, not for printing. The first value is an InetAddressAndPort, which 
cannot be cast to a String when printing, causing a ClassCastException. 
Instead, we print epDns (as returned by the addNode() function), which is a 
String and is appropriate for display in the table.



##########
src/java/org/apache/cassandra/tools/nodetool/Status.java:
##########
@@ -179,15 +244,112 @@ private void addNode(String endpoint, Float owns, 
HostStatWithPort hostStat, int
             throw new RuntimeException(e);
         }
 
-        epDns = hostStat.ipOrDns(printPort);
         if (isTokenPerNode)
+            return List.of(addressAndPort, statusAndState, epDns, load, 
strOwns, hostID, hostStat.token, rack);
+        else
+            return List.of(addressAndPort, statusAndState, epDns, load, 
String.valueOf(size), strOwns, hostID, rack);
+    }
+
+    private Boolean desc()

Review Comment:
   Thank you for the suggestion. I see that using the ternary operator makes 
the code more concise and easier to read. I appreciate the simplification. The 
logic is clear and maintains the intended functionality, so I'll go ahead and 
implement the updated version.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to