CSE 486/586 Distributed Systems Concurrency Control --- 1

Slides:



Advertisements
Similar presentations
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Advertisements

CS 542: Topics in Distributed Systems Transactions and Concurrency Control.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Transactions (Chapter ). What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Transactions Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
1 TRANSACTION & CONCURRENCY CONTROL Huỳnh Văn Quốc Phương Thái Thị Thu Thủy
Computer Science 425 Distributed Systems Lecture 21 Transaction Processing and Concurrency Control Reading: Sections
Lecture 11: Transactions and Concurrency Control Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
Transactions and concurrency control
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
Distributed Systems Fall 2010 Transactions and concurrency control.
1 ACID Properties of Transactions Chapter Transactions Many enterprises use databases to store information about their state –e.g., Balances of.
Transaction Management
1 Transaction Management Database recovery Concurrency control.
Desirable features implementation How to cope with multiple users conducting simultaneous transactions.
Transaction. A transaction is an event which occurs on the database. Generally a transaction reads a value from the database or writes a value to the.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Mid-Semester Overview Steve Ko Computer Sciences and Engineering University at Buffalo.
08_Transactions_LECTURE2 DBMSs should guarantee ACID properties (Atomicity, Consistency, Isolation, Durability). This is typically done by guaranteeing.
Lecture 16-1 Computer Science 425 Distributed Systems CS 425 / ECE 428 Fall 2013 Indranil Gupta (Indy) October 17, 2013 Lecture 16 Concurrency Control.
Distributed Systems CS 425 / CSE 424 / ECE 428 Transactions & Concurrency Control  2010, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi,
CSE 486/586 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
Transaction processing Book, chapter 6.6. Problem: With a single user…. you run a query, you get the results, you run the next, etc. But database life.
Presented By: Shreya Patel ( ) Vidhi Patel ( ) Universal College Of Engineering And Technology.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Concurrency Server accesses data on behalf of client – series of operations is a transaction – transactions are atomic Several clients may invoke transactions.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Chapter 15: Transactions Loc Hoang CS 157B. Definition n A transaction is a discrete unit of work that must be completely processed or not processed at.
Transactions. Transaction: Informal Definition A transaction is a piece of code that accesses a shared database such that each transaction accesses shared.
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
Transaction Processing Concepts Muheet Ahmed Butt.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Replication Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Transactions on Replicated Data Steve Ko Computer Sciences and Engineering University at Buffalo.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
Distributed Systems Lecture 12 Concurrency and replication control 1.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
Transactions.
CSE 486/586 Distributed Systems Consistency --- 2
Transaction Management
CSE 486/586 Distributed Systems Consistency --- 2
CSE 486/586 Distributed Systems Consistency --- 1
March 21st – Transactions
ACID PROPERTIES.
Ch 21: Transaction Processing
CSE 486/586 Distributed Systems Consistency --- 3
CSE 486/586 Distributed Systems Consistency --- 1
Lecture 21: Concurrency & Locking
Concurrency Control WXES 2103 Database.
CSE 486/586 Distributed Systems Concurrency Control --- 2
CSE 486/586 Distributed Systems Concurrency Control --- 3
Database Security Transactions
Lecture 21: Intro to Transactions & Logging III
Transaction management
Slides for Chapter 12: Transactions and Concurrency Control
C. Faloutsos Transactions
CSE 486/586 Distributed Systems Concurrency Control --- 2
CSE 486/586 Distributed Systems Concurrency Control --- 1
CSE 486/586 Distributed Systems Consistency --- 2
CSE 486/586 Distributed Systems Consistency --- 3
CSE 486/586 Distributed Systems Consistency --- 1
UNIT -IV Transaction.
CSE 486/586 Distributed Systems Concurrency Control --- 3
Presentation transcript:

CSE 486/586 Distributed Systems Concurrency Control --- 1 Steve Ko Computer Sciences and Engineering University at Buffalo

Banking Example (Once Again) Banking transaction for a customer (e.g., at ATM or browser) Transfer $100 from saving to checking account Transfer $200 from money-market to checking account Withdraw $400 from checking account Transaction savings.deduct(100) checking.add(100) mnymkt.deduct(200) checking.add(200) checking.deduct(400) dispense(400)

Transaction Abstraction for grouping multiple operations into one A transaction is indivisible (atomic) from the point of view of other transactions No access to intermediate results/states Free from interference by other operations Primitives begin(): begins a transaction commit(): tries completing the transaction abort(): aborts the transaction as if nothing happened Why abort()? A failure happens in the middle of execution. A transaction is part of a bigger transaction (i.e., it’s a sub-transaction), and the bigger transaction needs abort. Etc.

Properties of Transactions: ACID Atomicity: All or nothing Consistency: if the server starts in a consistent state, the transaction ends with the server in a consistent state. Isolation: Each transaction must be performed without interference from other transactions, i.e., the non-final effects of a transaction must not be visible to other transactions. Durability: After a transaction has completed successfully, all its effects are saved in permanent storage. (E.g., powering off the machine doesn’t mean the result is gone.)

This Week Question: How to support multiple transactions? When multiple transactions share data. Assume a single processor (one instruction at a time). What would be your first strategy (hint: locks)? One transaction at a time with one big lock, i.e., complete serialization Two issues Performance Abort

Performance? Process 1 Process 2 lock(mutex); savings.deduct(100); checking.add(100); mnymkt.deduct(200); checking.add(200); checking.deduct(400); dispense(400); unlock(mutex); Process 2 lock(mutex); savings.deduct(200); checking.add(200); unlock(mutex); How can we improve the performance? Can process 2 not wait until process 1 finishes?

Abort? 1. savings.deduct(100) 2. checking.add(100) 3. mnymkt.deduct(200) 4. checking.add(200) 5. checking.deduct(400) 6. dispense(400) An abort at these points does not cause lost money, but old steps cannot be repeated An abort at these points means the customer loses money; we need to restore old state

This Week Question: How to support transactions? Multiple transactions share data. What would be your first strategy (hint: locks)? Complete serialization One transaction at a time with one big lock Two issues: Performance and abort First, let’s see how we can improve performance.

Possibility: Interleaving Transactions for Performance Process 1 savings.deduct(100); checking.add(100); mnymkt.deduct(200); checking.add(200); checking.deduct(400); dispense(400); Process 2 savings.deduct(200); checking.add(200); P2 will not have to wait until P1 finishes.

Transaction T1 Transaction T2 What Can Go Wrong? Transaction T1 Transaction T2 balance = b.getBalance() b.setBalance(balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) T1/T2’s update on the shared object, “b”, is lost a: 100 b: 200 c: 300 b: 220 b: 220 a: 80 c: 280

Transaction T1 Transaction T2 Lost Update Problem One transaction causes loss of info. for another: consider three account objects Transaction T1 Transaction T2 balance = b.getBalance() b.setBalance(balance*1.1) b.setBalance = (balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) T1/T2’s update on the shared object, “b”, is lost a: 100 b: 200 c: 300 b: 220 b: 220 a: 80 c: 280

Transaction T1 Transaction T2 What Can Go Wrong? Transaction T1 Transaction T2 a.withdraw(100) total = a.getBalance() total = total + b.getBalance b.deposit(100) total = total + c.getBalance T1’s partial result is used by T2, giving the wrong result a: 100 b: 200 c: 300 a: 00 total 0.00 200 b: 300 500

Inconsistent Retrieval Problem Partial, incomplete results of one transaction are retrieved by another transaction. Transaction T1 Transaction T2 a.withdraw(100) total = a.getBalance() total = total + b.getBalance b.deposit(100) total = total + c.getBalance T1’s partial result is used by T2, giving the wrong result a: 100 b: 200 c: 300 a: 00 total 0.00 200 b: 300 500

What This Means Question: How to support transactions (with locks)? Multiple transactions share data. Complete serialization is correct, but performance and abort are two issues. Executing transactions concurrently for performance Problem: Not all interleavings produce a correct outcome

What is “Correct”? How would you define correctness? For example, two independent transactions made by me and my wife on our three accounts. What do we care about at the end of the day? Correct final balance for each account Transaction T1 Transaction T2 balance = b.getBalance() balance = b.getBalance() b.setBalance = (balance*1.1) b.setBalance(balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) a: 100 b: 200 c: 300

Concurrency Control: Providing “Correct” Interleaving An interleaving of the operations of 2 or more transactions is said to be serially equivalent if the combined effect is the same as if these transactions had been performed sequentially in some order. Transaction T1 Transaction T2 balance = b.getBalance() b.setBalance = (balance*1.1) b.setBalance(balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) a: 100 b: 200 c: 300 == T1 (complete) followed by T2 (complete) b: 220 Serial equivalence is what would happen with one big lock. b: 242 a: 80 c: 278

CSE 486/586 Administrivia Grading is done. PA3 is due next week.

Providing Serial Equivalence What operations are we considering? Read/write What operations matter for correctness? When write is involved Transaction T1 Transaction T2 balance = b.getBalance() balance = b.getBalance() b.setBalance = (balance*1.1) b.setBalance(balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) a: 100 b: 200 c: 300

Conflicting Operations Two operations are said to be in conflict, if their combined effect depends on the order they are executed, e.g., read-write, write-read, write-write (all on same variables). NOT read-read, not on different variables. Operations of different transactions Conflict Reason read No Because the effect of a pair of operations does not depend on the order in which they are executed write Yes Because the effect of a and a operation depends on the order of their execution

Conditions for Correct Interleaving What do we need to do to guarantee serial equivalence with conflicting operations? Case 1 T1.1 -> T1.2 -> T2.1 -> T2.2 -> T1.3 -> T2.3 Case 2 T1.1 -> T2.1 -> T2.2 -> T1.2 -> T1.3 -> T2.3 Which one’s correct and why? Transaction T1 Transaction T2 1. balance = b.getBalance() 1. balance = b.getBalance() 2. b.setBalance = (balance*1.1) 2. b.setBalance(balance*1.1) 3. a.withdraw(balance* 0.1) 3. c.withdraw(balance*0.1) C1 is correct, C2 is not.

Observation Case 1 T1.1 -> T1.2 -> T2.1 -> T2.2 -> T1.3 -> T2.3 Correct: for a shared object (b), T1 produces its final outcome, and then T2 accesses it. Transaction T1 Transaction T2 1. balance = b.getBalance() 2. b.setBalance = (balance*1.1) 2. b.setBalance(balance*1.1) 3. a.withdraw(balance* 0.1) 3. c.withdraw(balance*0.1)

Observation Case 2 T1.1 -> T2.1 -> T2.2 -> T1.2 -> T1.3 -> T2.3 Incorrect: for a shared object (b), T2 uses T1’s intermediate outcome, which T1 later modifies. Transaction T1 Transaction T2 1. balance = b.getBalance() 2. b.setBalance(balance*1.1) 2. b.setBalance = (balance*1.1) 3. a.withdraw(balance* 0.1) 3. c.withdraw(balance*0.1)

Generalizing the Observation Insight for serial equivalence Only the final outcome of a shared object from one transaction should be visible to another transaction. The above should be the case for each and every shared object in the same order. E.g., if T1’s final outcome on one shared object becomes visible to T2, then for each and every other shared object, T1 should produce the final outcome before T2 uses it. The other way round is possible, i.e., T2 first then T1. What is it when one transaction modifies a shared object and another transaction uses it? Conflicting operations

Serial Equivalence and Conflicting Operations Two transactions are serially equivalent if and only if all pairs of conflicting operations (pair containing one operation from each transaction) are executed in the same order (transaction order) for all objects (data) they both access.

Serial Equivalence Example An interleaving of the operations of 2 or more transactions is said to be serially equivalent if the combined effect is the same as if these transactions had been performed sequentially (in some order). Transaction T1 Transaction T2 balance = b.getBalance() b.setBalance = (balance*1.1) b.setBalance(balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) a: 100 b: 200 c: 300 == T1 (complete) followed by T2 (complete) b: 220 C1 is correct because only the final result of T1 on b becomes visible to C2, even if we interleave them. In fact, this has to be done in all shared variables in the same order (e.g., T1’s final results on all variables before T2 uses them.) b: 242 a: 80 c: 278 Pairs of Conflicting Operations

Another Example Transaction T1 Transaction T2 x= a.read() a.write(20) y = b.read() b.write(30) b.write(x) z = a.read() a.write(20) z = a.read() y = b.read() Conflicting Ops. Non-serially equivalent interleaving of operations Serially equivalent interleaving of operations

Inconsistent Retrievals Problem Transaction V : a.withdraw(100) b.deposit(100) W aBranch.branchTotal() a.withdraw(100); $100 total = a.getBalance() total = total+b.getBalance() $300 total = total+c.getBalance() Both withdraw and deposit contain a write operation

Serially-Equivalent Ordering Transaction V : a.withdraw(100); b.deposit(100) W aBranch.branchTotal() $100 $300 total = a.getBalance() total = total+b.getBalance() $400 total = total+c.getBalance() ...

Summary Transactions need to provide ACID Serial equivalence defines correctness of executing concurrent transactions It is handled by ordering conflicting operations

Acknowledgements These slides contain material developed and copyrighted by Indranil Gupta (UIUC).