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

feat: saga's tcc-like mode #651

Open
wants to merge 7 commits into
base: feature/saga
Choose a base branch
from

Conversation

kaori-seasons
Copy link
Contributor

@kaori-seasons kaori-seasons commented Jan 24, 2024

BackGround

The seata saga mode will support multiple usage methods in the future.

  1. State machine json: json
  2. Streaming orchestration: saga.task(xxx).build().start()
  3. TCC-like mode

The saga in seata java is implemented based on the state machine.
1) 2) are all implemented based on the state machine engine, 3) can exist independently of the state machine engine. It is completely independent coding of the business and does not require understanding of the state machine process.

The intention of this PR is to support 3) mode

Equivalent to the Saga state machine mode (1), no matter if the user writes a transaction operation, it will always only include ordinary transaction operations based on the transaction type (ServiceTask, choice action)
And compensation transaction operation (compensation), so the tcc-like mode is equivalent to the degraded version of tcc, without the prepare process.
In the first stage, positive/negative transaction operations are directly submitted without waiting. In the second stage, transaction compensation operations will only occur during rollback.

What this PR does:

  • 1. The saga branch transaction is also divided into two phases, similar to tcc. The difference is that when the saga transaction is submitted, the first phase is submitted directly.
    There is no need for two-phase submission, which means that the two-phase commit of tcc is degraded and will only be executed when the transaction needs to be rolled back.
    The second phase compensates the transaction data submitted in the first phase.
  • 2. Added saga annotation CompensationBusinessAction,
    Add this annotation to the branch transaction service interface or implementation that needs to use the saga mode.
  • 3. Because it is similar to the tcc process, the saga-annotation mode reuses most of the tcc process.
    Special aspects have been rewritten.
  • 4. Compared with the state machine, the saga annotation mode does not currently support the forward retry capability.
  • 5. Anti-suspension can be reused with tcc anti-suspension.
  • 6. Comparing the action information with tcc, the actions of tcc are prepare, commit, rollback,
    saga is action, compensationAction
  • 7.Improve testing

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@ptyin
Copy link
Member

ptyin commented Jan 24, 2024

Have we ever discussed about this feature anywhere? I think we should launch a review meeting to discuss about it.

@ptyin
Copy link
Member

ptyin commented Jan 24, 2024

BTW, code comments should be re-written in English. Plz check.

@kaori-seasons
Copy link
Contributor Author

kaori-seasons commented Jan 28, 2024

Have we ever discussed about this feature anywhere? I think we should launch a review meeting to discuss about it.

@ptyin
Sorry, this is my oversight. This requirement was discussed with @wt-better, but was not recorded in the meeting or issue. I will try my best to take time to prepare for this design discussion at the next weekly meeting to achieve consensus.

Copy link

sonarcloud bot commented Oct 27, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
19.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@@ -18,6 +18,7 @@
package client

import (
"github.com/seata/seata-go/pkg/rm/saga"
Copy link
Contributor

Choose a reason for hiding this comment

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

格式不对,挪到第三课 import 里面

@@ -0,0 +1,45 @@
package fence

import (
Copy link
Contributor

Choose a reason for hiding this comment

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

格式太乱了

@@ -0,0 +1,166 @@
package handler

import (
Copy link
Contributor

Choose a reason for hiding this comment

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

format 下,乱

@@ -0,0 +1,216 @@
package saga

import (
Copy link
Contributor

Choose a reason for hiding this comment

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

format 下,乱

@@ -0,0 +1,216 @@
package saga
Copy link
Contributor

Choose a reason for hiding this comment

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

代码加下 apache license header

@@ -0,0 +1,204 @@
package saga

import (
Copy link
Contributor

Choose a reason for hiding this comment

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

1 添加 apache license header;
2 format import 代码块

@@ -0,0 +1,281 @@
package saga
Copy link
Contributor

Choose a reason for hiding this comment

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

1 添加 apache license header;
2 format import 代码块

@@ -0,0 +1,221 @@
package rm
Copy link
Contributor

Choose a reason for hiding this comment

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

1 添加 apache license header;
2 format import 代码块
3 注释不要用中文

@@ -0,0 +1,16 @@
package testdata
Copy link
Contributor

Choose a reason for hiding this comment

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

1 添加 apache license header;
2 format import 代码块

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.

4 participants