database 什么是“分布式事务”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4217270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a "distributed transaction"?
提问by Zombie
The Wikipedia article for Distributed transactionisn'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.
此外,您能否举例说明为什么应用程序或数据库应该执行更新两台或多台联网计算机上的数据的事务?我理解了经典的银行示例;我更关心 Dynamo、Bigtable、HBase 或 Cassandra 等 Web 规模数据库中的分布式事务。
回答by Heinzi
Usually, transactions occur on one database server:
通常,事务发生在一台数据库服务器上:
BEGIN TRANSACTION
SELECT something FROM myTable
UPDATE something IN myTable
COMMIT
A distributed transactioninvolves 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 communicateto ensure that transactional properties such as atomicityare 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.
困难在于服务器必须进行通信以确保在两台服务器上都满足诸如原子性之类的事务属性:如果事务成功,则必须在两台服务器上更新值。如果事务失败,则必须在两台服务器上回滚事务。永远不会发生值在一台服务器上更新但不在另一台服务器上更新的情况。
回答by Aaron McIver
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...
...分布式事务可以看作是必须在分布在不同物理位置的多个参与数据库之间同步(或提供 ACID 属性)的数据库事务...
回答by Klaus Byskov Pedersen
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.
分布式事务是跨多台计算机工作的事务。假设您在计算机 A 上的程序中以某种方法启动事务。然后对计算机 A 上的方法中的数据进行一些更改,然后该方法调用计算机 B 上的 Web 服务。计算机 B 上的 Web 服务方法失败并回滚事务。由于事务是分布式的,这意味着在计算机 A 上所做的任何更改也需要回滚。Windows 上的分布式事务协调器和 .net 框架的结合促进了这一功能。
回答by Jerry Coffin
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.
分布式事务是分布式数据库上的事务(即,数据存储在多个物理上独立的系统上)。值得注意的是,这涉及相当多的复杂性(尤其是在通信中),以确保所有机器保持一致,因此要么整个交易成功,要么看起来什么也没发生。
回答by Alexandar Petrov
I have tryed to depict the distributed transactions details in this post How would you tune Distributed ( XA ) transaction for performance?
我试图在这篇文章中描述分布式事务的详细信息如何调整分布式(XA)事务以提高性能?
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 questionabout Dynamo, Bigtable, HBase, or Cassandra.
现在是关于 Dynamo、Bigtable、HBase 或 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.
您无法在 NOSQL 数据库和分布式事务之间建立并行关系。这类数据库的存在本身就被证明是避免分布式事务的一种手段。分布式事务以一致性为中心。这与以可用性和分区为中心的 NOSQL 存储完全相反。
The usual transactional model used in such databases is Eventual Consistency.
此类数据库中使用的常用事务模型是最终一致性。