jmckenzie-dev commented on code in PR #332:
URL: https://github.com/apache/cassandra-sidecar/pull/332#discussion_r3040850803


##########
server/src/main/java/org/apache/cassandra/sidecar/cdc/CdcManager.java:
##########
@@ -207,34 +205,17 @@ public void stopConsumers()
         consumers.forEach(SidecarCdc::stop);
     }
 
-    private Integer getInstanceId(String instanceIp)
-    {
-        for (InstanceMetadata instance : instanceFetcher.allLocalInstances())
-        {
-            String configuredIpAddress = instance.ipAddress();
-
-            // Option 1a: Normalize both to InetAddress and compare
-            if (resolveToSameAddress(instanceIp, configuredIpAddress))
-            {
-                return instance.id();
-            }
-        }
-        LOGGER.warn("Requested IP {} does not match with any instances", 
instanceIp);
-        return -1;
-    }
-
-    public static boolean resolveToSameAddress(String address1, String 
address2)
+    @VisibleForTesting
+    Integer getInstanceId(String instanceIp)
     {
         try
         {
-            InetAddress addr1 = InetAddress.getByName(address1);
-            InetAddress addr2 = InetAddress.getByName(address2);
-            return addr1.equals(addr2);
+            return instanceFetcher.instance(instanceIp).id();
         }
-        catch (UnknownHostException e)
+        catch (Exception e)
         {
-            LOGGER.warn("Could not resolve hostname: {}", e.getMessage());
-            return address1.equals(address2); // Fallback to string comparison
+            LOGGER.warn("Requested IP {} does not match with any instances", 
instanceIp);
+            return -1;

Review Comment:
   wdyt about, instead of using `-1` here as a magic number, we define a static 
constant `UNKNOWN_INSTANCE` or something we return when we fail to match and 
check against?



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