What is a “distributed transaction”?

妖精的绣舞 提交于 2019-11-28 22:23:14

问题


The Wikipedia article for Distributed transaction isn't very helpful.

Can you give a high-level description of what a distributed transaction is?

Also, can you give an example of why an application or database should perform a transaction that updates data on two or more networked computers? I understood the classic bank example; I care more about distributed transactions in Web-scale databases like Dynamo, Bigtable, HBase, or Cassandra.


回答1:


Usually, transactions occur on one database server:

BEGIN TRANSACTION
SELECT something FROM myTable
UPDATE something IN myTable
COMMIT

A distributed transaction involves multiple servers:

BEGIN TRANSACTION
UPDATE amount = amount - 100 IN bankAccounts WHERE accountNr = 1
UPDATE amount = amount + 100 IN someRemoteDatabaseAtSomeOtherBank.bankAccounts WHERE accountNr = 2
COMMIT

The difficulty comes from the fact that the servers must communicate to ensure that transactional properties such as atomicity are satisfied on both servers: If the transaction succeeds, the values must be updated on both servers. If the transaction fails, the transaction must be rollbacked on both servers. It must never happen that the values are updated on one server but not updated on the other.




回答2:


Distributed transactions span multiple physical systems, whereas standard transactions do not. Synchronization amongst the systems becomes a need which traditionally would not exist in a standard transaction.

From your Wikipedia reference...

...a distributed transaction can be seen as a database transaction that must be synchronized (or provide ACID properties) among multiple participating databases which are distributed among different physical locations...




回答3:


A distributed transaction is a transaction that works across several computers. Say you start a transaction in some method in a program on computer A. You then make some changes to data in the method on computer A, and afterwords the method calls a web service on computer B. The web service method on computer B fails and rolls the transaction back. Since the transaction is distributed, this means that any changes made on computer A also need to be rolled back. The combination of the distributed transaction coordinator on windows and the .net framework facilitate this functionality.




回答4:


A distributed transaction is a transaction on a distributed database (i.e., one where the data is stored on a number of physically separate systems). It's noteworthy because there's a fair amount of complexity involved (especially in the communications) to assure that all the machines remain in agreement, so either the whole transaction succeeds, or else it appears that nothing happened at all.




回答5:


I have tryed to depict the distributed transactions details in this post How would you tune Distributed ( XA ) transaction for performance?

Data good for distributed transaction is data that has very high requirement for Consistency. Usualy this is money or something else that we can never have stale data. Usualy I define two categories Live data and data that there is no imediate need for correctness/consistency.

Now the second part of the question about Dynamo, Bigtable, HBase, or Cassandra.

You can not draw a paralel in between NOSQL databases and distributed transactions. The very existance of this class of databases is justified as a means of avoiding distributed transactions. Distributed transaction is centered all around consistency. That is quite the oposite with the NOSQL storages which are centered around Availability and Partitioning.

The usual transactional model used in such databases is Eventual Consistency.



来源:https://stackoverflow.com/questions/4217270/what-is-a-distributed-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!