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


##########
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:
   that sounds like a bad idea. Why don't we mimic what `RingProvider` is doing 
instead. If there are host resolution errors, we should fail the request, 
client will see a 500, clients should leverage retries in that case.



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