Table 3 shows that there are many similarities between 2PC and TC/C, but there are also differences. In 2PC, all local transactions are not done (still locked) when the second phase starts, while in TC/C, all local transactions are done (unlocked) when the second phase starts. In other words, the second phase of 2PC is about completing an unfinished transaction, such as an abort or commit, while in TC/C, the second phase is about using a reverse operation to offset the previous transaction result when an error occurs. The following table summarizes their differences.
First Phase Second Phase: success Second Phase: fail
2PC Local transactions are not done yet Commit all local transactions Cancel all local transactions Cancel all local transactions
TC/C
All local transactions are completed, either committed or canceled
Execute new local transactions if needed
Reverse the side effect of the already committed transaction, or called “undo”
Table 3 2PC vs TC/C
TC/C is also called a distributed transaction by compensation. It is a high-level solution because the compensation, also called the “undo,” is implemented in the business logic. The advantage of this approach is that it is database-agnostic. As long as a database supports transactions, TC/C will work. The disadvantage is that we have to manage the details and handle the complexity of the distributed transactions in the business logic at the application layer.