You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by mi...@apache.org on 2025/02/24 02:58:50 UTC

(incubator-seata) branch 2.x updated: optimize: Throwing IOException in sendSyncRequest (#7162)

This is an automated email from the ASF dual-hosted git repository.

minghua 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 679a2e01ec optimize: Throwing IOException in sendSyncRequest (#7162)
679a2e01ec is described below

commit 679a2e01ec985c9743e338bb418c9d4d5c998323
Author: justabug <Bu...@users.noreply.github.com>
AuthorDate: Mon Feb 24 10:58:45 2025 +0800

    optimize: Throwing IOException in sendSyncRequest (#7162)
---
 .../main/java/org/apache/seata/core/rpc/RemotingServer.java |  7 ++++---
 .../seata/core/rpc/netty/AbstractNettyRemotingServer.java   | 13 +++++++------
 .../main/java/org/apache/seata/mockserver/call/CallRm.java  |  5 +++--
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/core/src/main/java/org/apache/seata/core/rpc/RemotingServer.java b/core/src/main/java/org/apache/seata/core/rpc/RemotingServer.java
index c3141603a0..f38e301b85 100644
--- a/core/src/main/java/org/apache/seata/core/rpc/RemotingServer.java
+++ b/core/src/main/java/org/apache/seata/core/rpc/RemotingServer.java
@@ -21,6 +21,7 @@ import org.apache.seata.core.protocol.RpcMessage;
 import org.apache.seata.core.rpc.processor.RemotingProcessor;
 import org.apache.seata.core.protocol.MessageType;
 
+import java.io.IOException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeoutException;
 
@@ -41,7 +42,7 @@ public interface RemotingServer {
      * @return client result message
      * @throws TimeoutException TimeoutException
      */
-    Object sendSyncRequest(String resourceId, String clientId, Object msg, boolean tryOtherApp) throws TimeoutException;
+    Object sendSyncRequest(String resourceId, String clientId, Object msg, boolean tryOtherApp) throws TimeoutException, IOException;
 
     /**
      * server send sync request.
@@ -51,7 +52,7 @@ public interface RemotingServer {
      * @return client result message
      * @throws TimeoutException TimeoutException
      */
-    Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException;
+    Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException, IOException;
 
     /**
      * server send async request.
@@ -59,7 +60,7 @@ public interface RemotingServer {
      * @param channel client channel
      * @param msg     transaction message {@code org.apache.seata.core.protocol}
      */
-    void sendAsyncRequest(Channel channel, Object msg);
+    void sendAsyncRequest(Channel channel, Object msg) throws IOException;
 
     /**
      * server send async response.
diff --git a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java
index 67df2ea849..fc6a7f21dd 100644
--- a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java
+++ b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java
@@ -16,6 +16,7 @@
  */
 package org.apache.seata.core.rpc.netty;
 
+import java.io.IOException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeoutException;
@@ -68,28 +69,28 @@ public abstract class AbstractNettyRemotingServer extends AbstractNettyRemoting
 
     @Override
     public Object sendSyncRequest(String resourceId, String clientId, Object msg, boolean tryOtherApp)
-        throws TimeoutException {
+            throws TimeoutException, IOException {
         Channel channel = ChannelManager.getChannel(resourceId, clientId, tryOtherApp);
         if (channel == null) {
-            throw new RuntimeException("rm client is not connected. dbkey:" + resourceId + ",clientId:" + clientId);
+            throw new IOException("rm client is not connected. dbkey:" + resourceId + ",clientId:" + clientId);
         }
         RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC);
         return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout());
     }
 
     @Override
-    public Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException {
+    public Object sendSyncRequest(Channel channel, Object msg) throws TimeoutException, IOException {
         if (channel == null) {
-            throw new RuntimeException("client is not connected");
+            throw new IOException("client is not connected");
         }
         RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_SYNC);
         return super.sendSync(channel, rpcMessage, NettyServerConfig.getRpcRequestTimeout());
     }
 
     @Override
-    public void sendAsyncRequest(Channel channel, Object msg) {
+    public void sendAsyncRequest(Channel channel, Object msg) throws IOException {
         if (channel == null) {
-            throw new RuntimeException("client is not connected");
+            throw new IOException("client is not connected");
         }
         RpcMessage rpcMessage = buildRequestMessage(msg, ProtocolConstants.MSGTYPE_RESQUEST_ONEWAY);
         super.sendAsync(channel, rpcMessage);
diff --git a/mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java b/mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java
index 8a347246f3..be48ab4c63 100644
--- a/mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java
+++ b/mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java
@@ -16,6 +16,7 @@
  */
 package org.apache.seata.mockserver.call;
 
+import java.io.IOException;
 import java.util.concurrent.TimeoutException;
 
 import io.netty.channel.Channel;
@@ -49,7 +50,7 @@ public class CallRm {
             BranchCommitResponse response = (BranchCommitResponse)remotingServer.sendSyncRequest(
                 branchSession.getResourceId(), branchSession.getClientId(), request, false);
             return response.getBranchStatus();
-        } catch (TimeoutException e) {
+        } catch (TimeoutException | IOException e) {
             throw new RuntimeException(e);
         }
     }
@@ -68,7 +69,7 @@ public class CallRm {
             BranchRollbackResponse response = (BranchRollbackResponse)remotingServer.sendSyncRequest(
                 branchSession.getResourceId(), branchSession.getClientId(), request, false);
             return response.getBranchStatus();
-        } catch (TimeoutException e) {
+        } catch (TimeoutException | IOException e) {
             throw new RuntimeException(e);
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org