arjunashok commented on code in PR #69:
URL: https://github.com/apache/cassandra-sidecar/pull/69#discussion_r1332054697


##########
adapters/base/src/main/java/org/apache/cassandra/sidecar/adapters/base/TokenRangeReplicaProvider.java:
##########
@@ -115,22 +121,51 @@ private List<TokenRangeReplicas> 
transformRangeMappings(Map<List<String>, List<S
                               .collect(toList());
     }
 
-    private Map<String, String> replicaToStateMap(List<TokenRangeReplicas> 
replicaSet, StorageJmxOperations storage)
+    private List<ReplicaMetadata> getReplicaMetadata(List<TokenRangeReplicas> 
replicaSet,
+                                                     StorageJmxOperations 
storage,
+                                                     Map<String, String> 
hostToDatacenter)
     {
         List<String> joiningNodes = storage.getJoiningNodesWithPort();
         List<String> leavingNodes = storage.getLeavingNodesWithPort();
         List<String> movingNodes = storage.getMovingNodesWithPort();
 
+        List<String> liveNodes = storage.getLiveNodesWithPort();
+        List<String> deadNodes = storage.getUnreachableNodesWithPort();
+
+
         String rawGossipInfo = getRawGossipInfo();
         GossipInfoResponse gossipInfo = GossipInfoParser.parse(rawGossipInfo);
 
         StateWithReplacement state = new StateWithReplacement(joiningNodes, 
leavingNodes, movingNodes, gossipInfo);
+        RingProvider.Status status = new RingProvider.Status(liveNodes, 
deadNodes);
 
         return replicaSet.stream()
                          .map(TokenRangeReplicas::replicaSet)
                          .flatMap(Collection::stream)
                          .distinct()
-                         .collect(Collectors.toMap(Function.identity(), 
state::of));
+                         .map(r -> new ReplicaMetadata(state.of(r),
+                                                       status.of(r),
+                                                       resolveReplica(r),
+                                                       r,
+                                                       
hostToDatacenter.get(r)))
+                         .collect(Collectors.toList());
+
+    }
+
+    private String resolveReplica(String r)
+    {
+        String hostName;
+        try
+        {
+            hostName = dnsResolver.reverseResolve(r.split(":")[0]);
+        }
+        catch (Exception e)
+        {
+            // Swallow exception to not fail-fast on DNS resolution failure
+            LOGGER.warn("Failed to resolve hostname for instance {}: {}", r, 
e);
+            hostName = "";

Review Comment:
   I explicitly left this empty to denote the resolution failure, so the client 
can choose to handle it differently in this event. For instance, it can retry 
instead of making a sidecar request with the IP, which would fail to verify the 
client identity with TLS.



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