github-actions[bot] commented on code in PR #69423:
URL: https://github.com/apache/doris/pull/69423#discussion_r4345214798


##########
fe/fe-core/src/main/java/org/apache/doris/common/DNSCache.java:
##########
@@ -57,7 +59,27 @@ public void start() {
      * @return The IP address for the given hostname.
      */
     public String get(String hostname) {
-        return cache.computeIfAbsent(hostname, this::resolveHostname);
+        String cachedIp = cache.get(hostname);
+        if (cachedIp != null && !refreshPending.contains(hostname)) {
+            return cachedIp;
+        }
+        return cache.compute(hostname, (host, currentIp) -> {
+            // Claim before DNS I/O so an invalidation arriving during this 
lookup is
+            // retained for the next get(). Concurrent lookups of this host 
serialize here.
+            boolean needsRefresh = refreshPending.remove(host);
+            if (currentIp == null || needsRefresh) {
+                return resolveHostname(host);
+            }
+            return currentIp;
+        });
+    }
+
+    public void invalidate(String hostname) {
+        // A successful heartbeat may coincide with a temporary DNS outage. 
Keep the
+        // last known IP so resolveHostname can fall back instead of caching 
an empty IP.
+        if (cache.containsKey(hostname)) {

Review Comment:
   [P2] Preserve invalidation during the first hostname lookup
   
   If a query is inside the first `get(hostname)` DNS computation when a 
successful restart heartbeat (or its replay) calls this method, the cache entry 
has not been published, so `containsKey` is false and the refresh request is 
lost. That earlier lookup can then publish the old pod IP and create a channel 
after `invalidateForAll` has finished. Subsequent queries take the unmarked 
cache fast path and keep connecting to the obsolete IP until the periodic 
refresh (60 seconds, with a 120-second initial delay). Retain invalidation for 
in-flight first lookups, for example with a pending marker or generation, and 
cover this ordering with a latch-controlled test. This is distinct from the 
existing fallback-retention thread: here no cached IP exists when invalidation 
arrives.



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