Skip to content
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: Improve the performance of global commit and global rollback #4270

Merged
merged 6 commits into from
Jan 19, 2022

Conversation

pengten
Copy link
Contributor

@pengten pengten commented Jan 6, 2022

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

When the global commit or rollback is performed, the branch transaction enters the thread pool for asynchronous deletion after the second-phase delivery is successful.

全局提交或回滚时,分支事务二阶段下发成功后进入线程池中异步删除。

Ⅱ. Does this pull request fix one issue?

fixes #3750

Ⅲ. Why don't you add test cases (unit test/integration test)?

先review方案

Ⅳ. Describe how to verify it

The transaction is committed and rolled back normally, the TM receives the response before the branch transaction is deleted, and the branch transaction is deleted after the asynchronous thread is executed.

正常提交和回滚事务,TM在分支事务删除前收到响应,异步线程执行后分支事务被删除。

Ⅴ. Special notes for reviews

@funky-eyes
Copy link
Contributor

异步删除globalsession目前已经实现了(rollback下异步删除已经有pr),当同步二阶段完成的时候,end是通过retrycommit/retryrollback的定时线程去删除的,已经避免了changestatus和delete lock和delete globalsession的情况。
目前我们的需求是异步删除branch,比如一个branch的二阶段下发已经结束了,他可以丢到异步线程里删除,但是这样要保证globalsession的删除一定要晚于所有branch的删除。
至于最后的2个问题:
1.先unlock,再丢到异步线程里删
全局提交或回滚时,当碰到执行失败的分支时,前面执行成功的分支数据做批量同步删除,然后由TM发起重试。
2.我怀疑你理解错了,如果遇到失败的分支,将前面执行成功的branch批量删除就好了,这里只是要求等到endglobalsession之前进行统计哪些成功的,进行批量异步删掉,但是这里其实有个幂等问题,如果到endglobalsession的时候还没删tc就宕机了,那么tc将会重试这些本来二阶段已经执行完成的分支事务

@pengten
Copy link
Contributor Author

pengten commented Jan 6, 2022

1.先unlock,再丢到异步线程里删 全局提交或回滚时,当碰到执行失败的分支时,前面执行成功的分支数据做批量同步删除,然后由TM发起重试。

  1. 这里为什么不做异步删除呢?
  2. 目前TM在commit失败后,会定时向TC询问事务状态;但是貌似没有重新发起commit的重试机制? 我只在TC找到了retryCommit

@pengten
Copy link
Contributor Author

pengten commented Jan 6, 2022

@a364176773 我理解是不是应该这样做:

  • 分支事务提交和回滚后,先unlock,然后扔入专用的线程池。 (若线程池队列已满,则同步删除)
  • globalsession end时,检查如果所有分支都删除成功后才进行delete globalsession。

至于幂等问题,需要业务方自行保证。

@funky-eyes
Copy link
Contributor

1.先unlock,再丢到异步线程里删 全局提交或回滚时,当碰到执行失败的分支时,前面执行成功的分支数据做批量同步删除,然后由TM发起重试。

  1. 这里为什么不做异步删除呢?
  2. 目前TM在commit失败后,会定时向TC询问事务状态;但是貌似没有重新发起commit的重试机制? 我只在TC找到了retryCommit

发起后是tc重试,不是tm,做异步删除,我好像没说不做吧

@funky-eyes
Copy link
Contributor

@a364176773 我理解是不是应该这样做:

  • 分支事务提交和回滚后,先unlock,然后扔入专用的线程池。 (若线程池队列已满,则同步删除)
  • globalsession end时,检查如果所有分支都删除成功后才进行delete globalsession。

至于幂等问题,需要业务方自行保证。

执行完一个branch直接异步删即可

@pengten pengten force-pushed the develop branch 4 times, most recently from 8d4713a to d7bb4a1 Compare January 7, 2022 13:31
@codecov-commenter
Copy link

codecov-commenter commented Jan 7, 2022

Codecov Report

Merging #4270 (0703565) into develop (11d3478) will decrease coverage by 0.02%.
The diff coverage is 38.75%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #4270      +/-   ##
=============================================
- Coverage      48.54%   48.52%   -0.03%     
- Complexity      3793     3798       +5     
=============================================
  Files            724      725       +1     
  Lines          24240    24305      +65     
  Branches        2971     2984      +13     
=============================================
+ Hits           11768    11794      +26     
- Misses         11230    11261      +31     
- Partials        1242     1250       +8     
Impacted Files Coverage Δ
...ava/io/seata/core/constants/ConfigurationKeys.java 0.00% <ø> (ø)
...ta/spring/boot/autoconfigure/StarterConstants.java 100.00% <ø> (ø)
...configure/SeataServerEnvironmentPostProcessor.java 0.00% <0.00%> (ø)
...ava/io/seata/server/transaction/saga/SagaCore.java 2.72% <0.00%> (+0.11%) ⬆️
...e/properties/server/session/SessionProperties.java 25.00% <25.00%> (ø)
.../java/io/seata/server/coordinator/DefaultCore.java 51.74% <25.00%> (-0.59%) ⬇️
...in/java/io/seata/server/session/SessionHelper.java 60.86% <37.50%> (-7.06%) ⬇️
...o/seata/server/coordinator/DefaultCoordinator.java 48.91% <48.88%> (-0.01%) ⬇️
...n/src/main/java/io/seata/common/util/IdWorker.java 77.08% <0.00%> (-6.25%) ⬇️

@pengten pengten force-pushed the develop branch 3 times, most recently from f5948f7 to 5c674db Compare January 9, 2022 07:08
@pengten
Copy link
Contributor Author

pengten commented Jan 10, 2022

@a364176773 done

@pengten pengten force-pushed the develop branch 2 times, most recently from cfe8ee5 to ab08e2b Compare January 11, 2022 02:40
Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 补充一下change log,在changes文件夹里有中英两版1.5.0.md文件,补充pr信息和作者信息

@funky-eyes funky-eyes added this to the 1.5.0 milestone Jan 17, 2022
@pengten
Copy link
Contributor Author

pengten commented Jan 17, 2022

LGTM 补充一下change log,在changes文件夹里有中英两版1.5.0.md文件,补充pr信息和作者信息

已补充pr信息,作者信息之前已有。

Copy link
Contributor

@wangliang181230 wangliang181230 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wangliang181230 wangliang181230 merged commit 21c103d into apache:develop Jan 19, 2022
*/
private static final Configuration CONFIG = ConfigurationFactory.getInstance();

private static final Boolean ENABLE_BRANCH_ASYNC_REMOVE = CONFIG.getBoolean(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default value should be false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Summer2021] Improve the performance of global commit and global rollback
5 participants