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 561740593a optimize: report the tcc fence transaction isolation level (#6768) 561740593a is described below commit 561740593a3115d241eb7cb151558c479543f0a6 Author: iAmClever <158091...@qq.com> AuthorDate: Thu Aug 22 17:20:08 2024 +0800 optimize: report the tcc fence transaction isolation level (#6768) --- changes/en-us/2.x.md | 1 + changes/zh-cn/2.x.md | 1 + .../java/org/apache/seata/common/Constants.java | 5 +++ .../interceptor/TccActionInterceptorHandler.java | 16 ++++++++ .../org/apache/seata/rm/tcc/utils/MethodUtils.java | 47 ++++++++++++++++++++++ 5 files changed, 70 insertions(+) diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index 081e0757d8..bbc5cb504a 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -59,6 +59,7 @@ Add changes here for all PR submitted to the 2.x branch. - [[#6755](https://github.com/apache/incubator-seata/pull/6755)] optimize namingserver code logic - [[#6763](https://github.com/apache/incubator-seata/pull/6763)] optimize NacosConfiguration singleton reload - [[#6761](https://github.com/apache/incubator-seata/pull/6761)] optimize the namingserver code to improve readability +- [[#6768](https://github.com/apache/incubator-seata/pull/6768)] report the tcc fence transaction isolation level ### refactor: diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md index 0d7436294d..0b98b0fd8a 100644 --- a/changes/zh-cn/2.x.md +++ b/changes/zh-cn/2.x.md @@ -60,6 +60,7 @@ - [[#6755](https://github.com/apache/incubator-seata/pull/6755)] 优化namingserver代码逻辑 - [[#6763](https://github.com/apache/incubator-seata/pull/6763)] 优化 NacosConfiguration 单例加载 - [[#6761](https://github.com/apache/incubator-seata/pull/6761)] 提升namingserver manager代码可读性 +- [[#6768](https://github.com/apache/incubator-seata/pull/6768)] 上报tcc fence事务隔离级别 ### refactor: diff --git a/common/src/main/java/org/apache/seata/common/Constants.java b/common/src/main/java/org/apache/seata/common/Constants.java index 1c715b2dff..d3a0ab512d 100644 --- a/common/src/main/java/org/apache/seata/common/Constants.java +++ b/common/src/main/java/org/apache/seata/common/Constants.java @@ -101,6 +101,11 @@ public interface Constants { */ String TX_ACTION_CONTEXT = "actionContext"; + /** + * isolation + */ + String TX_ISOLATION = "isolation"; + /** * default charset name */ diff --git a/tcc/src/main/java/org/apache/seata/rm/tcc/interceptor/TccActionInterceptorHandler.java b/tcc/src/main/java/org/apache/seata/rm/tcc/interceptor/TccActionInterceptorHandler.java index acf84663c1..dc6a9d3424 100644 --- a/tcc/src/main/java/org/apache/seata/rm/tcc/interceptor/TccActionInterceptorHandler.java +++ b/tcc/src/main/java/org/apache/seata/rm/tcc/interceptor/TccActionInterceptorHandler.java @@ -38,7 +38,9 @@ import org.apache.seata.integration.tx.api.interceptor.SeataInterceptorPosition; import org.apache.seata.integration.tx.api.interceptor.TwoPhaseBusinessActionParam; import org.apache.seata.integration.tx.api.interceptor.handler.AbstractProxyInvocationHandler; import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; +import org.apache.seata.rm.tcc.utils.MethodUtils; import org.slf4j.MDC; +import org.springframework.transaction.annotation.Transactional; import static org.apache.seata.common.ConfigurationKeys.TCC_ACTION_INTERCEPTOR_ORDER; @@ -82,6 +84,7 @@ public class TccActionInterceptorHandler extends AbstractProxyInvocationHandler } try { TwoPhaseBusinessActionParam businessActionParam = createTwoPhaseBusinessActionParam(businessAction); + initTransactionalAnnotationContext(method, targetBean, businessActionParam.getBusinessActionContext()); //Handler the TCC Aspect, and return the business result return actionInterceptorHandler.proceed(method, invocation.getArguments(), xid, businessActionParam, invocation::proceed); @@ -99,6 +102,19 @@ public class TccActionInterceptorHandler extends AbstractProxyInvocationHandler return invocation.proceed(); } + /** + * Initializes the transaction annotation context + * @param method the method + * @param targetBean the target bean + * @param businessActionContext the business action context + */ + private void initTransactionalAnnotationContext(Method method, Object targetBean, Map<String, Object> businessActionContext) { + Transactional transactionalAnnotation = MethodUtils.getTransactionalAnnotationByMethod(method, targetBean); + if (transactionalAnnotation != null) { + businessActionContext.put(Constants.TX_ISOLATION, transactionalAnnotation.isolation().value()); + } + } + private Annotation parseAnnotation(Method methodKey) throws NoSuchMethodException { Annotation result = parseAnnotationCache.computeIfAbsent(methodKey, method -> { Annotation twoPhaseBusinessAction = method.getAnnotation(getAnnotationClass()); diff --git a/tcc/src/main/java/org/apache/seata/rm/tcc/utils/MethodUtils.java b/tcc/src/main/java/org/apache/seata/rm/tcc/utils/MethodUtils.java new file mode 100644 index 0000000000..a3c6a758e6 --- /dev/null +++ b/tcc/src/main/java/org/apache/seata/rm/tcc/utils/MethodUtils.java @@ -0,0 +1,47 @@ +/* + * 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.rm.tcc.utils; + +import java.lang.reflect.Method; + +import org.apache.seata.common.exception.ShouldNeverHappenException; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.transaction.annotation.Transactional; + + + +public class MethodUtils { + /** + * Retrieve the Transactional annotation of a business method + * @param interfaceMethod interface method object + * @param targetTCCBean target tcc bean + * @return the @Transactional annotation + */ + public static Transactional getTransactionalAnnotationByMethod(Method interfaceMethod, Object targetTCCBean) { + String methodName = interfaceMethod.getName(); + Class<?>[] parameterTypes = interfaceMethod.getParameterTypes(); + + Class<?> clazz = targetTCCBean.getClass(); + Method implementationMethod; + try { + implementationMethod = clazz.getMethod(methodName, parameterTypes); + } catch (NoSuchMethodException e) { + throw new ShouldNeverHappenException(e); + } + return AnnotatedElementUtils.findMergedAnnotation(implementationMethod, Transactional.class); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org