1 / 34

Distributed Transactions

Distributed Transactions. 分布式事物. Transaction Processing 事务处理.  Why Most of the information systems used in businesses are transaction based. The market for transaction processing is many tens of billions of dollars per year

Download Presentation

Distributed Transactions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Distributed Transactions 分布式事物

  2. Transaction Processing事务处理 •  Why • Most of the information systems used in businesses are transaction based. The market for transaction processing is many tens of billions of dollars per year • Not long ago, transaction processing was only used in large companies. •  This is no longer the case (CORBA, J2EE, WWW, Internet …) •  There are may standards (XA-interface, Java Transaction API (JTA), Java Transaction Service (JTS), Web Services Transaction (WS-Transaction)) • Transaction processing has become a core distributed systems technology • It is an accepted, proven and tested programming model and computing paradigm for complex applications.

  3. Transaction事务 •  A transaction is a collection of actions that belong logically together 事务是一个逻辑上连接的行为集合  Example: Money transfer •  Withdraw amount X from account A •  Deposit amount X on account B

  4. Example Flight Reservation预订机票实例 •  Relations: •  FLIGHTS(FNO, DATE, SEATSSOLD, CAPACITY) •  RESERVATION(FNO, DATE, NAME) • BEGIN_TRANSACTION • input(flight, name, date) • EXEC SQL SELECT SEATSSOLD, CAPACITY • INTO temp1, temp2 • FROM FLIGHTS • WHERE FNO=flight AND DATE = date • if temp1 == temp2 • ABORT_Transaction • else • EXEC SQL UPDATE FLIGHTS • SET SEATSSOLD = SEATSSOLD + 1 • WHERE FNO=fight AND DATE=date; • EXEC SQL INSERT INTO RESERVATION values (flight,date,name) • COMMIT_TRANSACTION

  5. Formalization central system形式化中心系统 • Let •  Oij(x) be either a read (ri) or write (wi) operation of • transaction Ti on data item x •  OSi = ∪j Oij •  Ni ∈ {commit (c), abort (a)} • Transaction Ti is a total order Ti = {Σi, <i} •  Σi = OSi ∪ Ni (alphabet)  For any two operations Oij(x) and Oik(x) ∈ OSi, then either Oij(x) <i Oik(x) or Oik(x) <i Oij(x)  (for reads rij(X) and rik(x) they could be executedconcurrently. ) •  For all Oij ∈ OSi, Oij <i Ni

  6. Example • Consider the transaction Ti READ(X) READ(Y) X <- X + Y Write(X) Commit ri(x) ri(y) wi(x) ci Ri(X) Ri(Y) Wi(x) Ci

  7. Limitations局限性 • Inserts not well reflected. Insert into table xyz values (1,’abc’,3) • Complex selects (joins or predicates not well reflected) SELECT * from xyz WHERE location = ‘Montreal’; Table, tuple, subset?

  8. Property of Transactions事务属性 • Atomicity原子性  All or nothing  A transaction often involves several operations that are executed at different times.  Return Commit to user: all updates are safely in the database  Return Abort to user: none of the updates is reflected in the database  Abort might be user-induced or system-induced  Local Recovery: eliminating partial results • Consistency一致性  Transactions make mistakes (introduce negative salaries, etc.)  Transaction consistency enforced by integrity constraints:  Null constraints, Foreign keys, Triggers and assertions  Integrity constraints act as filters determining whether a transaction is acceptable or not.  Checked by the system, not by the programmer

  9. Property of Transactions •  Isolation独立性  Ensuring correct results even when there are many transactions being executed concurrently on the same data  Execution of concurrent transactions controlled such that result the same as if executed serially  Enforced by a concurrency control protocol  Why is concurrent execution useful? •  Durability持久性  Committed updates persistent despite failures  System crash / disk survives:  Global recovery: make sure committed, and only committed data is on disk  UNDO transactions that were in the middle of execution at time of crash (abort)  REDO transactions that were committed before crash but for which updates might not be reflected in DB on disk  Disk failure solved by replication: database backups, mirrored disks, etc.  Durability often combined with availability: percentage of time a system can be used for its intended purpose

  10. Centralized Transaction Execution集中交换处理

  11. Distributed Transaction execution(homogenous)分布式交换操作

  12. Federated Databases联邦数据库

  13. Interface界面 • Begin_Transaction() -> XID; • starts a new transaction and delivers a unique transaction ID XID. This identifier will be used in the other operations in the transaction. • Commit_Transaction(XID) -> (true, false); • ends a transaction: a TRUE return value indicates that the transaction has committed; a FALSE return value indicates that it has aborted. • Abort_Transaction(XID); • aborts the transaction.

  14. Transaction life histories事务生命周期

  15. Schedule调度 • Schedule: sequence of actions (read,write,commit,abort) from a set of transactions (which obeys the sequence of operations within a transaction) Reflects how the DBMS sees the execution of operations; ignores thing likereading/writing from OS files etc.

  16. Serial History串行调度

  17. Execution Schedule (History)执行时间表

  18. Serializability and Dependency Graphs串行和依赖图

  19. Distributed Transaction Processing分布式事务处理

  20. Global and local Histories全局与本地史

  21. Independent Execution独立执行

  22. Concurrency Control: Locking并发控制:死锁

  23. Two-phase locking (2PL)两相锁(两段锁)

  24. Example

  25. Centralized 2PL集中两段锁

  26. Distributed 2PL分布式两段锁

  27. Deadlocks死锁

  28. Dependency graph - wait-forgraph依赖图-等待forgraph

  29. Deadlock Detection (Continued)僵局检测(续)

  30. Deadlock in distributed system分布式系统死锁

  31. Edge chasing

More Related