Download presentation
Presentation is loading. Please wait.
Published byReese Weaver Modified over 9 years ago
1
Wait-die Transactions given a timestamp when they arrive …. ts(T i ) T i can only wait for T j if ts(T i )< ts(T j )...else die T 1 (ts =10) T 2 (ts =20) T 3 (ts =25) Wait for A Wait for C? Wait fo B
2
T 1 (ts =22) T 2 (ts =20) T 3 (ts =25) wait(A) requests A: wait for T 2 or T 3 or both? (in my html notes, I assume both) Note: ts between 20 and 25. Wait-die-1
3
T 1 (ts =22) T 2 (ts =20) T 3 (ts =25) wait(A) One option: T 1 waits just for T 3, transaction holding lock. wait(A) But when T 2 gets lock, T 1 will have to die! (also lots of WFG revision) Wait-die-1
4
T 1 (ts =22) T 2 (ts =20) T 3 (ts =25) wait(A) Another option: T 1 waits for both T 2, T 3 E.g., (saves having to revise WFG) T 1 allowed to wait iff there is at least one younger trans wait-involved with A. But again, when T2 gets lock, T 1 must die! Wait-die-2
5
T 1 (ts =22) T 2 (ts =20) T 3 (ts =25) wait(A) Yet another option: T 1 preempts T 2 (T 2 is just waiting idly anyway), so T 1 only waits for T 3 ; T 2 then waits for T 3 But, T 2 may starve? And lots of WFG work for Deadlock Mgr (shifting edges) wait-A Wait-die-3
6
Wound-wait Transactions given a timestamp when they arrive … ts(T i ) T i wounds T j if ts(T i )< ts(T j ) else T i waits “Wound”: T j rolls back (if it cannot finish in small interval of time) and gives lock to T i
7
T 1 (ts =25) T 2 (ts =20) T 3 (ts =10) Wait A Wait B Wait C Wound-wait
8
T 1 (ts =15) T 2 (ts =20) T 3 (ts =10) wait(A) requests A: wait for T 2 or T 3 ? Note: ts between 10 and 20. Wound-wait-2
9
T 1 (ts =15) T 2 (ts =20) T 3 (ts =10) wait(A) One option: T 1 waits just for T 3, transaction holding lock. But when T 2 gets lock, T 1 waits for T 2 and wounds T 2. Wound-wait-2 Wait A
10
T 1 (ts =15) T 2 (ts =20) T 3 (ts =10) wait(A) Another option: T 1 waits for both T 2, T 3 T 2 wounded right away! Wound-wait-3
11
T 1 (ts =15) T 2 (ts =20) T 3 (ts =10) wait(A) Yet another option: T 1 preempts T 2, so T 1 only waits for T 3 ; T 2 then waits for T 3 and T 1... T 2 is spared! Lots of WFG work for Deadlock Mgr (shifting edges) and T 2 may starve. Wound-wait-4 wait-A
12
User/Program commands Lots of variations, but in general Begin_work Commit_work Abort_work
13
Nested transactions User program: Begin_work; If results_ok, then commit work else abort_work...
14
Nested transactions User program: Begin_work; If results_ok, then commit work else {abort_work; try something else…} If results_ok, then commit work else abort_work...
15
Parallel Nested Transactions T 1 : begin-work parallel: T 11 :begin_work commit_work T 12 :begin_work commit_work... T1T1 T 11 T 12 T1T1
16
Locking What are we really locking?
17
Example: T i Read record r 1 Read record r 1 do record locking Modify record r 3...
18
But underneath: Disk pages R3R3 R1R1 R2R2 record id If we lock all data involved in read of R1, we may prevent an update to R2 (which may require reorganization within block)
19
Solution: view DB at two levels Top level: record actions record locks undo/redo actions — logical e.g., Insert record(X,Y,Z) Redo: insert(X,Y,Z) Undo: delete
20
Low level: deal with physical details latch page during action (release at end of action)
21
Note: undo does not return physical DB to original state; only same logical state e.g., Insert R3Undo (delete R3) R1 R2 R1 R2 R3
22
Logging Logical Actions Logical action typically span one block (physiological actions) Undo/redo log entry specifies undo/redo logical action Challenge: making actions idempotent Example (bad): redo insert key inserted multiple times!
23
Solution: Add Log Sequence Number Log record: LSN=26 OP=insert(5,v2) into P... 3, v1 semlsn=25... 3, v1 semlsn=26... 5, v2
24
Still Have a Problem! 3, v1 lsn=24... 4, v2 3, v1 lsn=25... 3, v1 lsn=26... 5, v3 T1 Del 4 T2 Ins 5 3, v1 lsn=??... 5, v3 4, v2 undo Del 4 Make log entry for undo lsn=27
25
Compensation Log Records Log record to indicate undo (not redo) action performed Note: Compensation may not return page to exactly the initial state
26
At Recovery: Example lsn=21 T1 a1 p1 lsn=35 T1 a2 -1 p2 lsn=27 T1 a2 p2... Log:
27
What to do with p2 (during T1 rollback)? If lsn(p2)<27 then... ? If 27 lsn(p2) < 35 then... ? If lsn(p2) 35 then... ? Note: lsn(p2) is lsn of p copy on disk
28
Recovery Strategy [1] Reconstruct state at time of crash Find latest valid checkpoint, Ck, and let ac be its set of active transactions Scan log from Ck to end: For each log entry [lsn, page] do: if lsn(page) < lsn then redo action If log entry is start or commit, update ac
29
Recovery Strategy [2] Abort uncommitted transactions Set ac contains transactions to abort Scan log from end to Ck : For each log entry (not undo) of an ac transaction, undo action (making log entry) For ac transactions not fully aborted, read their log entries older than Ck and undo their actions
30
Example: What To Do After Crash lsn=21 T1 a1 p1 lsn=35 T1 a2 -1 p2 lsn=27 T1 a2 p2... Log:... lsn=29 T1 a3 p3 lsn=31 T1 a3 -1 p3... chk pt
31
During Undo: Skip Undo’s lsn=21 T1 a1 p1 lsn=35 T1 a2 -1 p2 lsn=27 T1 a2 p2... Log:... lsn=29 T1 a3 p3 lsn=31 T1 a3 -1 p3... chk pt pointer to forward action pointer to previous T1 action
32
Related idea: Sagas Long running activity: T 1, T 2,... T n Each step/trasnaction Ti has a compensating transaction Ti-1 Semantic atomicity: execute one of T 1, T 2,... T n T 1, T 2,... T n-1 T -1 n-1, T -1 n-2,... T -1 1 T 1, T 2,... T n-2 T -1 n-2, T -1 n-3,... T -1 1 T 1, T -1 1 nothing...
33
Summary Cascading rollback Recoverable schedule Deadlock Prevention Detectoin Nested transactions Multi-level view
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.