An overview of the content

  1. The DTP model

  2. 2 PC model

  3. 3 PC model

A. Application scenario of strongly consistent distributed transactions

It is used in scenarios that require high data consistency. Such as inter-bank transfer.

B. pros and cons

advantages

  1. High data consistency
  2. The latest written data can be queried at any time

disadvantages

  1. Performance problems exist
  2. complex
  3. Usability has been sacrificed
  4. Do not apply to high concurrency scenarios

C. Solutions

1. The DTP model

X/Open DTP(X/Open Distributed Transaction Processing Reference Model) is a standard for Distributed transactions defined by X/Open. Specific implementation by the manufacturer.

1.1. Important concepts of DTP model

  • Transactions: A transaction is a complete unit of work, consisting of multiple independent computational tasks that are logically atomic and have ACID properties.
  • Global transaction: A transaction managed by a transaction manager that can operate on multiple resource managers at once.
  • Branch transactions: Transactions that are executed independently by each resource manager in a global transaction managed by a transaction manager.
  • Control thread: a thread that performs a global transaction. This thread is used to associate the application, transaction manager, and resource manager with each other. This thread represents the relationship between a global transaction and a branch transaction, also known as a transaction context.

1.2. DTP model has five basic functional components

  • AP: Application Programs are applications that participate in the DTP distributed transaction model
  • RM: Resource Manager can be understood as database or message service Manager. The application can control the corresponding resources through the resource manager, and the corresponding resources need to implement the XA defined interface.
  • TM: Transaction Manager is responsible for coordinating and managing transactions in the DTP model, providing programming interfaces for applications and managing resource managers.
  1. An AP can communicate with TM and RM, and TM and RM can communicate with each other.
  2. The DTP model defines an XA interface through which TM and RM can communicate bidirectional.
  3. TM controls global transactions, manages the life cycle of transactions and coordinates resources.
  4. RM controls and manages actual resources.

(XA Specification refers to the interface between TM and RM. Databases such as Mysql,Oracle, DB2, etc., all implement XA interface.)

2. 2 PC model

A two-phase Commit protocol model that divides transactions into Prepare and Commit phases.

2.2. Execution process

1. Prepare phase

During the Prepare phase, the transaction manager sends a Prepare message to each resource manager participating in the global transaction. The resource manager either returns a failure message or executes the transaction locally without committing the transaction.

2. com MIT stage

If the transaction manager receives a failure message from the resource manager, it sends a rollback message directly to the resource manager that successfully executed in the Prepare phase. Otherwise, it sends a Commit message to each resource manager. The corresponding resource manager performs the corresponding transaction rollback or transaction Commit and releases the applicable locks based on the Commit message.

2.3. Problems of 2PC model

1. Synchronization blocking problem: all participating nodes lock the common resources they occupy. 2. Single point of failure problem: If the transaction manager fails, the resource manager will remain blocked. 3. Data inconsistency: If the network or some resource managers fail during the Commit phase and do not receive the Commit message, data inconsistency occurs.

2. 3 PC model

The model is improved based on 2PC, and the Prepare stage in 2PC is divided into two stages. There are three phases: CanCommit, PreCommit, and Doollback.

  • Compared with 2PC model, 3PC model mainly solves the single point of failure and reduces the blocking phenomenon in the process of transaction execution