cs505: intermediate topics in database systems
DESCRIPTION
CS505: Intermediate Topics in Database Systems. Jinze Liu. Next:. Tree-based concurrency control Validation concurrency control. T 1 lock. T 1 lock. T 1 lock. all objects accessed through root, following pointers. Example. A. B. C. D. E. F. can we release A lock - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/1.jpg)
Jinze Liu
![Page 2: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/2.jpg)
Tree-based concurrency controlValidation concurrency control
![Page 3: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/3.jpg)
Example
A
B C
D
E F
all objects accessedthrough root,following pointers
T1 lock
T1 lockT1 lock
can we release A lockif we no longer need A??
![Page 4: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/4.jpg)
A
B C
D
E F
T1 lock
T1 lockT1 lock
T1 lock
![Page 5: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/5.jpg)
Assume all Ti start at root; exclusive lockTi Tj Ti locks root before Tj
Actually works if we don’t always start at root
Root
Q Ti Tj
![Page 6: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/6.jpg)
(1) First lock by Ti may be on any item(2) After that, item Q can be locked by Ti
only if parent(Q) locked by Ti
(3) Items may be unlocked at any time(4) After Ti unlocks Q, it cannot relock Q
![Page 7: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/7.jpg)
Tree-like protocols are used typically for B-tree concurrency control
E.g., during insert, do not release parent lock, until you are certain child does not have to split
Root
![Page 8: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/8.jpg)
Rules for shared & exclusive locks?
A
B C
D
E F
T1 S lock(released)
T1 S lock (held)
T1 X lock (released)
T1 X lock (will get)
![Page 9: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/9.jpg)
Rules for shared & exclusive locks?
A
B C
D
E F
T1 S lock(released)
T1 S lock (held)
T1 X lock (released)
T1 X lock (will get)
T2 reads:• B modified by T1
• F not yet modified by T1
![Page 10: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/10.jpg)
Need more restrictive protocolWill this work??
Once T1 locks one object in X mode,all further locks down the tree must bein X mode
![Page 11: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/11.jpg)
Transactions have 3 phases:(1) Read
all DB values readwrites to temporary storageno locking
(2) Validatecheck if schedule so far is serializable
(3) Writeif validate ok, write to DB
![Page 12: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/12.jpg)
Make validation atomicIf T1, T2, T3, … is validation order, then
resulting schedule will be conflict equivalent to Ss = T1 T2 T3...
![Page 13: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/13.jpg)
To implement validation, system keeps two sets:
FIN = transactions that have finished phase 3 (and are all done)
VAL = transactions that have successfully finished phase 2 (validation)
![Page 14: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/14.jpg)
RS(T2)={B} RS(T3)={A,B}WS(T2)={B,D} WS(T3)={C}
time
T2start
T2validated
T3validatedT3
start
![Page 15: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/15.jpg)
RS(T2)={B} RS(T3)={A,B}WS(T2)={B,D} WS(T3)={C}
T2
finishphase 3
time
T2start
T2validated
T3validatedT3
start
allow
T3start
![Page 16: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/16.jpg)
RS(T2)={A} RS(T3)={A,B}WS(T2)={D,E} WS(T3)={C,D}
time
T2validated
T3validated
finish
T2BAD: w3(D) w2(D)
![Page 17: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/17.jpg)
finish
T2
RS(T2)={A} RS(T3)={A,B}WS(T2)={D,E} WS(T3)={C,D}
time
T2validated
T3validated
allow
finish
T2
![Page 18: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/18.jpg)
(1) When Tj starts phase 1: ignore(Tj) FIN
(2) at Tj Validation:if check (Tj) then
[ VAL VAL U {Tj}; do write phase; FIN FIN U {Tj} ]
![Page 19: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/19.jpg)
Check (Tj):For Ti VAL - IGNORE (Tj) DO
IF [ WS(Ti) RS(Tj) OR Ti FIN ]
THEN RETURN false;RETURN true;
![Page 20: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/20.jpg)
For Ti VAL - IGNORE (Tj) DO IF [ WS(Ti) RS(Tj) OR(Ti FIN AND WS(Ti) WS(Tj) )]THEN RETURN false;RETURN true;
![Page 21: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/21.jpg)
T: RS(T)={A,B} WS(T)={A,C}
V: RS(V)={B} WS(V)={D,E}
U: RS(U)={B} WS(U)={D}
W: RS(W)={A,D} WS(W)={A,C}
startvalidatefinish
![Page 22: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/22.jpg)
Validation (also called optimistic concurrency control) is useful in some cases:
- Conflicts rare- System resources plentiful- Have real time constraints
![Page 23: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/23.jpg)
Have studied C.C. mechanisms used in practice- 2 PL- Multiple granularity- Tree (index) protocols- Validation
![Page 24: CS505: Intermediate Topics in Database Systems](https://reader036.vdocuments.net/reader036/viewer/2022062409/56815123550346895dbf41d3/html5/thumbnails/24.jpg)
Concurrency controlSerial schedule: no interleavingConflict-serializable schedule: no cycles in the
precedence graph; equivalent to a serial schedule2PL: guarantees a conflict-serializable scheduleStrict 2PL: also guarantees recoverability
Recovery: undo/redo logging with fuzzy checkpointingNormal operation: write-ahead logging, no force,
stealRecovery: first redo (forward), and then undo
(backword)