This is an automated email from the ASF dual-hosted git repository.
jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push:
new cb3e99b52e optimize: simplifying the relevant transport.*
configuration types (#7645)
cb3e99b52e is described below
commit cb3e99b52ef7d0951cb98451bac2487d844557e0
Author: xiaoyu <[email protected]>
AuthorDate: Wed Sep 24 11:25:14 2025 +0800
optimize: simplifying the relevant transport.* configuration types (#7645)
---
changes/en-us/2.x.md | 1 +
changes/zh-cn/2.x.md | 1 +
.../org/apache/seata/common/ConfigurationKeys.java | 2 +
.../seata/core/rpc/TransportProtocolType.java | 58 ----------------
.../apache/seata/core/rpc/TransportServerType.java | 56 ---------------
.../seata/core/rpc/netty/NettyBaseConfig.java | 81 ++--------------------
.../seata/core/rpc/netty/NettyClientBootstrap.java | 17 ++---
.../seata/core/rpc/netty/NettyClientConfig.java | 10 ---
.../core/rpc/netty/NettyClientBootstrapTest.java | 22 ++++++
.../seata/core/rpc/netty/TmNettyClientTest.java | 9 ++-
script/client/spring/application.properties | 2 -
script/config-center/config.txt | 2 -
12 files changed, 47 insertions(+), 214 deletions(-)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 890dc420f0..129ddf8c54 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -52,6 +52,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7603](https://github.com/seata/seata/pull/7603)] upgrade Apache Tomcat
dependency from 9.0.106 to 9.0.108
- [[#7614](https://github.com/seata/seata/pull/7614)] update README.md
- [[#7443](https://github.com/seata/seata/pull/7443)] Replace @LocalTCC with
@SagaTransactional in the saga annotation pattern
+- [[#7645](https://github.com/seata/seata/pull/7645)] simplifying the relevant
transport.* configuration types
### security:
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 6eb04046d7..de96eb1f33 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -51,6 +51,7 @@
- [[#7603](https://github.com/seata/seata/pull/7603)] 将Apache
Tomcat依赖项从9.0.106升级到9.0.108
- [[#7614](https://github.com/seata/seata/pull/7614)] 更新 README.md
- [[#7443](https://github.com/seata/seata/pull/7443)]
将saga注释模式中的@LocalTCC替换为@SagaTransactional
+- [[#7645](https://github.com/seata/seata/pull/7645)] 简化相关的 transport.* 配置项类型
### security:
diff --git
a/common/src/main/java/org/apache/seata/common/ConfigurationKeys.java
b/common/src/main/java/org/apache/seata/common/ConfigurationKeys.java
index 2eb5fe3e2f..b99c856a0f 100644
--- a/common/src/main/java/org/apache/seata/common/ConfigurationKeys.java
+++ b/common/src/main/java/org/apache/seata/common/ConfigurationKeys.java
@@ -667,11 +667,13 @@ public interface ConfigurationKeys {
/**
* The constant TRANSPORT_TYPE
*/
+ @Deprecated
String TRANSPORT_TYPE = TRANSPORT_PREFIX + "type";
/**
* The constant TRANSPORT_SERVER
*/
+ @Deprecated
String TRANSPORT_SERVER = TRANSPORT_PREFIX + "server";
/**
diff --git
a/core/src/main/java/org/apache/seata/core/rpc/TransportProtocolType.java
b/core/src/main/java/org/apache/seata/core/rpc/TransportProtocolType.java
deleted file mode 100644
index 4c47d1db49..0000000000
--- a/core/src/main/java/org/apache/seata/core/rpc/TransportProtocolType.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.seata.core.rpc;
-
-/**
- * The enum Transport protocol type.
- *
- */
-public enum TransportProtocolType {
- /**
- * Tcp transport protocol type.
- */
- TCP("tcp"),
-
- /**
- * Unix domain socket transport protocol type.
- */
- UNIX_DOMAIN_SOCKET("unix-domain-socket");
-
- /**
- * The Name.
- */
- public final String name;
-
- TransportProtocolType(String name) {
- this.name = name;
- }
-
- /**
- * Gets type.
- *
- * @param name the name
- * @return the type
- */
- public static TransportProtocolType getType(String name) {
- name = name.trim().replace('-', '_');
- for (TransportProtocolType b : TransportProtocolType.values()) {
- if (b.name().equalsIgnoreCase(name)) {
- return b;
- }
- }
- throw new IllegalArgumentException("unknown type:" + name);
- }
-}
diff --git
a/core/src/main/java/org/apache/seata/core/rpc/TransportServerType.java
b/core/src/main/java/org/apache/seata/core/rpc/TransportServerType.java
deleted file mode 100644
index 0b1026d200..0000000000
--- a/core/src/main/java/org/apache/seata/core/rpc/TransportServerType.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.seata.core.rpc;
-
-/**
- * The enum Transport server type.
- *
- */
-public enum TransportServerType {
- /**
- * Native transport server type.
- */
- NATIVE("native"),
- /**
- * Nio transport server type.
- */
- NIO("nio");
-
- /**
- * The Name.
- */
- public final String name;
-
- TransportServerType(String name) {
- this.name = name;
- }
-
- /**
- * Gets type.
- *
- * @param name the name
- * @return the type
- */
- public static TransportServerType getType(String name) {
- for (TransportServerType b : TransportServerType.values()) {
- if (b.name().equalsIgnoreCase(name)) {
- return b;
- }
- }
- throw new IllegalArgumentException("unknown type:" + name);
- }
-}
diff --git
a/core/src/main/java/org/apache/seata/core/rpc/netty/NettyBaseConfig.java
b/core/src/main/java/org/apache/seata/core/rpc/netty/NettyBaseConfig.java
index ae171933bd..355b5830f6 100644
--- a/core/src/main/java/org/apache/seata/core/rpc/netty/NettyBaseConfig.java
+++ b/core/src/main/java/org/apache/seata/core/rpc/netty/NettyBaseConfig.java
@@ -18,14 +18,9 @@ package org.apache.seata.core.rpc.netty;
import io.netty.channel.Channel;
import io.netty.channel.ServerChannel;
-import io.netty.channel.epoll.EpollDomainSocketChannel;
-import io.netty.channel.epoll.EpollServerDomainSocketChannel;
+import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollServerSocketChannel;
import io.netty.channel.epoll.EpollSocketChannel;
-import io.netty.channel.kqueue.KQueueDomainSocketChannel;
-import io.netty.channel.kqueue.KQueueServerDomainSocketChannel;
-import io.netty.channel.kqueue.KQueueServerSocketChannel;
-import io.netty.channel.kqueue.KQueueSocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.NettyRuntime;
@@ -34,10 +29,6 @@ import org.apache.commons.lang.StringUtils;
import org.apache.seata.config.Configuration;
import org.apache.seata.config.ConfigurationFactory;
import org.apache.seata.core.constants.ConfigurationKeys;
-import org.apache.seata.core.rpc.TransportProtocolType;
-import org.apache.seata.core.rpc.TransportServerType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import static
org.apache.seata.common.DefaultValues.DEFAULT_TRANSPORT_HEARTBEAT;
@@ -46,7 +37,6 @@ import static
org.apache.seata.common.DefaultValues.DEFAULT_TRANSPORT_HEARTBEAT;
*
*/
public class NettyBaseConfig {
- private static final Logger LOGGER =
LoggerFactory.getLogger(NettyBaseConfig.class);
/**
* The constant CONFIG.
@@ -72,11 +62,6 @@ public class NettyBaseConfig {
*/
protected static final int WORKER_THREAD_SIZE;
- /**
- * The constant TRANSPORT_SERVER_TYPE.
- */
- protected static final TransportServerType TRANSPORT_SERVER_TYPE;
-
/**
* The constant SERVER_CHANNEL_CLAZZ.
*/
@@ -86,11 +71,6 @@ public class NettyBaseConfig {
*/
protected static final Class<? extends Channel> CLIENT_CHANNEL_CLAZZ;
- /**
- * The constant TRANSPORT_PROTOCOL_TYPE.
- */
- protected static final TransportProtocolType TRANSPORT_PROTOCOL_TYPE;
-
private static final int DEFAULT_WRITE_IDLE_SECONDS = 5;
private static final int READIDLE_BASE_WRITEIDLE = 3;
@@ -111,8 +91,6 @@ public class NettyBaseConfig {
protected static final int MAX_ALL_IDLE_SECONDS = 0;
static {
- TRANSPORT_PROTOCOL_TYPE = TransportProtocolType.getType(
- CONFIG.getConfig(ConfigurationKeys.TRANSPORT_TYPE,
TransportProtocolType.TCP.name()));
String workerThreadSize =
CONFIG.getConfig(ConfigurationKeys.WORKER_THREAD_SIZE);
if (StringUtils.isNotBlank(workerThreadSize) &&
StringUtils.isNumeric(workerThreadSize)) {
WORKER_THREAD_SIZE = Integer.parseInt(workerThreadSize);
@@ -121,51 +99,11 @@ public class NettyBaseConfig {
} else {
WORKER_THREAD_SIZE = WorkThreadMode.Default.getValue();
}
- TRANSPORT_SERVER_TYPE = TransportServerType.getType(
- CONFIG.getConfig(ConfigurationKeys.TRANSPORT_SERVER,
TransportServerType.NIO.name()));
- switch (TRANSPORT_SERVER_TYPE) {
- case NIO:
- if (TRANSPORT_PROTOCOL_TYPE == TransportProtocolType.TCP) {
- SERVER_CHANNEL_CLAZZ = NioServerSocketChannel.class;
- CLIENT_CHANNEL_CLAZZ = NioSocketChannel.class;
- } else {
- raiseUnsupportedTransportError();
- SERVER_CHANNEL_CLAZZ = null;
- CLIENT_CHANNEL_CLAZZ = null;
- }
- break;
- case NATIVE:
- if (PlatformDependent.isWindows()) {
- throw new IllegalArgumentException("no native supporting
for Windows.");
- } else if (PlatformDependent.isOsx()) {
- if (TRANSPORT_PROTOCOL_TYPE == TransportProtocolType.TCP) {
- SERVER_CHANNEL_CLAZZ = KQueueServerSocketChannel.class;
- CLIENT_CHANNEL_CLAZZ = KQueueSocketChannel.class;
- } else if (TRANSPORT_PROTOCOL_TYPE ==
TransportProtocolType.UNIX_DOMAIN_SOCKET) {
- SERVER_CHANNEL_CLAZZ =
KQueueServerDomainSocketChannel.class;
- CLIENT_CHANNEL_CLAZZ = KQueueDomainSocketChannel.class;
- } else {
- raiseUnsupportedTransportError();
- SERVER_CHANNEL_CLAZZ = null;
- CLIENT_CHANNEL_CLAZZ = null;
- }
- } else {
- if (TRANSPORT_PROTOCOL_TYPE == TransportProtocolType.TCP) {
- SERVER_CHANNEL_CLAZZ = EpollServerSocketChannel.class;
- CLIENT_CHANNEL_CLAZZ = EpollSocketChannel.class;
- } else if (TRANSPORT_PROTOCOL_TYPE ==
TransportProtocolType.UNIX_DOMAIN_SOCKET) {
- SERVER_CHANNEL_CLAZZ =
EpollServerDomainSocketChannel.class;
- CLIENT_CHANNEL_CLAZZ = EpollDomainSocketChannel.class;
- } else {
- raiseUnsupportedTransportError();
- SERVER_CHANNEL_CLAZZ = null;
- CLIENT_CHANNEL_CLAZZ = null;
- }
- }
- break;
- default:
- throw new IllegalArgumentException("unsupported.");
- }
+
+ boolean useEpoll = !PlatformDependent.isWindows() &&
!PlatformDependent.isOsx() && Epoll.isAvailable();
+ SERVER_CHANNEL_CLAZZ = useEpoll ? EpollServerSocketChannel.class :
NioServerSocketChannel.class;
+ CLIENT_CHANNEL_CLAZZ = useEpoll ? EpollSocketChannel.class :
NioSocketChannel.class;
+
boolean enableHeartbeat =
CONFIG.getBoolean(ConfigurationKeys.TRANSPORT_HEARTBEAT,
DEFAULT_TRANSPORT_HEARTBEAT);
if (enableHeartbeat) {
MAX_WRITE_IDLE_SECONDS = DEFAULT_WRITE_IDLE_SECONDS;
@@ -175,13 +113,6 @@ public class NettyBaseConfig {
MAX_READ_IDLE_SECONDS = MAX_WRITE_IDLE_SECONDS *
READIDLE_BASE_WRITEIDLE;
}
- private static void raiseUnsupportedTransportError() throws
RuntimeException {
- String errMsg = String.format(
- "Unsupported provider type :[%s] for transport:[%s].",
TRANSPORT_SERVER_TYPE, TRANSPORT_PROTOCOL_TYPE);
- LOGGER.error(errMsg);
- throw new IllegalArgumentException(errMsg);
- }
-
/**
* The enum Work thread mode.
*/
diff --git
a/core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientBootstrap.java
b/core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientBootstrap.java
index 2b8396d4e2..dd732eaa6a 100644
---
a/core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientBootstrap.java
+++
b/core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientBootstrap.java
@@ -27,6 +27,7 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollChannelOption;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollMode;
@@ -125,16 +126,12 @@ public class NettyClientBootstrap implements
RemotingBootstrap {
.option(ChannelOption.SO_SNDBUF,
nettyClientConfig.getClientSocketSndBufSize())
.option(ChannelOption.SO_RCVBUF,
nettyClientConfig.getClientSocketRcvBufSize());
- if (nettyClientConfig.enableNative()) {
- if (PlatformDependent.isOsx()) {
- if (LOGGER.isInfoEnabled()) {
- LOGGER.info("client run on macOS");
- }
- } else {
- bootstrap
- .option(EpollChannelOption.EPOLL_MODE,
EpollMode.EDGE_TRIGGERED)
- .option(EpollChannelOption.TCP_QUICKACK, true);
- }
+ if (PlatformDependent.isWindows() || PlatformDependent.isOsx()) {
+ LOGGER.info("client run on MacOS/Windows, fallback to NIO.");
+ } else if (Epoll.isAvailable()) {
+ bootstrap
+ .option(EpollChannelOption.EPOLL_MODE,
EpollMode.EDGE_TRIGGERED)
+ .option(EpollChannelOption.TCP_QUICKACK, true);
}
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
diff --git
a/core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientConfig.java
b/core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientConfig.java
index a73be26faf..9547c5b613 100644
--- a/core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientConfig.java
+++ b/core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientConfig.java
@@ -18,7 +18,6 @@ package org.apache.seata.core.rpc.netty;
import io.netty.channel.Channel;
import org.apache.seata.common.ConfigurationKeys;
-import org.apache.seata.core.rpc.TransportServerType;
import static
org.apache.seata.common.DefaultValues.DEFAULT_ENABLE_CLIENT_BATCH_SEND_REQUEST;
import static
org.apache.seata.common.DefaultValues.DEFAULT_ENABLE_CLIENT_USE_SHARED_EVENT_LOOP;
@@ -172,15 +171,6 @@ public class NettyClientConfig extends NettyBaseConfig {
return clientChannelClazz;
}
- /**
- * Enable native boolean.
- *
- * @return the boolean
- */
- public boolean enableNative() {
- return TRANSPORT_SERVER_TYPE == TransportServerType.NATIVE;
- }
-
/**
* Gets per host max conn.
*
diff --git
a/core/src/test/java/org/apache/seata/core/rpc/netty/NettyClientBootstrapTest.java
b/core/src/test/java/org/apache/seata/core/rpc/netty/NettyClientBootstrapTest.java
index 67852b4ba2..cdd37a05b8 100644
---
a/core/src/test/java/org/apache/seata/core/rpc/netty/NettyClientBootstrapTest.java
+++
b/core/src/test/java/org/apache/seata/core/rpc/netty/NettyClientBootstrapTest.java
@@ -17,6 +17,10 @@
package org.apache.seata.core.rpc.netty;
import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollSocketChannel;
+import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.util.internal.PlatformDependent;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -59,6 +63,24 @@ class NettyClientBootstrapTest {
Assertions.assertNotEquals(tmEventLoopGroupWorker,
rmEventLoopGroupWorker);
}
+ @Test
+ void testStartWithSharedEventLoopAndChannelSelection() {
+
when(nettyClientConfig.getEnableClientSharedEventLoop()).thenReturn(true);
+ when(nettyClientConfig.getClientChannelClazz()).thenAnswer(invocation
-> {
+ if (PlatformDependent.isWindows() || PlatformDependent.isOsx()) {
+ return NioSocketChannel.class;
+ } else if (Epoll.isAvailable()) {
+ return EpollSocketChannel.class;
+ } else {
+ return NioSocketChannel.class;
+ }
+ });
+
+ NettyClientBootstrap tmNettyClientBootstrap =
+ new NettyClientBootstrap(nettyClientConfig,
NettyPoolKey.TransactionRole.TMROLE);
+ tmNettyClientBootstrap.start();
+ }
+
private EventLoopGroup getEventLoopGroupWorker(NettyClientBootstrap
bootstrap) {
try {
java.lang.reflect.Field field =
NettyClientBootstrap.class.getDeclaredField("eventLoopGroupWorker");
diff --git
a/core/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java
b/core/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java
index 9fc224405e..589e66a4dc 100644
--- a/core/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java
+++ b/core/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java
@@ -20,6 +20,8 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFactory;
import io.netty.channel.ChannelOption;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.seata.common.ConfigurationKeys;
@@ -101,7 +103,12 @@ public class TmNettyClientTest {
ChannelFactory<? extends Channel> channelFactory =
(ChannelFactory<? extends Channel>)
channelFactoryField.get(bootstrap);
Assertions.assertNotNull(channelFactory);
- Assertions.assertTrue(channelFactory.newChannel() instanceof
NioSocketChannel);
+
+ if (Epoll.isAvailable()) {
+ Assertions.assertTrue(channelFactory.newChannel() instanceof
EpollSocketChannel);
+ } else {
+ Assertions.assertTrue(channelFactory.newChannel() instanceof
NioSocketChannel);
+ }
}
/**
diff --git a/script/client/spring/application.properties
b/script/client/spring/application.properties
index 8f69e6045f..804b0d09e2 100755
--- a/script/client/spring/application.properties
+++ b/script/client/spring/application.properties
@@ -75,8 +75,6 @@ seata.transport.thread-factory.client-selector-thread-size=-1
seata.transport.thread-factory.client-worker-thread-prefix=NettyClientWorkerThread
seata.transport.thread-factory.worker-thread-size=default
seata.transport.thread-factory.boss-thread-size=1
-seata.transport.type=TCP
-seata.transport.server=NIO
seata.transport.heartbeat=true
seata.transport.serialization=seata
seata.transport.compressor=none
diff --git a/script/config-center/config.txt b/script/config-center/config.txt
index 4c9e5c43a2..c6435eee60 100644
--- a/script/config-center/config.txt
+++ b/script/config-center/config.txt
@@ -18,8 +18,6 @@
#For details about configuration items, see
https://seata.apache.org/zh-cn/docs/user/configurations
#Transport configuration, for client and server
transport.protocol=seata
-transport.type=TCP
-transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]