-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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: fixed a bug that after branch deletion, there are still remaining branch lock #3056
Conversation
release 0.5.2
Release 0.6.1
release 0.7.1
release 0.8.0
[release] release 1.0.0
release 1.2.0
Codecov Report
@@ Coverage Diff @@
## develop #3056 +/- ##
=============================================
- Coverage 50.38% 50.37% -0.02%
+ Complexity 3090 3088 -2
=============================================
Files 600 600
Lines 19518 19519 +1
Branches 2410 2411 +1
=============================================
- Hits 9835 9832 -3
- Misses 8697 8698 +1
- Partials 986 989 +3
|
首先那个issue描述的不是pr中处理方式的问题。 |
@@ -246,10 +246,10 @@ public void addBranch(BranchSession branchSession) throws TransactionException { | |||
|
|||
@Override | |||
public void removeBranch(BranchSession branchSession) throws TransactionException { | |||
branchSession.unlock(); |
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.
If it is false, please throw exception, otherwise the problem will still exist.
以数据库存储方式为例,lifecycleListener.onRemoveBranch(this, branchSession)这里是删除分支事务的逻辑,之后进行branchSession.unlock()解锁的时候,如果出现数据库网络波动,或者sever挂了等情况,就会出现删除分支事务不删除锁的情况。 |
你说的没错,修改一下标题以bugfix: 开头,内容描述你pr改动的原因,简短易懂一些 |
好的,改了。 |
标题改成英文吧。 |
#2976 不需要放在标题,内容里有就可以里。 |
好的,加了 |
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.
LGTM
@@ -246,10 +246,12 @@ public void addBranch(BranchSession branchSession) throws TransactionException { | |||
|
|||
@Override | |||
public void removeBranch(BranchSession branchSession) throws TransactionException { | |||
if (!branchSession.unlock()) { | |||
throw new RuntimeException("Unlock branch lock failed!"); |
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.
throw TransactionException, not RuntimeException, otherwise, some forEach will break.
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.
done
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 for @wangliang181230
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
…ning branch lock (apache#3056)
…ning branch lock (apache#3056)
Ⅰ. Describe what this PR did
修改一个bug, 当二阶段回滚的时候,删除了分支事务之后,准备删除分支事务锁的时候突然由于某些原因造成删除锁失败。那么这个锁数据将会一直存在,造成之后的事务无法获取此锁。
fix a bug, when the branch phase two rollbacked, and the branch info had been delete from the branch_table. But
then delete the branch lock from the table of lock_table, an error occurred which cause the branch lock delete failed.
Then the branch lock will be always in the table, and cause new transactions could not get this lock.
Ⅱ. Does this pull request fix one issue?
fixes #2976
Ⅲ. Why don't you add test cases (unit test/integration test)?
This problem occurs only in exceptional cases, test cases are difficult to write
此问题在某些特殊情况下才会发生,用例不好写。
Ⅳ. Describe how to verify it
My test is to manually throw an exception directly in the unlock and delete branch transaction table。
我的测试方式是在解锁和删除分支事务表直接手动抛出异常。
branchSession.unlock();
// throw an exception
for (SessionLifecycleListener lifecycleListener : lifecycleListeners) {
lifecycleListener.onRemoveBranch(this, branchSession);
}
Ⅴ. Special notes for reviews
问题发生的原因就是删除了分支事务表,但是锁没有删掉。如果两个都还在,那么重试的时候会通过分支事务数据删除该锁。所以问题的关键在于锁需要先于分支事务删除。
因为GlobalSession.removeBranch()仅发生在二阶段相应的分支已经完成seata-server的回滚和响应请求之后。也就是说此时RM的相应操作已经完成,比如删除undoLog,或者设置undoLog状态为完成,异常等等。所以RM的任务已经完成了,此时已经可以删除锁了。所以即使在删除锁后分支事务表还在,也没有事情,当他发起重试的时候,RM已经完成了操作,不会重复再次执行一篇。