350 likes | 497 Views
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
E N D
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 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.
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
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
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
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
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?
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
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
Distributed Transaction execution(homogenous)分布式交换操作
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.
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.