bitflicker64 commented on code in PR #3291:
URL: https://github.com/apache/hugegraph/pull/3291#discussion_r4222850214
##########
hugegraph-store/hg-store-core/src/main/java/org/apache/hugegraph/store/util/IpUtil.java:
##########
@@ -63,8 +70,21 @@ private static List<String> getIpAddress() throws
SocketException {
*/
public static String getNearestAddress(String raftAddress) {
try {
- List<String> ipv4s = getIpAddress();
String[] tmp = raftAddress.split(":");
+ if (!isDottedIpv4(tmp[0])) {
+ return raftAddress;
+ }
+
+ // A configured literal that is bound locally stays, including
+ // loopback. The default raft address is 127.0.0.1 and the
+ // partition engine uses that same value as its PeerId.
+ // Loopback is dropped only from fallback candidates, when the
+ // configured IPv4 is not local.
+ if (getIpAddress(true).contains(tmp[0])) {
Review Comment:
Important: This check keeps a configured literal only if
`getIpAddress(true)` contains it, but `getIpAddress` skips
`isLinkLocalAddress()` unconditionally (lines 52-53), even when
`includeLoopback` is true. Before this PR every IPv4 was collected, so a bound
link-local literal had distance 0 and came back unchanged. Now a Store with
`raft.address` set to a 169.254.x.y address bound on its own interface fails
this check and is rewritten to the nearest other interface. `HeartbeatService`
lines 186-187 register that rewritten value with PD, while `PartitionEngine`
keeps `options.getRaftAddress()` as its PeerId. That is the same
registered-address/PeerId mismatch the 127.0.0.1 fix addressed. I compiled the
base and head `IpUtil` on their own: an unbound `169.254.10.10:8510` gives
`127.0.0.1:8510` at base and `100.82.33.17:8510` at head, which confirms
link-local is never a candidate at head. The bound case was traced statically,
since I could not bind 169.254 without root. Please run
this check against all local IPv4 addresses, link-local and loopback included,
and skip link-local and loopback only from the fallback candidates. For
example, give `getIpAddress` a single `forFallback` flag that drops both.
--
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]