Distributed transaction (the first 04) Distributed Transaction Solution -3PC

What is a three-phase commit protocol (3PC)

3PC is an improved version of 2PC. Mainly in the following improvements:

  • Added a stage inquiry, inquiry stage to ensure that behavior can not be found in performing operations required discontinuation as early as possible, but it does not find all such acts will only reduce the occurrence of this situation.
  • Increasing the processing logic to wait for a timeout if a timeout waiting for the inquiry stage, the automatic stay; if the wait time out after the preparatory stage, it is automatically submitted. This is also the biggest in accordance correctness probability and statistics.

Two 3PC workflow

  1. Questioning: coordinator asked if participants can complete instruction coordinator only need to answer yes or no, without having to make a real operation, this phase participants will be automatically suspended after waiting for a timeout.
  2. Preparation phase: If the inquiry stage all participants can return to perform operations coordinator for pre-execution request is sent to the participants, and participants write redo and undo logs, locking resources, perform the operation, but not the commit operation; if asked stage of any participant returns the result can not perform the operation, the coordinator sends the request to suspend the participants, the preparatory phase where the logic of the two-phase commit protocol is similar, at this stage the participants will automatically be submitted after waiting for a timeout.
  3. Commit phase: if each participant in the preparation phase to prepare a successful return, which is reserved resources and the implementation of the operation is successful, the coordinator initiates submit instructions to the participants, the participant commits the transaction resource changes, the release of locked resources; if any one participants return preparation failed, that is, to reserve resources or perform the operation fails, coordinator launch abort instruction to the participants, the participants cancel the transaction has been changed, run the undo log, release the locked resources, where logic and two-phase commit protocol submit the same stage.

legend:

Three is better than not 2PC 3PC

3PC advantages :

  • Questioning can be found to ensure that the behavior can not perform operations required discontinuation as early as possible.
  • Avoiding the resource is unlimited locked.

3PC disadvantages :

  • Increases the complexity of the system, increase the number of communications between the participants and the coordinator.

Four 3PC specific implementation framework

I did not find to add it to find ......

Guess you like

Origin www.cnblogs.com/NEWHOM/p/12406313.html