34
Distributed Transactions 分分分分分

Distributed Transactions

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: Distributed Transactions

Distributed Transactions

分布式事物

Page 2: 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 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 Transactio

n (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.

Page 3: Distributed Transactions

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

Page 4: Distributed Transactions

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

Page 5: Distributed Transactions

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∈

Page 6: Distributed Transactions

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

Page 7: Distributed Transactions

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?

Page 8: Distributed Transactions

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

Page 9: Distributed Transactions

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

Page 10: Distributed Transactions

Centralized Transaction Execution集中交换处理

Page 11: Distributed Transactions

Distributed Transaction execution(homogenous)

分布式交换操作

Page 12: Distributed Transactions

Federated Databases联邦数据库

Page 13: Distributed Transactions

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.

Page 14: Distributed Transactions

Transaction life histories事务生命周期

Page 15: Distributed Transactions

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.

Page 16: Distributed Transactions

Serial History串行调度

Page 17: Distributed Transactions

Execution Schedule (History)执行时间表

Page 18: Distributed Transactions
Page 19: Distributed Transactions
Page 20: Distributed Transactions

Serializability and Dependency Graphs 串行和依赖图

Page 21: Distributed Transactions

Distributed Transaction Processing 分布式事务处理

Page 22: Distributed Transactions

Global and local Histories全局与本地史

Page 23: Distributed Transactions

Independent Execution独立执行

Page 24: Distributed Transactions

Concurrency Control: Locking并发控制 : 死锁

Page 25: Distributed Transactions

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

Page 26: Distributed Transactions

Example

Page 27: Distributed Transactions

Centralized 2PL集中两段锁

Page 28: Distributed Transactions

Distributed 2PL分布式两段锁

Page 29: Distributed Transactions

Deadlocks死锁

Page 30: Distributed Transactions

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

Page 31: Distributed Transactions

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

Page 32: Distributed Transactions

Deadlock in distributed system分布式系统死锁

Page 33: Distributed Transactions
Page 34: Distributed Transactions

Edge chasing