Distributed --- distributed transactions

2. Distributed Transaction

  Refer matters to do gymnastics are on different nodes, the need to ensure the ACID transaction properties. For example, in a single scene, inventory and order, if not on the same node, involving distributed transactions.

2PC

  Two-phase commit protocol design starting point is to allow any participant waive that part of its own affairs . Due to the requirements atomic transaction, if part of the transaction is abandoned, then the whole distributed transaction must also be abandoned .

  Two-phase commit (2PC), by introducing a coordinator to coordinate the behavior of participants (Coordinate), the participants and the final decision whether to actually execute the transaction.

1. Run process

1.1 Preparation stage

  Coordinator asked whether participants in a transaction executed successfully, participants send back the results of transaction execution.

1.2 commit phase

  If the transactions are executed successfully on each participant , the transaction coordinator sends a notification so that participants commit the transaction ; otherwise, the coordinator sends a notification to let participants roll back the transaction .

  Note that, in the preparation stage, the participants performed the transaction but not yet committed . Only after receiving the notification sent by the coordinator of the submission period, only be committed or rolled back.

2. Problems

2.1 synchronous blocking

  All transaction participants while waiting for the response of the other participants are in synchronous blocking state can not perform other operations.

2.2 single-point problem

  Coordinator plays a very large role in the 2pc, it will cause a great impact when a failure occurs. In particular place in the second phase, all participants will have to wait, you can not perform other operations.

2.3 data inconsistencies

  In phase two, if only partially commit coordinator to send the message, then network exception occurs, then only a portion of the participants received commit message, that is only part of the participants also submitted a transaction, making the data system inconsistencies.

2.4 is too conservative

  Any node failure will cause the entire transaction fails, there is no complete fault tolerance.

Local news list

  Local service data message table and a table in the same database, so that we can use the local transaction to ensure that the transaction satisfies the operating characteristics of the two tables, and uses the message queue to ensure that the final consistency.

  1. In a distributed transaction after completion of the operation one of the write operation to send a message service data message to the local table, the local transaction to ensure that the message will be written to the local message table.

  2. After the local message table message to message queue, if the message is successfully forwarded the message is deleted from the local list, or continue forward again.

  3. The read operation in the other distributed transaction in a message from the message queue, and performs an operation message.

Guess you like

Origin www.cnblogs.com/yjxyy/p/11139432.html