dataroaring commented on code in PR #62246:
URL: https://github.com/apache/doris/pull/62246#discussion_r3058343672
##########
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:
Addressed: now using `InetAddress.getByName("localhost").getHostAddress()`
for the localhost test (avoids hardcoding 127.0.0.1 which may not hold on
IPv6-only systems), and switched to `nonexistent.invalid` (RFC 6761 reserved
TLD) for the unresolvable host test. Also fixed the test to use current
`Env`/`AddBackendOp` APIs instead of the removed `Catalog`/`AddBackendClause`.
##########
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:
Addressed: the reported host is now resolved once per
`findBackendByHostAndPort()` call into a `Set<InetAddress>`, then the set is
reused for O(1) containment checks against each backend. DNS resolution no
longer happens inside the loop.
##########
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:
Addressed: added a `ConcurrentHashMap`-backed set (`warnedHostMismatches`)
keyed by `backendId:reportedHost`. Each mismatch pair is warned exactly once.
Subsequent matches for the same pair skip the log.
##########
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:
Addressed: extracted a shared `findBackendByHostAndPort(host, port,
portAccessor, portLabel)` helper that takes a `ToIntFunction<Backend>` for port
extraction. The three public methods are now one-liners delegating to this
helper, eliminating the duplicated fallback logic entirely.
--
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]