Skip to content

Commit

Permalink
feature: raft implements domain name resolution and selects peerId (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
PeppaO authored Feb 25, 2025
1 parent d667466 commit 5c353cf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7114](https://github.com/apache/incubator-seata/pull/7114)] support raft mode registry to namingserver
- [[#7133](https://github.com/apache/incubator-seata/pull/7133)] Implement scheduled handling for end status transaction
- [[#7171](https://github.com/apache/incubator-seata/pull/7171)] support EpollEventLoopGroup in client
- [[#7181](https://github.com/apache/incubator-seata/pull/7181)] raft implements domain name resolution and selects peerId


### bugfix:
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [[#7114](https://github.com/apache/incubator-seata/pull/7114)] 支持raft集群注册至namingserver
- [[#7133](https://github.com/apache/incubator-seata/pull/7133)] 实现对残留的end状态事务定时处理
- [[#7171](https://github.com/apache/incubator-seata/pull/7171)] 客户端支持 EpollEventLoopGroup
- [[#7181](https://github.com/apache/incubator-seata/pull/7181)] raft实现域名解析并选择peerId


### bugfix:
Expand Down
25 changes: 25 additions & 0 deletions common/src/main/java/org/apache/seata/common/util/NetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.List;
import java.util.ArrayList;


/**
Expand Down Expand Up @@ -367,4 +369,27 @@ private static String removeBrackets(String str) {
}
return str.replaceAll("[\\[\\]]", "");
}

public static List<String> getHostByName(String ipOrDomain) {
if (ipOrDomain == null) {
return null;
}
List<String> ipAddressList = new ArrayList<>();
if (isValidIPv4(ipOrDomain) || isValidIPv6(ipOrDomain)) {
ipAddressList.add(ipOrDomain);
return ipAddressList;
} else {
try {
InetAddress[] allByName = InetAddress.getAllByName(ipOrDomain);
for (InetAddress address : allByName) {
ipAddressList.add(address.getHostAddress());
}
return ipAddressList;
} catch (UnknownHostException e) {
LOGGER.warn("Failed to resolve ip address, {}", e.getMessage());
ipAddressList.add(ipOrDomain);
return ipAddressList;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import com.alipay.remoting.serialization.SerializerManager;
Expand All @@ -39,6 +40,7 @@
import org.apache.seata.common.ConfigurationKeys;
import org.apache.seata.common.XID;
import org.apache.seata.common.store.SessionMode;
import org.apache.seata.common.util.NetUtil;
import org.apache.seata.common.util.StringUtils;
import org.apache.seata.config.ConfigurationFactory;
import org.apache.seata.core.serializer.SerializerType;
Expand Down Expand Up @@ -117,12 +119,16 @@ public static void init() {
if (port <= 0) {
// Highly available deployments require different nodes
for (PeerId peer : initConf.getPeers()) {
if (StringUtils.equals(peer.getIp(), host)) {
if (serverId != null) {
throw new IllegalArgumentException(
"server.raft.cluster has duplicate ip, For local debugging, use -Dserver.raftPort to specify the raft port");
List<String> peerIps = NetUtil.getHostByName(peer.getIp());
for (String peerIp : peerIps) {
if (StringUtils.equals(peerIp, host)) {
if (serverId != null) {
throw new IllegalArgumentException(
"server.raft.cluster has duplicate ip, For local debugging, use -Dserver.raftPort to specify the raft port");
}
serverId = peer;
break;
}
serverId = peer;
}
}
} else {
Expand Down

0 comments on commit 5c353cf

Please sign in to comment.