Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme.

Similar presentations


Presentation on theme: "1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme."— Presentation transcript:

1 1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme

2 Database Implementation – Concurrency Control Yan Huang2 Learning Objectives Dealing with Deadlock and Starvation Time Stamp Ordering Technique Validation

3 Database Implementation – Concurrency Control Yan Huang3 Deadlocks Detection Wait-for graph Prevention Resource ordering Timeout Wait-die Wound-wait

4 Database Implementation – Concurrency Control Yan Huang4 Deadlock Detection Build Wait-For graph Use lock table structures Build incrementally or periodically When cycle found, rollback victim T1T1 T3T3 T2T2 T6T6 T5T5 T4T4 T7T7

5 Database Implementation – Concurrency Control Yan Huang5 Resource Ordering Order all elements A 1, A 2, …, A n A transaction T can lock A i after A j only if i > j Problem : Ordered lock requests not realistic in most cases

6 Database Implementation – Concurrency Control Yan Huang6 Timeout If transaction waits more than L sec., roll it back! Simple scheme Hard to select L

7 Database Implementation – Concurrency Control Yan Huang7 Wait-die Transactions are 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

8 Database Implementation – Concurrency Control Yan Huang8 T 1 (ts =10) T 2 (ts =20) T 3 (ts =25) wait Example: wait? Very high level: only older ones have the privilege to wait, younger ones die if they attempt to wait for older ones

9 Database Implementation – Concurrency Control Yan Huang9 Wound-wait Transactions are 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 and gives lock to T i

10 Database Implementation – Concurrency Control Yan Huang10 T 1 (ts =25) T 2 (ts =20) T 3 (ts =10) wait Example: wait Very high level: younger ones wait; older ones kill (wound) younger ones who hold needed locks

11 Database Implementation – Concurrency Control Yan Huang11 Who die? Looks like it is always the younger ones either die automatically or killed What is the reason? Will the younger ones starve? Suggestions?

12 Database Implementation – Concurrency Control Yan Huang12 Timestamp Ordering Key idea: Transactions access variables according to an order decided by their time stamps when they enter the system No cycles are possible in the precedence graph

13 Database Implementation – Concurrency Control Yan Huang13 Timestamp System time when transactions starts An increasing unique number given to each stransaction Denoted by ts(Ti)

14 Database Implementation – Concurrency Control Yan Huang14 The way it works Two time stamps associated with each variable x RS(x): the largest time stamp of the transactions read it WS(x): the largest time stamp of the transactions write it Protocol: ri(x) is allowed if ts(Ti) >= WS(x) wi(x) is allowed if ts(Ti) >=WS(x) and ts(Ti) >=RS(x) Disallowed ri(x) or wi(x) will kill Ti, Ti will restart

15 Database Implementation – Concurrency Control Yan Huang15 Example Assuming: ts(T1) = 100, ts(T2) = 200, ts(T3) = 300 T1 T2 T3 R(x); W(y); R (y); W(z); R(x); W(z); R(y); W(x); x y z RS=-1 RS=-1 RS=-1 WS=-1 WS=-1 WS=-1

16 Database Implementation – Concurrency Control Yan Huang16 Example x y z RS=100 RS=-1 RS=-1 WS=-1 WS=-1 WS=-1

17 Database Implementation – Concurrency Control Yan Huang17 Example x y z RS=100 RS=-1 RS=-1 WS=-1 WS=100 WS=-1

18 Database Implementation – Concurrency Control Yan Huang18 Example x y z RS=100 RS=200 RS=-1 WS=-1 WS=100 WS=-1

19 Database Implementation – Concurrency Control Yan Huang19 Example x y z RS=100 RS=200 RS=-1 WS=-1 WS=100 WS=300

20 Database Implementation – Concurrency Control Yan Huang20 Example x y z RS=200 RS=200 RS=-1 WS=-1 WS=100 WS=300

21 Database Implementation – Concurrency Control Yan Huang21 Example x y z RS=200 RS=200 RS=-1 WS=-1 WS=100 WS=300 T1 is rolled back

22 Database Implementation – Concurrency Control Yan Huang22 Net result of TO scheduling Conflict pairs of actions are taken in the order of their home transactions But the basic TO does not guarantee recoverability

23 Database Implementation – Concurrency Control Yan Huang23 Validation An optimistic scheme Transactions have 3 phases: (1) Read all DB values read writes to temporary storage no locking (2) Validate check if schedule so far is serializable (3) Write if validate ok, write to DB

24 Database Implementation – Concurrency Control Yan Huang24 Time stamps of a transaction Ti Start(Ti) Validation(Ti) Finish(Ti)

25 Database Implementation – Concurrency Control Yan Huang25 Key idea Make validation atomic If T 1, T 2, T 3, … is validation order, then resulting schedule will be conflict equivalent to S s = T 1 T 2 T 3...

26 Database Implementation – Concurrency Control Yan Huang26 Schedule T1 T2 Read(A) A A+100; Read(A) A Ax2; Read(B);B B+100 validate Write(A) Write(B); Read(B) B Bx2; validate Write(A) Write(B);

27 Database Implementation – Concurrency Control Yan Huang27 Example of what validation must prevent: RS(T 2 )={B} RS(T 3 )={A,B} WS(T 2 )={B,D} WS(T 3 )={C} time T 2 start T 2 validate T 3 validate T 3 start  =  T 2 finishes T 3 finishes

28 Database Implementation – Concurrency Control Yan Huang28 T 2 finish phase 3 Example of what validation must prevent: RS(T2)={B} RS(T3)={A,B} WS(T2)={B,D} WS(T3)={C} time T 2 start T 2 validated T 3 validated T 3 start  =  allow T 3 start

29 Database Implementation – Concurrency Control Yan Huang29 Another thing validation must prevent: RS(T 2 )={A} RS(T 3 )={A,B} WS(T 2 )={D,E} WS(T 3 )={C,D} time T 2 validated T 3 validated finish T 2 BAD: w 3 (D) w 2 (D)

30 Database Implementation – Concurrency Control Yan Huang30 finish T 2 Another thing validation must prevent: RS(T 2 )={A} RS(T 3 )={A,B} WS(T 2 )={D,E} WS(T 3 )={C,D} time T 2 validated T 3 validated allow finish T 2

31 Database Implementation – Concurrency Control Yan Huang31 Validation Rule When start validating T Check RS(T)  WS(U) is empty for any U that started but (did not finish validation before T started) Check WS(T)  WS(U) is empty for any U that started but (did not finish validation before T started validation)

32 Database Implementation – Concurrency Control Yan Huang32 Exercise: 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} start validate finish

33 Database Implementation – Concurrency Control Yan Huang33 Exercise: 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} start validate finish

34 Database Implementation – Concurrency Control Yan Huang34 Exercise: 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} start validate finish

35 Database Implementation – Concurrency Control Yan Huang35 Exercise: 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} start validate finish W is rolled bak


Download ppt "1 Concurrency Control III Dead Lock Time Stamp Ordering Validation Scheme."

Similar presentations


Ads by Google