This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

What are TCC transactions

TCC is short for Try, Confirm, and Cancel. Each branch transaction must perform three operations: preprocessing Try: perform service check and resource reservation confirmation Confirm: perform service confirmation Cancel: perform rollback

TM will first initiate the try operation of all branch transactions. If the try operation of any branch transaction fails, TM will initiate the Cancel operation of all branch transactions. If the try operation succeeds, TM will initiate the confirm operation of all branch transactions. TM will retry.

TCC is divided into three phases:

1) In the Try phase, services are checked (consistency) and resources are reserved (isolation). 2) Confirm phase is to Confirm submission. In the Try phase, all branch transactions are successfully executed and Confirm execution begins. In general, TCC assumes that the Confirm phase does not fail, and that Confirm will succeed as long as the try succeeds. If confirm fails, retry or manual processing is performed. 3) The Cancel stage refers to the cancellation of other branch transactions that have not failed when the business execution error needs to be rolled back, that is, the release of reserved resources. In general, TCC’s Cancel phase is also considered a certain success, and retries or manual processing are introduced if errors occur. \

TCC implementation scheme

The following frameworks all support TCC global transactions, currently Ali Seata has a large user base, Github star number is far ahead, behind will gradually increase seATA source code.

The name of the github
tcc-transaction Github.com/changmingxi…
LCN Github.com/codingapi/t…
Alibaba Seata github.com/seata/seata
Hmily Github.com/yu199195/hm…
ByteTCC Github.com/liuyangming…

What problem does TCC’s empty rollback solve?

In the Try phase, suppose that A Try request is sent to service A, and the network times out due to network reasons. At this time, the coordinator receives the response of network timeout and performs the cancel operation in the second step. However, service A did not execute successfully in the Try phase, resulting in data inconsistencies.

The key to solving the problem is how to identify whether service A was successfully executed in the Try phase, commit if it was successful, and empty rollback if it failed. You can add a branch transaction record table to record branch transactions and global transaction IDS. If the request times out, you can use this table to view branch transactions. If the request does not execute a Try, it will record the branch transaction.

How does TCC solve idempotent problems?

This occurs mainly in the Try phase. Query before Confirm or Cancel by adding a transaction status table.

More rigor requires the addition of distributed locks.

How does TCC solve the suspension problem?

Cancel executes before try due to timeout or other reasons, which is a suspension problem.

The solution adds a branch transaction record table, queries first, and does not execute a try if cancel has already been executed.


If it is helpful to friends, please help me to pay attention to it, thank you!!

“Welcome to the discussion in the comments section. The excavation authorities will draw 100 nuggets in the comments section after project Diggnation. See the event article for details.”