Skip to content

Commit c59002e

Browse files
committed
Revert "tmp fix dns cache problem"
This reverts commit e5d83d8.
1 parent a1d5a46 commit c59002e

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

fe/fe-core/src/main/java/org/apache/doris/common/DNSCache.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,10 @@ public String get(String hostname) {
6868
* @return The IP address for the given hostname, or an empty string if the hostname cannot be resolved.
6969
*/
7070
private String resolveHostname(String hostname) {
71-
String cachedIp = cache.get(hostname);
7271
try {
73-
String ip = NetUtils.getIpByHost(hostname, 0);
74-
if (ip == null || ip.isEmpty()) {
75-
if (cachedIp != null && !cachedIp.isEmpty()) {
76-
LOG.warn("Failed to resolve hostname {}, use cached ip: {}", hostname, cachedIp);
77-
return cachedIp;
78-
} else {
79-
LOG.warn("Failed to resolve hostname {}, no cached ip available", hostname);
80-
return "";
81-
}
82-
}
83-
return ip;
72+
return NetUtils.getIpByHost(hostname, 0);
8473
} catch (UnknownHostException e) {
85-
if (cachedIp != null && !cachedIp.isEmpty()) {
86-
LOG.warn("Failed to resolve hostname {}, use cached ip: {}", hostname, cachedIp);
87-
return cachedIp;
88-
} else {
89-
LOG.warn("Failed to resolve hostname {}, no cached ip available", hostname);
90-
return "";
91-
}
74+
return "";
9275
}
9376
}
9477

@@ -100,12 +83,15 @@ private String resolveHostname(String hostname) {
10083
*/
10184
private void refresh() {
10285
for (String hostname : cache.keySet()) {
103-
String resolvedHostname = resolveHostname(hostname);
104-
String currentHostname = cache.get(hostname);
105-
if (!resolvedHostname.equals(currentHostname)) {
106-
cache.put(hostname, resolvedHostname);
107-
LOG.info("IP for hostname {} has changed from {} to {}", hostname, currentHostname,
108-
resolvedHostname);
86+
String resolvedIp = resolveHostname(hostname);
87+
String currentIp = cache.get(hostname);
88+
if (resolvedIp.isEmpty()) {
89+
LOG.warn("Failed to resolve hostname {}, using cached IP: {}", hostname, currentIp);
90+
continue;
91+
}
92+
if (!resolvedIp.equals(currentIp)) {
93+
cache.put(hostname, resolvedIp);
94+
LOG.info("IP for hostname {} has changed from {} to {}", hostname, currentIp, resolvedIp);
10995
}
11096
}
11197
}

0 commit comments

Comments
 (0)