-
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
optimize: Prohibit registration of TCC resources with the same name #6091
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## 2.x #6091 +/- ##
============================================
- Coverage 48.94% 48.91% -0.03%
- Complexity 4775 4779 +4
============================================
Files 913 914 +1
Lines 31710 31728 +18
Branches 3827 3829 +2
============================================
Hits 15521 15521
- Misses 14653 14661 +8
- Partials 1536 1546 +10
|
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.
LGTM
please resolve conflicts |
Class<?> newResourceClass = newResource.getTargetBean().getClass(); | ||
Class<?> oldResourceClass = oldResource.getTargetBean().getClass(); | ||
if (!newResourceClass.isAssignableFrom(oldResourceClass) | ||
&& !oldResourceClass.isAssignableFrom(newResourceClass)) { |
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.
只要存在相同的resourceId
,是不是可以直接抛出异常?同一个 TCCResource
应该不会注册多次吧?
如果担心重复注册时误判导致抛出该异常,那你可以判断一下新老资源是否为同一个实例。
Is it possible to throw an exception as long as the same resourceId
exists? The same TCCResource
should not be registered multiple times, right?
If you are worried about duplicate registration, just check if the registered resource and the new resource are the same object.
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.
只要存在相同的
resourceId
,是不是可以直接抛出异常?同一个TCCResource
应该不会注册多次吧? 如果担心重复注册时误判导致抛出该异常,那你可以判断一下新老资源是否为同一个实例。Is it possible to throw an exception as long as the same
resourceId
exists? The sameTCCResource
should not be registered multiple times, right? If you are worried about duplicate registration, just check if the registered resource and the new resource are the same object.
@funky-eyes 之前说过有可能在父子类的情况下注册多次
@funky-eyes said before it's possible to register multiple times in the case of parent-child classes
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.
只判断是否父子关系,是无法判断注册进来的资源内部的属性。如果两个资源的属性不一致,那么它们的逻辑也很可能是不一样的,很可能是用户自己重复定义了 resourceId
。
Only determining whether there is a parent-child relationship cannot determine the internal attributes of the registered resources.If the value of there fields are inconsistent, their logic is also likely to be different, and it is likely that the user has repeatedly defined the resourceId
.
Class<?> oldResourceClass = oldResource.getTargetBean().getClass(); | ||
if (!newResourceClass.isAssignableFrom(oldResourceClass) | ||
&& !oldResourceClass.isAssignableFrom(newResourceClass)) { | ||
throw new ShouldNeverHappenException(String.format("Same TCC resource name between class <%s> and class <%s>, should be unique", |
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.
异常类型换一个吧。ShouldNeverHappenException
只有在 前置操作未执行过
时才使用。
但这里明显不是因为前置操作未执行引起的。
Change the exception type. The ShouldNeverHappenException
is only used when the preceding operation has not been executed.
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.
Change the exception type. The
ShouldNeverHappenException
is only used when the preceding operation has not been executed.异常类型换一个吧。
ShouldNeverHappenException
只有在前置操作未执行过
时才使用。 但这里明显不是因为前置操作未执行引起的。
我查看了几处使用示例,比如
I looked at a couple of example uses, such as
看起来好像这个异常普遍用在 发生系统规则之外情况 的时候?或者说你觉得哪种异常更适合被用在这里呢
It seems like this exception is commonly used when something happens outside of the system rules? Or which exception do you think would be more appropriate to use here?
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.
你可以自定义一个异常类。
You can customize an exception class.
if (oldResource != null) { | ||
Class<?> newResourceClass = newResource.getTargetBean().getClass(); | ||
Class<?> oldResourceClass = oldResource.getTargetBean().getClass(); | ||
if (newResourceClass != oldResourceClass) { |
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 targetBean, not the targetBeanClass.
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.
LGTM
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.
From the perspective of internal practical experience, share my suggestions:
- The resource name should be globally unique.
- Annotations to the interface, do not allow multiple implementation classes, single responsibility.
你的意思是将定义TCC资源的注解直接移动到接口上而不是某个方法上吗? |
LGTM |
common/src/main/java/io/seata/common/exception/RepeatRegistrationException.java
Outdated
Show resolved
Hide resolved
LGTM |
d137200
There are some conflicting files, please fix. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## 2.x #6091 +/- ##
============================================
+ Coverage 48.95% 48.98% +0.02%
- Complexity 4778 4781 +3
============================================
Files 915 916 +1
Lines 31892 31910 +18
Branches 3853 3855 +2
============================================
+ Hits 15613 15631 +18
+ Misses 14720 14718 -2
- Partials 1559 1561 +2
|
Thanks for the heads up, I have resolved the conflict |
I can't merge this pr due to another conflict, please fix it. |
Ⅰ. Describe what this PR did
Check when registering TCC resources, if a resource with the same name already exists, determine if it is a parent-child relationship, if not, prevent the application from starting by throwing an exception.
注册TCC资源时进行检查,如果已经存在相同名称的资源,判断是否是父子类关系,如果不是,通过抛出异常的方式阻止应用启动
Ⅱ. Does this pull request fix one issue?
#6088
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews