问题
I'm working on a distributed system that uses distributed transactions, which means that I may have a transaction that needs to edit multiple databases (on multiple servers) at the same time.
In my system there is a controller to manage the distribution.
the scenario that I want to satisfy is: server A wants to initiate a distributed transaction. the participants are server A and server B. so server A sends a request to the controller to initiate a distributed transaction. the controller opens a connection to server A and to server B and ask them to do local transactions. both server A and server B must reply the server that they are ready. the controller then sends commit to both server A and server B.
Do you have any advice for me to be able to build this distributed transaction ?
回答1:
I think you can google two-phase commit, it is a very famous and useful protocol for distributed transactions, and this is the wiki from wikipedia Two-phase commit
回答2:
Two phase commit is what you want, as BitHigher mentions. It's also known as XA transactions. For MySQL specific operations, read this.
Note that XA will come with its own complications, especially in cases of failures. Make sure you understand all the corner cases before attempting to use XA.
来源:https://stackoverflow.com/questions/17772363/distributed-transaction-on-mysql