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

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 Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
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.
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
CMPT Dr. Alexandra Fedorova Lecture X: Transactions.
Distributed Systems Fall 2010 Transactions and concurrency control.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transaction Management
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.
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.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
CSE 486/586 CSE 486/586 Distributed Systems Consistency Steve Ko Computer Sciences and Engineering University at Buffalo.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
Page 1 Concurrency Control Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
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.
Concurrency Control Introduction Lock-Based Protocols
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
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.
Distributed Transactions What is a transaction? (A sequence of server operations that must be carried out atomically ) ACID properties - what are these.
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
Transaction Management
Concurrency Control Techniques
CSE 486/586 Distributed Systems Consistency --- 2
CSE 486/586 Distributed Systems Consistency --- 1
CS422 Principles of Database Systems Concurrency Control
Concurrency Control.
Multiple Granularity Granularity is the size of data item  allowed to lock. Multiple Granularity is the hierarchically breaking up the database into portions.
Part- A Transaction Management
CSE 486/586 Distributed Systems Consistency --- 3
CSE 486/586 Distributed Systems Concurrency Control --- 1
CSE 486/586 Distributed Systems Consistency --- 1
Lecture 21: Concurrency & Locking
Chapter 15 : Concurrency Control
CSE 486/586 Distributed Systems Concurrency Control --- 3
ENFORCING SERIALIZABILITY BY LOCKS
Distributed Transactions
Atomic Commit and Concurrency Control
Database Transactions
Slides for Chapter 12: Transactions and Concurrency Control
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
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
CSE 486/586 Distributed Systems Concurrency Control --- 3
Presentation transcript:

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

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

Recap: 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

Recap: Serial Equivalence 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 b: 242 a: 80 c: 278

Recap: Serial Equivalence How to provide serial equivalence with conflicting operations? Execute all pairs of conflicting operations in the same order for all objects

Recap: Serial Equivalence How to provide serial equivalence with conflicting operations? Execute all pairs of conflicting operations in the same order for all 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) a: 100 b: 200 c: 300 == T1 (complete) followed by T2 (complete) b: 220 b: 242 a: 80 c: 278 Pairs of Conflicting Operations

Handling Abort() What can go wrong? 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() ... A, after withdrawal it’s $100. B, before deposit it’s $300.

Strict Executions of Transactions Problem of interleaving for abort() Intermediate state visible to other transactions, i.e., other transactions could have used some results already. For abort(), transactions should delay both their read and write operations on an object (until commit time) Until all transactions that previously wrote that object have either committed or aborted This way, we avoid making intermediate states visible before commit, just in case we need to abort. This is called strict executions. This further restricts which interleavings of transactions are allowed. Thus, correctness criteria for transactions: Serial equivalence Strict execution

Story Thus Far Question: How to support transactions? With multiple transactions sharing data First strategy: Complete serialization One transaction at a time with one big lock Correct, but at the cost of performance How to improve performance? Let’s see if we can interleave different transactions. Problem: Not all interleavings produce a correct outcome Serial equivalence & strict execution must be met. Now, how do we meet the requirements? Overall strategy: using more and more fine-grained locking No silver bullet. Fine-grained locks have their own implications.

Transaction T1 Transaction T2 Using Exclusive Locks Exclusive Locks (Avoiding One Big Lock) Transaction T1 Transaction T2 begin() balance = b.getBalance() begin() balance = b.getBalance() b.setBalance = (balance*1.1) a.withdraw(balance* 0.1) commit() b.setBalance = (balance*1.1) c.withdraw(balance*0.1) Lock B WAIT on B … Lock A … UnLock B Lock B UnLock A Lock C UnLock B UnLock C

How to Acquire/Release Locks Can’t do it naively Serially equivalent? Strict execution? Transaction T1 Transaction T2 x= a.read() a.write(20) y = b.read() b.write(30) b.write(x) z = a.read() Lock A Lock B UnLock A UnLock B Lock B Lock A UnLock B UnLock A

Using Exclusive Locks Two phase locking Strict two phase locking To satisfy serial equivalence First phase (growing phase): new locks are acquired Second phase (shrinking phase): locks are only released A transaction is not allowed to acquire any new lock, once it has released any one lock Strict two phase locking To satisfy strict execution, i.e., to handle abort() & failures Locks are only released at the end of the transaction, either at commit() or abort(), i.e., the second phase is only executed at commit() or abort(). The example shown before does both. Better than one big lock, but still losing the interleaving benefits

CSE 486/586 Administrivia Midterm grades will be posted today.

Can We Do Better? What we saw was “exclusive” locks. Non-exclusive locks: break a lock into a read lock and a write lock Allows more concurrency Read locks can be shared (no harm to share) Write locks should be exclusive

non-exclusive lock compatibility Non-Exclusive Locks non-exclusive lock compatibility Lock already Lock requested set read write none OK OK read OK WAIT write WAIT WAIT A read lock is promoted to a write lock when the transaction needs write access to the same object. A read lock shared with other transactions’ read lock(s) cannot be promoted. Transaction waits for other read locks to be released. Cannot demote a write lock to read lock during transaction – violates the 2P principle

Example: Non-Exclusive Locks Transaction T1 Transaction T2 begin() balance = b.getBalance() begin() … balance = b.getBalance() … b.setBalance =balance*1.1 Commit R-Lock B R-Lock B Cannot Promote lock on B, Wait Promote lock on B …

Cannot Promote lock on B, Wait Cannot Promote lock on B, Wait 2PL: a Problem What happens in the example below? Transaction T1 Transaction T2 begin() balance = b.getBalance() begin() balance = b.getBalance() b.setBalance =balance*1.1 b.setBalance=balance*1.1 R-Lock B R-Lock B Cannot Promote lock on B, Wait Cannot Promote lock on B, Wait … …

Deadlock Conditions Necessary conditions W ... T V U T ... U Non-sharable resources (locked objects) No lock preemption Hold & wait or circular wait Held by Held by Wait for Held by Wait for W ... Wait for A A T V U T B B ... U Wait for Held by Wait for Held by Wait for Held by Hold & Wait Circular Wait

Preventing Deadlocks Acquiring all locks at once Acquiring locks in a predefined order Not always practical: Transactions might not know which locks they will need in the future One strategy: timeout If we design each transaction to be short and fast, then we can abort() after some period of time.

Two-Version Locking Three types of locks: read lock, write lock, commit lock Transaction cannot get a read or write lock if there is a commit lock Read and write (from different transactions) can go together. Acquiring a commit lock only happens at commit(). lock compatibility Lock already Lock requested set read write commit none OK OK OK read OK OK WAIT write OK WAIT commit WAIT WAIT

Two-Version Locking Three types of locks: read lock, write lock, commit lock Transaction cannot get a read or write lock if there is a commit lock At commit(), Promote all the write locks of the transaction into commit locks If any objects have outstanding read locks, transaction must wait until the transactions that set these locks have completed and locks are released Compare with read/write locks: Read operations are delayed only while transactions are committed Read operations of one transaction can cause a delay in the committing of other transactions

Extracting Even More Concurrency Allow writing tentative versions of objects Letting other transactions read from the previously committed version At commit(), Promote all the write locks of the transaction into commit locks If any objects have outstanding read locks, transaction must wait until the transactions that set these locks have completed and locks are released Allow read and write locks to be set together by different transactions Unlike non-exclusive locks Disallow commit if other uncompleted transactions have read the objects These transactions must wait until the reading transactions have committed

Extracting Even More Concurrency This allows for more concurrency than read-write locks. Writing transactions risk waiting or rejection when commit Read operations wait only if another transaction is committing the same object Read operations of one transaction can cause a delay in the committing of other transactions

Summary Strict Execution Strict execution with exclusive locks Delaying both their read and write operations on an object until all transactions that previously wrote that object have either committed or aborted Strict execution with exclusive locks Strict 2PL Increasing concurrency Non-exclusive locks Two-version locks Etc.

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