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

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.
CSC271 Database Systems Lecture # 32.
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 2012 CSE 486/586 Distributed Systems Replication 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
1 Distribuerede systemer og sikkerhed – 18. marts 2002 zFrom Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design zEdition 3, © Addison-Wesley.
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.
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.
CMPT Dr. Alexandra Fedorova Lecture X: Transactions.
Consistency in distributed systems Distributed systems Lecture # 10 Distributed systems Lecture # 10.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
1 ACID Properties of Transactions Chapter Transactions Many enterprises use databases to store information about their state –e.g., Balances of.
Transaction Management
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Mid-Semester Overview Steve Ko Computer Sciences and Engineering University at Buffalo.
Lecture 16-1 Computer Science 425 Distributed Systems CS 425 / ECE 428 Fall 2013 Indranil Gupta (Indy) October 17, 2013 Lecture 16 Concurrency Control.
EE324 INTRO. TO DISTRIBUTED SYSTEMS LECTURE 13 TRANSACTIONS.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Distributed Systems CS 425 / CSE 424 / ECE 428 Transactions & Concurrency Control  2010, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi,
Chapter 12 Transactions 12.1 Introduction 12.2 Transactions 12.3Nested Transactions 12.4 Locks.
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)
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
Transactions. Transaction: Informal Definition A transaction is a piece of code that accesses a shared database such that each transaction accesses shared.
CSC 240 (Blum)1 Database Transactions. CSC 240 (Blum)2 Transaction  A transaction is an interaction between a user (or application) and a database. A.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
Software System Lab. Transactions Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Replication Steve Ko Computer Sciences and Engineering University at Buffalo.
TRANSACTION & CONCURRENCY CONTROL 1. CONTENT 2  Transactions & Nested transactions  Methods for concurrency control  Locks  Optimistic concurrency.
EE324 INTRO. TO DISTRIBUTED SYSTEMS LECTURE 13 TRANSACTIONS.
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.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Paxos Steve Ko Computer Sciences and Engineering University at Buffalo.
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.
CSE 486/586 Distributed Systems Consistency --- 2
CSE 486/586 Distributed Systems Mid-Semester Overview
CSE 486/586 Distributed Systems Consistency --- 2
CSE 486/586 Distributed Systems Consistency --- 1
ACID PROPERTIES.
CSE 486/586 Distributed Systems Concurrency Control --- 1
CSE 486/586 Distributed Systems Consistency --- 1
Concurrency Control WXES 2103 Database.
CSE 486/586 Distributed Systems Concurrency Control --- 2
CSE 486/586 Distributed Systems Concurrency Control --- 3
Database Security Transactions
Transaction management
Slides for Chapter 12: Transactions and Concurrency Control
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 --- 1
CSE 486/586 Distributed Systems Concurrency Control --- 3
CSE 486/586 Distributed Systems Mid-Semester Overview
Presentation transcript:

CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo

CSE 486/586, Spring 2014 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 1.savings.deduct(100) 2.checking.add(100) 3.mnymkt.deduct(200) 4.checking.add(200) 5.checking.deduct(400) 6.dispense(400) 2

CSE 486/586, Spring 2014 Wait…We’ve Seen This Before… What are some things that can go wrong? –Multiple clients –Multiple servers How do you solve this? –Group everything as if it’s a single step Where have we seen this? –Mutual exclusion lecture So, we’re done? –No, we’re not satisfied. 3

CSE 486/586, Spring 2014 Concurrent Transactions Process 1 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); 4

CSE 486/586, Spring 2014 Why Not Satisfied? 1. savings.deduct(100) 2. checking.add(100) 3. mnymkt.deduct(200) 4. checking.add(200) 5. checking.deduct(400) 6. dispense(400) 5 A failure at these points means the customer loses money; we need to restore old state A failure at these points does not cause lost money, but old steps cannot be repeated

CSE 486/586, Spring 2014 Recap: Locks & Transactions What we discussed in mutual exclusion is one big lock. –Everyone else has to wait. –It does not necessarily deal with failures. Performance –Observation: we can interleave some operations from different processes. Failure –If a process crashes while holding a lock Let’s go beyond simple locking! 6

CSE 486/586, Spring 2014 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 Implementing transactions –Performance: finding out what operations we can interleave –Failure: dealing with failures, rolling back changes if necessary 7

CSE 486/586, Spring 2014 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. 8

CSE 486/586, Spring 2014 What Can Go Wrong? Transaction T1Transaction 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: b:c: 280 c: 80 a: 220 b: 220 b:

CSE 486/586, Spring 2014 Lost Update Problem One transaction causes loss of info. for another: consider three account objects Transaction T1Transaction 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: b:c: 280 c: 80 a: 220 b: 220 b:

CSE 486/586, Spring 2014 What Can Go Wrong? Transaction T1Transaction 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: b: 00 a: c: total 300 b:

CSE 486/586, Spring 2014 Inconsistent Retrieval Problem Partial, incomplete results of one transaction are retrieved by another transaction. Transaction T1Transaction 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: b: 00 a: c: total 300 b:

CSE 486/586, Spring 2014 What is “Correct”? How would you define correctness? Transaction T1 Transaction T2balance = b.getBalance() b.setBalance = (balance*1.1)b.setBalance(balance*1.1) a.withdraw(balance* 0.1)c.withdraw(balance*0.1) a: b:c:

CSE 486/586, Spring 2014 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) balance = b.getBalance() b.setBalance(balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) a: b:c: 278 c: a: 242 b: == T1 (complete) followed by T2 (complete)

CSE 486/586, Spring 2014 CSE 486/586 Administrivia Midterm: 3/6 (Wednesday) in class –Everything up to leader election –1-page cheat sheet is allowed. 15

CSE 486/586, Spring 2014 Providing Serial Equivalence What operations are we considering? Read/write What operations matter for correctness? When write is involved Transaction T1 Transaction T2balance = b.getBalance() b.setBalance = (balance*1.1)b.setBalance(balance*1.1) a.withdraw(balance* 0.1)c.withdraw(balance*0.1) a: b:c:

CSE 486/586, Spring 2014 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. 17 Operations of different transactions ConflictReason read NoBecause the effect of a pair ofread operations does not depend on the order in which they are executed readwriteYesBecause the effect of aread and awrite operation depends on the order of their execution write YesBecause the effect of a pair ofwrite operations depends on the order of their execution

CSE 486/586, Spring 2014 Conditions for Correct Interleaving What should 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? 18 Transaction T1 Transaction T21. 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)

CSE 486/586, Spring 2014 Conflicting Operations Insight for serial equivalence Outcomes of write operations in one transaction to all shared objects should be either consistently visible to the other transaction or the other way round. The effect of an operation refers to The value of an object set by a write operation The result returned by a read operation. 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. 19

CSE 486/586, Spring 2014 Example of Conflicting Operations 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) balance = b.getBalance() b.setBalance(balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) a: b:c: 278 c: a: 242 b: == T1 (complete) followed by T2 (complete) Pairs of Conflicting Operations

CSE 486/586, Spring 2014 Another Example Transaction T1 Transaction T2 x= a.read() a.write(20) y = b.read() b.write(30) b.write(x) z = a.read() x= a.read() a.write(20) z = a.read() b.write(x) y = b.read() b.write(30) 21 Serially equivalent interleaving of operations Conflicting Ops. Non- serially equivalent interleaving of operations

CSE 486/586, Spring 2014 Inconsistent Retrievals Problem 22 TransactionV: a.withdraw(100) b.deposit(100) TransactionW : aBranch.branchTotal() a.withdraw(100); $100 total = a.getBalance() $100 total = total+b.getBalance() $300 total = total+c.getBalance() b.deposit(100) $300 Both withdraw and deposit contain a write operation

CSE 486/586, Spring 2014 Serially-Equivalent Ordering 23 TransactionV: a.withdraw(100); b.deposit(100) TransactionW: aBranch.branchTotal() a.withdraw(100); $100 b.deposit(100) $300 total = a.getBalance() $100 total = total+b.getBalance() $400 total = total+c.getBalance()...

CSE 486/586, Spring 2014 Summary Transactions need to provide ACID Serial equivalence defines correctness of executing concurrent transactions It is handled by ordering conflicting operations 24

CSE 486/586, Spring Acknowledgements These slides contain material developed and copyrighted by Indranil Gupta (UIUC).