-
Notifications
You must be signed in to change notification settings - Fork 8.9k
optimize: global transaction support non-private methods #7867
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
base: 2.x
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x #7867 +/- ##
============================================
+ Coverage 71.07% 71.10% +0.02%
Complexity 797 797
============================================
Files 1294 1294
Lines 49528 49540 +12
Branches 5873 5877 +4
============================================
+ Hits 35202 35225 +23
+ Misses 11418 11411 -7
+ Partials 2908 2904 -4
🚀 New features to boost your workflow:
|
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.
Pull request overview
This PR optimizes global transaction support to include non-private methods by changing the reflection API used to discover annotated methods. The change allows protected and package-private methods with @GlobalTransactional or @GlobalLock annotations to be proxied, while explicitly excluding private methods which cannot be proxied anyway.
Key changes:
- Switched from
getMethods()togetDeclaredMethods()to access non-public methods - Added explicit filtering to exclude private methods from proxy consideration
- Updated both English and Chinese changelogs
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java | Changed reflection API from getMethods() to getDeclaredMethods() and added private method filtering |
| changes/zh-cn/2.x.md | Added Chinese changelog entry for PR #7867 |
| changes/en-us/2.x.md | Added English changelog entry for PR #7867 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/MethodImpl.java
Outdated
Show resolved
Hide resolved
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...he/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Show resolved
Hide resolved
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/MethodImpl.java
Outdated
Show resolved
Hide resolved
...he/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
Outdated
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
...apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
Outdated
Show resolved
Hide resolved
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java:122
- The current implementation processes public methods twice - once through
getMethods()(lines 92-105) and again throughgetDeclaredMethods()(lines 106-122). While theHashSetprevents duplicate entries, this creates unnecessary overhead by checking annotations on the same public methods twice. Consider optimizing by either using onlygetDeclaredMethods()with modifier checks, or tracking which methods have already been processed to avoid redundant annotation lookups.
Method[] methods = clazz.getMethods();
for (Method method : methods) {
trxAnno = method.getAnnotation(GlobalTransactional.class);
if (trxAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
GlobalLock lockAnno = method.getAnnotation(GlobalLock.class);
if (lockAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
}
Method[] declaredMethods = clazz.getDeclaredMethods();
for (Method method : declaredMethods) {
if (Modifier.isPrivate(method.getModifiers())) {
continue;
}
trxAnno = method.getAnnotation(GlobalTransactional.class);
if (trxAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
GlobalLock lockAnno = method.getAnnotation(GlobalLock.class);
if (lockAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
}
integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java:122
- The annotation processing logic for
GlobalLockandGlobalTransactionalis duplicated in two separate loops (lines 92-105 and lines 106-122). This duplication makes the code harder to maintain and increases the risk of inconsistencies if changes are needed in the future. Consider extracting the common annotation checking logic into a helper method to reduce duplication.
GlobalLock lockAnno = method.getAnnotation(GlobalLock.class);
if (lockAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
}
Method[] declaredMethods = clazz.getDeclaredMethods();
for (Method method : declaredMethods) {
if (Modifier.isPrivate(method.getModifiers())) {
continue;
}
trxAnno = method.getAnnotation(GlobalTransactional.class);
if (trxAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
GlobalLock lockAnno = method.getAnnotation(GlobalLock.class);
if (lockAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private static final Logger LOGGER = LoggerFactory.getLogger(NonPrivateMethodTestClass.class); | ||
|
|
||
| @GlobalTransactional(timeoutMills = 300000) | ||
| String dftMethod() { |
Copilot
AI
Dec 19, 2025
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.
The method name dftMethod uses an unclear abbreviation. Consider renaming to defaultMethod or packagePrivateMethod to better communicate that this method has package-private (default) access visibility. This would make the test class more self-documenting and easier to understand.
| String dftMethod() { | |
| String defaultMethod() { |
| } | ||
|
|
||
| @Test | ||
| void shouldExcludePrivateMethodsFromProxy() throws Exception { |
Copilot
AI
Dec 19, 2025
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.
The test name shouldExcludePrivateMethodsFromProxy doesn't fully capture what the test verifies. The test actually verifies that non-private methods (default and protected) ARE included while private methods are excluded. Consider a more descriptive name like shouldIncludeNonPrivateMethodsAndExcludePrivateMethodsFromProxy or shouldProxyOnlyNonPrivateMethods to better communicate the complete behavior being tested.
| void shouldExcludePrivateMethodsFromProxy() throws Exception { | |
| void shouldProxyOnlyNonPrivateMethods() throws Exception { |
Ⅰ. Describe what this PR did
Ⅱ. Does this pull request fix one issue?
fixes: #7770
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews