temple university – cis dept. cis661 – principles of data management
DESCRIPTION
Temple University – CIS Dept. CIS661 – Principles of Data Management. V. Megalooikonomou Concurrency control- Deadlocks (based on slides by C. Faloutsos at CMU and on notes by Silberchatz,Korth, and Sudarshan). General Overview. Relational model - SQL Functional Dependencies & Normalization - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/1.jpg)
Temple University – CIS Dept.CIS661 – Principles of Data Management
V. MegalooikonomouConcurrency control- Deadlocks
(based on slides by C. Faloutsos at CMU and on notes by Silberchatz,Korth, and
Sudarshan)
![Page 2: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/2.jpg)
General Overview Relational model - SQL Functional Dependencies &
Normalization Physical Design &Indexing Query optimization Transaction processing
concurrency control recovery
![Page 3: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/3.jpg)
Transactions - dfn= unit of work, eg.
move $10 from savings to checking
Atomicity (all or none)ConsistencyIsolation (as if alone)Durability
recovery
concurrency control
![Page 4: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/4.jpg)
Isolation - concurrency control serializability <-> correctness
precedence graph automatically correct
interleavings: locks + protocol (2PL, 2PLC) but: deadlocks!
![Page 5: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/5.jpg)
Deadlocks detection handling (prevention)
![Page 6: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/6.jpg)
Deadlock detectionT1 T2 lock
managerL(A) Yes L(B) Yes...L(B) No<waits> L(A) No
time
DEADLOCK
![Page 7: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/7.jpg)
Algo for deadlock detection? wait-for graph: nodes -> transactions arcs -> Tsource waits for Tsink if cycle, then deadlock! Must invoke a deadlock-detection
algorithm periodically to look for cycles.
![Page 8: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/8.jpg)
Eg:T1 T2 lock managerL(A) Yes L(B) Yes...L(B) No<waits> L(A) No
time
T1 T2‘A’
‘B’
for ‘B’
for ‘A’
![Page 9: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/9.jpg)
Another example
T1 T2
T3 T4
• is there a deadlock?
• if yes, which xacts are involved?
![Page 10: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/10.jpg)
Another example
T1 T2
T3 T4
• now, is there a deadlock?
• if yes, which xacts are involved?
![Page 11: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/11.jpg)
Deadlock detection how often should we run the algo? how many transactions are
typically involved?
![Page 12: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/12.jpg)
Deadlock handling
T1 T2
T3 T4
• Q: what to do?
![Page 13: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/13.jpg)
Deadlock handling
T1 T2
T3 T4
• Q0: what to do?
• A: select a ‘victim’ & ‘rollback’
• Q1: which/how to choose?
![Page 14: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/14.jpg)
Deadlock handling• Q1: which/how to choose?
• A1.1: by age
• A1.2: by progress
• A1.3: by # items locked already...
• A1.4: by # xacts to rollback
• Q2: How far to rollback?
T1 T2
T3 T4
![Page 15: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/15.jpg)
Deadlock handling• Q2: How far to rollback?
•A2.1: completely
•A2.2: minimally
• Q3: Starvation??
T1 T2
T3 T4
![Page 16: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/16.jpg)
Deadlock handling• Q3: Starvation??
• A3.1: include #rollbacks in victim selection criterion.
T1 T2
T3 T4
![Page 17: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/17.jpg)
SQL statement usually, conc. control is
transparent to the user, but LOCK <table-name> [EXCLUSIVE|
SHARED]
![Page 18: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/18.jpg)
Concurrency control - conclusions serializability <-> correctness automatically correct
interleavings: locks + protocol (2PL, 2PLC, ...) deadlock detection + handling
![Page 19: Temple University – CIS Dept. CIS661 – Principles of Data Management](https://reader035.vdocument.in/reader035/viewer/2022072014/56812e2d550346895d9392ad/html5/thumbnails/19.jpg)
Conclusions
serializable schedules2PL schedules
serializable schedules
serial sch’s2PLC