Three, 1pc transaction commit protocol

All articles

https://www.cnblogs.com/lay2017/p/12078232.html

 

text

In the basic concept of a transaction in one article, we know that the transaction must meet four basic properties of ACID. If you want the program to provide characteristics of a transaction, to meet the ACID properties, you have to try to comply with some of the norms. Of course, if there is sufficient capacity, you can also customize some of the specifications.

This article will learn about a relatively simple stage (1pc) transaction commit protocol.

1pc transaction commit protocol

First look at a sequence of FIG.

A two-phase commit protocol is only part

1) open a transaction

2) normal commit the transaction, or an exception when the rollback affairs

1pc advantage is very obvious. Very simple, just keep up a server interaction, loss on interactive significantly less, so the performance is relatively good.

And it's also very obvious shortcomings. If more than one server when it is unable to coordinate multiple server. Therefore, the use of scenarios is more limited.

Such a look, 1pc commit protocol is not like JDBC interface design on matters it?

Assuming that handle multiple server with 1pc?

Earlier, we said 1pc more suitable for the case of a single server. If it is more than the service side, it can not coordinate transactions 1pc multiple server-side.

So, we assume 1pc handle multiple server will be like?

We see that activity diagram opens the three transactions, all the way to commit if successful, then no problem.

If one fails, then rollback the current transaction, and submitted required data inconsistencies resulting from the transaction before human intervention.

Of course, in some scenarios, we can choose to continue to retry the commit, until it succeeds (for example mq, sending a message can be sent repeatedly consume messages idempotency to maintain. And mq case commit failure rarely occurs even if there are also relatively easy to recover). However, in most scenarios, 1pc obviously not suitable for multiple data sources.

to sum up

We can think so, if only for the next data source, or we can continue to retry commit (to maintain the eventual consistency) scenario we choose 1pc transaction commit protocol is a simple and efficient solution.

Guess you like

Origin www.cnblogs.com/lay2017/p/12099510.html