Skip to content

Commit

Permalink
optimize: Throwing IOException in sendSyncRequest (#7162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bughue authored Feb 24, 2025
1 parent c4b9b93 commit 679a2e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;

Expand All @@ -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.
Expand All @@ -51,15 +52,15 @@ 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.
*
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,28 +69,28 @@ public AbstractNettyRemotingServer(ThreadPoolExecutor messageExecutor, NettyServ

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.seata.mockserver.call;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import io.netty.channel.Channel;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static BranchStatus branchCommit(RemotingServer remotingServer, MockBranc
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);
}
}
Expand All @@ -68,7 +69,7 @@ public static BranchStatus branchRollback(RemotingServer remotingServer, MockBra
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);
}
}
Expand Down

0 comments on commit 679a2e0

Please sign in to comment.