Temple University – CIS Dept. CIS661 – Principles of Data Management

Slides:



Advertisements
Similar presentations
Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com Chapter 16 : Concurrency.
Advertisements

CM20145 Concurrency Control
Database Systems (資料庫系統)
1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 4: More on Locks Professor Chen Li.
1 CS216 Advanced Database Systems Shivnath Babu Notes 12: Concurrency Control (II)
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
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Concurrency Control Part 2 R&G - Chapter 17 The sequel was far better than the original! -- Nobody.
Quick Review of Apr 29 material
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Final Exam Review Last Lecture R&G - All Chapters Covered The end crowns all, And that old common arbitrator, Time, Will one day end it. William Shakespeare.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Concurrency Control. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Transaction Processing.
15.1Database System Concepts - 6 th Edition Chapter 15: Concurrency Control Lock-Based Protocols The Two-Phase Locking Protocol Graph-Based Protocols #Deadlock.
Concurrency Control.
Databases Illuminated
V. Megalooikonomou Concurrency control (based on slides by C. Faloutsos at CMU and on notes by Silberchatz,Korth, and Sudarshan) Temple University – CIS.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Concurrency control.
Concurrency Control Lectured by, Jesmin Akhter, Assistant professor, IIT, JU.
Chapter 11 Concurrency Control. Lock-Based Protocols  A lock is a mechanism to control concurrent access to a data item  Data items can be locked in.
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
1 Concurrency Control II: Locking and Isolation Levels.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
Jinze Liu. ACID Atomicity: TX’s are either completely done or not done at all Consistency: TX’s should leave the database in a consistent state Isolation:
CS 440 Database Management Systems Concurrency Control 1.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
CS 540 Database Management Systems Concurrency Control 1.
CS 440 Database Management Systems
Transaction Management
Lecture 3 Concurrency control techniques
Concurrency Control Techniques
Transaction Management and Concurrency Control
C. Faloutsos Concurrency control - deadlocks
Concurrency Control More !
Concurrency Control.
Part- A Transaction Management
Chapter 7: Concurrency Control
Chapter 16: Concurrency Control
Cse 344 March 25th – Isolation.
Temple University – CIS Dept. CIS661 – Principles of Data Management
Chapter 16: Concurrency Control
בקרת בו זמניות (concurrency control)
Chapter 16: Concurrency Control
March 9th – Transactions
Chapter 10 Transaction Management and Concurrency Control
Chapter 16: Concurrency Control
Lecture#21: Concurrency Control – Part 1
Ch 22: Databases Concurrency Control
Chapter 15 : Concurrency Control
Module 16 : Concurrency Control
Chapter 16: Concurrency Control
ENFORCING SERIALIZABILITY BY LOCKS
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Concurrency Control E0 261 Prasad Deshpande, Jayant Haritsa
Transaction Management
C. Faloutsos Transactions
Temple University – CIS Dept. CIS616– Principles of Data Management
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
Chapter 16 : Concurrency Control
Database Systems (資料庫系統)
Lecture 18: Concurrency Control
Database Systems (資料庫系統)
Temple University – CIS Dept. CIS661 – Principles of Data Management
Presentation transcript:

Temple University – CIS Dept. CIS661 – Principles of Data Management V. Megalooikonomou Concurrency control (based on slides by C. Faloutsos at CMU and on notes by Silberchatz,Korth, and Sudarshan)

General Overview Relational model - SQL Functional Dependencies & Normalization Physical Design &Indexing Query optimization Transaction processing concurrency control recovery

Transactions - dfn = unit of work, eg. Atomicity (all or none) move $10 from savings to checking Atomicity (all or none) Consistency Isolation (as if alone) Durability recovery concurrency control

Concurrency – overview why we want it? what does it mean ‘correct’ interleaving? precedence graph how to achieve correct interleavings automatically? concurrency control

Problem concurrent access to data (consider ‘lost update’ problem) how to solve it?

Lost update problem – no locks Read(N) time

Solution – part 1 locks! (most popular solution) lock manager: grants/denies lock requests

Lost update problem – with locks lock manager lock(N) Read(N) N=N-1 Write(N) Unlock(N) grants lock denies lock lock(N) time T2: waits grants lock to T2 Read(N) ...

Locks but, what if we all just want to read ‘N’?

Solution – part 1 Locks and their flavors compatibility matrix X-locks: exclusive (or write-) locks S-locks: shared (or read-) locks <and more ... > compatibility matrix T2 wants T1 has S X T F

Solution – part 1 A transaction may be granted a lock on an item if the requested lock is compatible with locks already held on the item by other transactions Any number of transactions can hold shared locks on an item, but if any transaction holds an exclusive on the item no other transaction may hold any lock on the item. If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks held by other transactions have been released. The lock is then granted.

Solution – part 1 transactions request locks (or upgrades) lock manager grants or blocks requests transactions release locks lock manager updates lock-table

Solution – part 2 locks are not enough – eg., ‘inconsistent analysis’

‘Inconsistent analysis’ time Precedence graph?

‘Inconsistent analysis’ – w/ locks time T1 L(A) Read(A) ... U(A) T2 L(A) .... L(B) the problem remains! Solution??

General solution: Protocol(s) Most popular protocol: A locking protocol is a set of rules followed by all transactions while requesting and releasing locks. Locking protocols restrict the set of possible schedules. Most popular protocol: 2 Phase Locking (2PL)

2PL Phase 1: Growing Phase Phase 2: Shrinking Phase This is a protocol which ensures conflict-serializable schedules. Phase 1: Growing Phase transaction may obtain locks transaction may not release locks Phase 2: Shrinking Phase transaction may release locks transaction may not obtain locks The protocol assures serializability. It can be proved that the transactions can be serialized in the order of their lock points (i.e. the point where a transaction acquired its final lock).

2PL X-lock version: transactions issue no lock requests, after the first ‘unlock’ THEOREM: if all transactions obey 2PL -> all schedules are serializable

2PL – example ‘inconsistent analysis’ – why not 2PL? how would it be under 2PL?

2PL – X/S lock version transactions issue no lock/upgrade request, after the first unlock/downgrade In general: ‘growing’ and ‘shrinking’ phase

2PL – observations limits concurrency may lead to deadlocks 2PLC (keep locks until ‘commit’) strict two-phase locking. Here a transaction must hold all its exclusive locks till it commits/aborts. Rigorous two-phase locking is even stricter: here all locks are held till commit/abort.

Concurrency – overview what does it mean ‘correct’ interleaving? precedence graph how to achieve correct interleavings automatically? concurrency control locks + protocols 2PL, 2PLC graph protocols multiple granularity locks <cc without locks: optimistic cc>

Other protocols than 2-PL – graph-based Assumption: we have prior knowledge about the order in which data items will be accessed (hierarchical) ordering on the data items, like, eg., pages of a B-tree A C B

Other protocols than 2-PL – graph-based Graph-based protocols are an alternative to two-phase locking Impose a partial ordering  on the set D = {d1, d2 ,..., dh} of all data items. If di  dj then any transaction accessing both di and dj must access di before accessing dj. Implies that the set D may now be viewed as a directed acyclic graph, called a database graph. The tree-protocol is a simple kind of graph protocol.

Eg., tree protocol (X-lock version) an xact can request any item, on its first lock request from then on, it can only request items for which it holds the parent lock it can release locks at any time it can NOT request an item twice

Tree protocol - example follows tree protocol? ‘correct’? T1 T2 L(B) L(D) L(H) U(D) L(E) U(E) L(D) U(B) U(H) L(G) U(G) B C D E F G H I

Tree protocol equivalent to 2PL? deadlocks? Pros and cons

Tree protocol The tree protocol ensures conflict serializability as well as freedom from deadlock. Unlocking may occur earlier in the tree-locking protocol than in the two-phase locking protocol. shorter waiting times, increase in concurrency protocol is deadlock-free, no rollbacks are required the abort of a transaction can still lead to cascading rollbacks. However, in the tree-locking protocol, a transaction may have to lock data items that it does not access. increased locking overhead, and additional waiting time potential decrease in concurrency Schedules not possible under two-phase locking are possible under tree protocol, and vice versa.

More protocols lock granularity – field? record? page? table? Pros and cons? (Ideally, each transaction should obtain a few locks)

Multiple granularity Eg: DB Table1 Table2 record1 record2 record-n attr2 attr1 attr1

Multiple granularity Allow data items to be of various sizes and define a hierarchy of data granularities Can be represented graphically as a tree (but don't confuse with tree-locking protocol) When a transaction locks a node in the tree explicitly, it implicitly locks all the node's descendents in the same mode. Locking granularity (level in tree where locking is done): fine granularity (lower in tree): high concurrency, high locking overhead coarse granularity (higher in tree): low locking overhead, low concurrency

what types of locks? X/S locks for leaf level + ‘intent’ locks, for higher levels IS: intent to obtain S-lock underneath IX: intent to obtain X-lock underneath S: shared lock for this level X: ex- lock for this level SIX: shared lock here; + IX

Protocol each xact obtains appropriate lock at highest level proceeds to desirable lower levels intention locks allow a higher level node to be locked in S or X mode without having to check all descendent nodes.

Protocol Transaction Ti can lock a node Q, using the following rules: 1. The lock compatibility matrix must be observed. 2. The root of the tree must be locked first, and may be locked in any mode. 3. A node Q can be locked by Ti in S or IS mode only if the parent of Q is currently locked by Ti in either IX or IS mode. 4. A node Q can be locked by Ti in X, SIX, or IX mode only if the parent of Q is currently locked by Ti in either IX or SIX mode. 5. Ti can lock a node only if it has not previously unlocked any node (that is, Ti is two-phase). 6. Ti can unlock a node Q only if none of the children of Q are currently locked by Ti. Observe that locks are acquired in root-to-leaf order, whereas they are released in leaf-to-root order.

Compatibility matrix T2 wants T1 has IS IX S SIX X t f

Conclusions ‘ACID’ for transactions concurrency: serializability (precedence graph) one (popular) solution: locks + 2PL(C) protocol graph protocols; multiple granularity