Skip to content

Commit

Permalink
Merge branch '2.x' into feature/7158
Browse files Browse the repository at this point in the history
  • Loading branch information
YongGoose authored Feb 27, 2025
2 parents c8d355a + 4c7d1d9 commit c93089f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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
- [[#7182](https://github.com/apache/incubator-seata/pull/7182)] use the ip of the peerId as the host of the raft node
- [[#7181](https://github.com/apache/incubator-seata/pull/7181)] raft implements domain name resolution and selects peerId


### bugfix:
Expand Down
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- [[#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
- [[#7182](https://github.com/apache/incubator-seata/pull/7182)] 采用peerId的ip作为raft节点的host
- [[#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
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public RaftClusterMetadata changeOrInitRaftClusterMetadata() {
if (leaderNode == null || (leaderNode.getInternal() != null
&& !cureentPeerId.equals(new PeerId(leaderNode.getInternal().getHost(), leaderNode.getInternal().getPort())))) {
Node leader =
raftClusterMetadata.createNode(XID.getIpAddress(), XID.getPort(), raftServer.getServerId().getPort(),
raftClusterMetadata.createNode(cureentPeerId.getIp(), XID.getPort(), raftServer.getServerId().getPort(),
Integer.parseInt(
((Environment)ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT))
.getProperty("server.port", String.valueOf(7091))),
Expand Down Expand Up @@ -413,7 +413,7 @@ private void syncCurrentNodeInfo(PeerId leaderPeerId) {
if (leader != null && StringUtils.isNotBlank(leader.getVersion())) {
RaftServer raftServer = RaftServerManager.getRaftServer(group);
PeerId cureentPeerId = raftServer.getServerId();
Node node = raftClusterMetadata.createNode(XID.getIpAddress(), XID.getPort(), cureentPeerId.getPort(),
Node node = raftClusterMetadata.createNode(cureentPeerId.getIp(), XID.getPort(), cureentPeerId.getPort(),
Integer.parseInt(
((Environment)ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT))
.getProperty("server.port", String.valueOf(7091))),
Expand Down

0 comments on commit c93089f

Please sign in to comment.