What is a “distributed transaction”?

后端 未结 5 2087
孤独总比滥情好
孤独总比滥情好 2020-12-24 07:19

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

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

5条回答
  •  Happy的楠姐
    2020-12-24 07:48

    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.

提交回复
热议问题