Copilot commented on code in PR #62246:
URL: https://github.com/apache/doris/pull/62246#discussion_r3052124413
##########
fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java:
##########
@@ -321,6 +321,16 @@ public Backend getBackendWithHeartbeatPort(String host,
int heartPort) {
return backend;
}
}
+ // Fallback: try matching by resolved IP addresses to handle
multi-homed hosts
+ // or hostname/IP mismatches that could cause the same BE to appear as
different nodes
+ for (Backend backend : idToBackend.values()) {
+ if (backend.getHeartbeatPort() == heartPort && isSameHost(host,
backend.getHost())) {
Review Comment:
The same fallback logic (loop + `isSameHost` + warning) is duplicated across
`getBackendWithHeartbeatPort`, `getBackendWithBePort`, and
`getBackendWithHttpPort`. To keep behavior consistent and reduce future drift,
consider extracting a shared private helper that takes a port accessor (or
predicate) and a label for log context.
##########
fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java:
##########
@@ -321,6 +321,16 @@ public Backend getBackendWithHeartbeatPort(String host,
int heartPort) {
return backend;
}
}
+ // Fallback: try matching by resolved IP addresses to handle
multi-homed hosts
+ // or hostname/IP mismatches that could cause the same BE to appear as
different nodes
+ for (Backend backend : idToBackend.values()) {
+ if (backend.getHeartbeatPort() == heartPort && isSameHost(host,
backend.getHost())) {
+ LOG.warn("Backend [id={}] matched by resolved IP. Reported
host: {}, registered host: {}."
+ + " Consider using a consistent IP/hostname.",
+ backend.getId(), host, backend.getHost());
Review Comment:
This WARN will trigger on every successful fallback match. If these methods
are invoked on a hot path (e.g., frequent BE reports), this can cause log
flooding and increase operational noise/cost. Consider
rate-limiting/deduplicating the warning (e.g., once per backend ID + reported
host pair), or logging at INFO/DEBUG with a separate metric/counter to surface
configuration inconsistencies without overwhelming logs.
##########
fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java:
##########
@@ -321,6 +321,16 @@ public Backend getBackendWithHeartbeatPort(String host,
int heartPort) {
return backend;
}
}
+ // Fallback: try matching by resolved IP addresses to handle
multi-homed hosts
+ // or hostname/IP mismatches that could cause the same BE to appear as
different nodes
+ for (Backend backend : idToBackend.values()) {
+ if (backend.getHeartbeatPort() == heartPort && isSameHost(host,
backend.getHost())) {
+ LOG.warn("Backend [id={}] matched by resolved IP. Reported
host: {}, registered host: {}."
+ + " Consider using a consistent IP/hostname.",
+ backend.getId(), host, backend.getHost());
+ return backend;
+ }
+ }
Review Comment:
`isSameHost()` performs DNS resolution (`InetAddress.getAllByName`) and this
fallback loop calls it once per backend candidate, which can turn a single
lookup into many blocking DNS calls (and nested address comparisons). Consider
resolving the reported `host` once per method call, and comparing against each
backend using precomputed sets (e.g., build a `Set<InetAddress>` for one side),
so the loop does not repeatedly resolve/compare more than necessary.
##########
fe/fe-core/src/test/java/org/apache/doris/cluster/SystemInfoServiceTest.java:
##########
@@ -263,6 +263,44 @@ public void removeBackendTest() throws UserException {
}
}
+ @Test
+ public void testIsSameHost() {
+ // Same string should match
+ Assert.assertTrue(SystemInfoService.isSameHost("127.0.0.1",
"127.0.0.1"));
+
+ // Different IPs should not match
+ Assert.assertFalse(SystemInfoService.isSameHost("192.168.0.1",
"192.168.0.2"));
+
+ // localhost and 127.0.0.1 should match
+ Assert.assertTrue(SystemInfoService.isSameHost("localhost",
"127.0.0.1"));
+
+ // Unknown host should return false, not throw
+
Assert.assertFalse(SystemInfoService.isSameHost("this.host.does.not.exist.example.com",
"127.0.0.1"));
Review Comment:
These assertions are potentially flaky across environments: (1) `localhost`
may resolve only to `::1` (IPv6) and not include `127.0.0.1`, making the test
fail even if the implementation is correct; (2) the `example.com` subdomain
could resolve in networks with wildcard DNS/NXDOMAIN rewriting. To make this
deterministic, avoid hard-coding `127.0.0.1` for the `localhost` check (e.g.,
compare `localhost` against
`InetAddress.getByName(\"localhost\").getHostAddress()`), and use a reserved
non-existent domain like `*.invalid` for the unknown-host case (e.g.,
`nonexistent.invalid`).
--
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]