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

feature: saga support parallel execution with multiple states #4349

Closed

Conversation

anselleeyy
Copy link
Contributor

@anselleeyy anselleeyy commented Jan 27, 2022

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

Saga 新增并发State节点,支持配置多个需要并发执行的state,并发执行的State支持 ServiceTask、SubStateMachine、ScriptTask,整体能力参考Loop循环属性的实现

image

  • 新增统一的并发处理层 (ParallelStateHandler) 用于对Parallel的节点类型,统一进行并发任务的预处理和任务分发,通过信号量 (Semaphore) 进行并发控制
  • 并发执行过程中,每一个节点都会有一个索引(取决于branches的配置顺序),比如:FirstState-parallel-0-branchStateName,便于在重试或补偿时,恢复上下文使用
  • 新增 ParallelTaskInterceptor,主要用于对并发执行时的异常后置处理
    • postprocess:
      • 异常时,记录 exp 信息到上下文中,同时释放信号量,并置全局并发状态为失败(failEnd)
  • 并发节点本身不支持配置循环属性
    • 希望使用循环属性时,可通过在分支节点上配置Loop属性,来达到对部分或所有的并发分支节点进行循环执行的诉求

在seata-saga-designer中,考虑到设计及简易性,增加了ParallelStart和ParallelEnd来标识并发的开始与结束,由DesignerJsonTransformer来统一处理并发场景下的json转换,设计器的demo可以参考下图

image

Ⅱ. Does this pull request fix one issue?

fixes #4351

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

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@anselleeyy
Copy link
Contributor Author

@long187 help to review this feature

@long187
Copy link
Contributor

long187 commented Jan 27, 2022

考虑一下设计器怎么画并发任务

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2022

Codecov Report

Merging #4349 (c2cdc04) into develop (4c88984) will increase coverage by 0.11%.
The diff coverage is 62.02%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #4349      +/-   ##
=============================================
+ Coverage      48.67%   48.79%   +0.11%     
- Complexity      3973     3989      +16     
=============================================
  Files            733      735       +2     
  Lines          25155    25229      +74     
  Branches        3085     3099      +14     
=============================================
+ Hits           12245    12310      +65     
- Misses         11596    11599       +3     
- Partials        1314     1320       +6     
Impacted Files Coverage Δ
.../saga/statelang/domain/impl/ParallelStateImpl.java 0.00% <0.00%> (ø)
...statelang/parser/impl/ParallelTaskStateParser.java 6.25% <6.25%> (ø)
...tatelang/parser/utils/DesignerJsonTransformer.java 63.15% <88.67%> (+8.49%) ⬆️
...eata/saga/statelang/parser/StateParserFactory.java 92.30% <100.00%> (+0.64%) ⬆️

... and 3 files with indirect coverage changes

@lgtm-com
Copy link

lgtm-com bot commented Feb 9, 2022

This pull request fixes 1 alert when merging 1616cea into b62f03e - view on LGTM.com

fixed alerts:

  • 1 for Dereferenced variable may be null

@slievrly slievrly added mode: SAGA SAGA transaction mode module/saga saga module labels Feb 10, 2022
@long187
Copy link
Contributor

long187 commented Feb 17, 2022

设计器中,ParallelStart和ParallelEnd 用 菱形并换个颜色。可以参考bpmn是图形

@long187
Copy link
Contributor

long187 commented Feb 17, 2022

设计器,编译命令npm install在有些版本的npm好像有问题,可以加上--legacy-peer-deps参数解决,并npm build有也版本也不识别要改成npm run install,在设计器的README上加一下吧。

@funky-eyes funky-eyes added this to the 2.0.0 milestone Feb 21, 2022
@lgtm-com
Copy link

lgtm-com bot commented Feb 27, 2022

This pull request fixes 1 alert when merging cfe2a2b into 4622746 - view on LGTM.com

fixed alerts:

  • 1 for Dereferenced variable may be null

@lgtm-com
Copy link

lgtm-com bot commented Mar 1, 2022

This pull request fixes 1 alert when merging c2cdc04 into 4c88984 - view on LGTM.com

fixed alerts:

  • 1 for Dereferenced variable may be null

@CLAassistant
Copy link

CLAassistant commented Dec 12, 2022

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ a364176773
❌ anselleeyy
You have signed the CLA already but the status is still pending? Let us recheck it.

@wt-better
Copy link
Contributor

探讨下哈,以ParallelState方式标记并行,用户需要再JSON里面声明ParallelStateStart,我理解是否可以在State级别支持多Next节点,框架内部构建多个水平执行数,相同层级的并发执行,这样对用户更加友好。

@anselleeyy
Copy link
Contributor Author

探讨下哈,以ParallelState方式标记并行,用户需要再JSON里面声明ParallelStateStart,我理解是否可以在State级别支持多Next节点,框架内部构建多个水平执行数,相同层级的并发执行,这样对用户更加友好。

@wt-better ParallelStart和ParallelEnd节点,主要是考虑到在设计器中画并发任务时,能够清晰看到并发任务的开始和结束;在实际的json配置文件和并发处理的代码实现中,并不存在这2个节点

@wt-better
Copy link
Contributor

wt-better commented Mar 13, 2023

  • 并行节点 多loop 分支节点的 loopResult可能会覆盖

  • 并行节点 多分支,单loop分支_is_loop_state_上下文传递,可能会导致非loop节点route null问题

  • loop实现目前是死等,可以优化成事件处理,loop执行完成之后push next

  • 并行节点里面如果还有并行,需要判断下上下文传递这里,是否支持

@wt-better
Copy link
Contributor

thank for you request, and this feature was designed and implementation by https://github.com/seata/seata/pull/5847 .
parallel was design fork-join and fix above question.

@wt-better wt-better closed this Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mode: SAGA SAGA transaction mode module/saga saga module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: saga support parallel execution with multiple states
7 participants