Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: Only AT mode try to get channel with other app #5153

Merged
merged 8 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/io/seata/core/rpc/RemotingServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public interface RemotingServer {
* @param resourceId rm client resourceId
* @param clientId rm client id
* @param msg transaction message {@code io.seata.core.protocol}
* @param tryOtherApp try other app
* @return client result message
* @throws TimeoutException TimeoutException
*/
Object sendSyncRequest(String resourceId, String clientId, Object msg) throws TimeoutException;
Object sendSyncRequest(String resourceId, String clientId, Object msg, boolean tryOtherApp) throws TimeoutException;

/**
* server send sync request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public AbstractNettyRemotingServer(ThreadPoolExecutor messageExecutor, NettyServ
}

@Override
public Object sendSyncRequest(String resourceId, String clientId, Object msg) throws TimeoutException {
Channel channel = ChannelManager.getChannel(resourceId, clientId);
public Object sendSyncRequest(String resourceId, String clientId, Object msg, boolean tryOtherApp)
throws TimeoutException {
Channel channel = ChannelManager.getChannel(resourceId, clientId, tryOtherApp);
if (channel == null) {
throw new RuntimeException("rm client is not connected. dbkey:" + resourceId + ",clientId:" + clientId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private static Channel getChannelFromSameClientMap(Map<Integer, RpcContext> clie
* @param clientId Client ID - ApplicationId:IP:Port
* @return Corresponding channel, NULL if not found.
*/
public static Channel getChannel(String resourceId, String clientId) {
public static Channel getChannel(String resourceId, String clientId, boolean tryOtherApp) {
Channel resultChannel = null;

String[] clientIdInfo = readClientId(clientId);
Expand Down Expand Up @@ -381,7 +381,7 @@ public static Channel getChannel(String resourceId, String clientId) {
}
}

if (resultChannel == null) {
if (resultChannel == null && tryOtherApp) {
resultChannel = tryOtherApp(applicationIdMap, targetApplicationId);

if (resultChannel == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ public BranchStatus branchCommit(GlobalSession globalSession, BranchSession bran

protected BranchStatus branchCommitSend(BranchCommitRequest request, GlobalSession globalSession,
BranchSession branchSession) throws IOException, TimeoutException {

BranchCommitResponse response = (BranchCommitResponse) remotingServer.sendSyncRequest(
branchSession.getResourceId(), branchSession.getClientId(), request);
branchSession.getResourceId(), branchSession.getClientId(), request, branchSession.isAT());
return response.getBranchStatus();
}

Expand All @@ -196,8 +197,9 @@ public BranchStatus branchRollback(GlobalSession globalSession, BranchSession br

protected BranchStatus branchRollbackSend(BranchRollbackRequest request, GlobalSession globalSession,
BranchSession branchSession) throws IOException, TimeoutException {

BranchRollbackResponse response = (BranchRollbackResponse) remotingServer.sendSyncRequest(
branchSession.getResourceId(), branchSession.getClientId(), request);
branchSession.getResourceId(), branchSession.getClientId(), request, branchSession.isAT());
return response.getBranchStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ public boolean unlock() throws TransactionException {
return true;
}

public boolean isAT() {
return this.getBranchType() == BranchType.AT;
}

public LockStatus getLockStatus() {
return lockStatus;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ static Stream<Arguments> xidAndBranchIdProviderForRollback() throws Exception {
public static class MockServerMessageSender implements RemotingServer {

@Override
public Object sendSyncRequest(String resourceId, String clientId, Object message) throws TimeoutException {
public Object sendSyncRequest(String resourceId, String clientId, Object message, boolean tryOtherApp)
throws TimeoutException {
if (message instanceof BranchCommitRequest) {
final BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
branchCommitResponse.setBranchStatus(BranchStatus.PhaseTwo_Committed);
Expand Down