-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
bugfix: add three tcc fence interceptors to fix tcc fence deadlock ex… #6706
Open
iAmClever
wants to merge
5
commits into
apache:2.x
Choose a base branch
from
iAmClever:clever_fix_tcc_deadlock_v2
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3447a5d
bugfix: add three tcc fence interceptors to fix tcc fence deadlock ex…
d56a07e
bugfix: add three tcc fence interceptors to fix tcc fence deadlock ex…
8c229c1
Merge branch '2.x' into clever_fix_tcc_deadlock_v2
iAmClever feda964
bugfix: add three tcc fence interceptors to fix tcc fence deadlock ex…
db2073e
Merge branch 'clever_fix_tcc_deadlock_v2' of https://github.com/iAmCl…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
core/src/main/java/org/apache/seata/core/model/TccLocalTxActive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.model; | ||
|
||
/** | ||
* Identifies whether tcc transactions are activated on the business side | ||
*/ | ||
public enum TccLocalTxActive { | ||
|
||
/** | ||
* The tcc transaction is not activated on the service side. | ||
*/ | ||
UN_ACTIVE(0), | ||
|
||
/** | ||
* The tcc transaction is activated on the service side. | ||
*/ | ||
ACTIVE(1); | ||
|
||
|
||
private final int code; | ||
|
||
TccLocalTxActive(int code) { | ||
this.code = code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,6 @@ | |
*/ | ||
package org.apache.seata.integration.tx.api.interceptor; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.UndeclaredThrowableException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.seata.common.Constants; | ||
import org.apache.seata.common.exception.FrameworkException; | ||
import org.apache.seata.common.exception.SkipCallbackWrapperException; | ||
|
@@ -42,6 +34,14 @@ | |
import org.slf4j.LoggerFactory; | ||
import org.slf4j.MDC; | ||
|
||
import javax.annotation.Nonnull; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. java的包应该在顶层 |
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.UndeclaredThrowableException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Handler the Tx Participant Aspect : Setting Context, Creating Branch Record | ||
* | ||
|
@@ -53,16 +53,17 @@ public class ActionInterceptorHandler { | |
/** | ||
* Handler the Tx Aspect | ||
* | ||
* @param method the method | ||
* @param arguments the arguments | ||
* @param invocation the invocation wrapper | ||
* @param xid the xid | ||
* @param businessActionParam the business action params | ||
* @param targetCallback the target callback | ||
* @return the business result | ||
* @throws Throwable the throwable | ||
*/ | ||
public Object proceed(Method method, Object[] arguments, String xid, TwoPhaseBusinessActionParam businessActionParam, | ||
Callback<Object> targetCallback) throws Throwable { | ||
public Object proceed(InvocationWrapper invocation, String xid, TwoPhaseBusinessActionParam businessActionParam) throws Throwable { | ||
Method method = invocation.getMethod(); | ||
Object targetTCCBean = invocation.getProxy(); | ||
Object[] arguments = invocation.getArguments(); | ||
Callback<Object> targetCallback = invocation::proceed; | ||
//Get action context from arguments, or create a new one and then reset to arguments | ||
BusinessActionContext actionContext = getOrCreateActionContextAndResetToArguments(method.getParameterTypes(), arguments); | ||
|
||
|
@@ -87,11 +88,13 @@ public Object proceed(Method method, Object[] arguments, String xid, TwoPhaseBus | |
try { | ||
//share actionContext implicitly | ||
BusinessActionContextUtil.setContext(actionContext); | ||
RootContext.bindBranchId(branchId); | ||
RootContext.bindResourceId(actionName); | ||
|
||
if (businessActionParam.getUseCommonFence()) { | ||
try { | ||
// Use common Fence, and return the business result | ||
return DefaultCommonFenceHandler.get().prepareFence(xid, Long.valueOf(branchId), actionName, targetCallback); | ||
return DefaultCommonFenceHandler.get().prepareFence(method, targetTCCBean, xid, Long.valueOf(branchId), actionName, targetCallback); | ||
} catch (SkipCallbackWrapperException | UndeclaredThrowableException e) { | ||
Throwable originException = e.getCause(); | ||
if (originException instanceof FrameworkException) { | ||
|
@@ -104,6 +107,8 @@ public Object proceed(Method method, Object[] arguments, String xid, TwoPhaseBus | |
return targetCallback.execute(); | ||
} | ||
} finally { | ||
RootContext.unbindBranchId(); | ||
RootContext.unbindResourceId(); | ||
try { | ||
//to report business action context finally if the actionContext.getUpdated() is true | ||
BusinessActionContextUtil.reportContext(actionContext); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rootcontext不应该用来存放这些数据
Rootcontext should not be used to store this data