You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/02/04 18:52:55 UTC

[GitHub] [cassandra] yifan-c commented on a change in pull request #1438: CASSANDRA-17347 Fix NullPointerException during StartupClusterConnectivityChecker

yifan-c commented on a change in pull request #1438:
URL: https://github.com/apache/cassandra/pull/1438#discussion_r799729740



##########
File path: src/java/org/apache/cassandra/net/StartupClusterConnectivityChecker.java
##########
@@ -171,7 +172,10 @@ public boolean execute(Set<InetAddressAndPort> peers, Function<InetAddressAndPor
         {
             // dc -> missing peer host addresses
             Map<String, List<String>> peersDown = acks.getMissingPeers().stream()
-                                                      .collect(groupingBy(peerToDatacenter::get,
+                                                      .collect(groupingBy(peer -> {
+                                                                              String dc = peerToDatacenter.get(peer);
+                                                                              return dc != null ? dc : StringUtils.defaultString(getDatacenterSource.apply(peer), "unknown");

Review comment:
       The goal is here very simple, i.e. try to resolve the value from the map cache, if not try to resolve from snitch, if all attempts fail, use the default "unknown". 
   There are so many ways to express it in the code and all correctly. Functional, ternary operator, or just the plain `if`
   In this particular scenario, I would rate the plain `if` to have the best readability, then the ternary operator. Functional seems a bit overkill. 




-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org