concurrency iii (timestamps)
DESCRIPTION
Concurrency III (Timestamps). Serializability Via Timestamps (Continued). Every DB element X has two timestamps: 1. RT (X) = highest timestamp of a transaction to read X. 2. WT (X) = highest timestamp of a transaction to write X. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/1.jpg)
Concurrency III (Timestamps)
![Page 2: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/2.jpg)
Serializability Via Timestamps (Continued)
• Every DB element X has two timestamps: 1. RT (X) = highest timestamp of a transaction to read X.
2. WT (X) = highest timestamp of a transaction to write X.
• Every DB element X has a bit C(X) indicating whether the most recent writer of X has committed.
![Page 3: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/3.jpg)
Physically Unrealizable Behaviors• The scheduler assumes the timestamp order of transactions is also
the serial order in which they must appear to execute.
• Scheduler needs to check that:
whenever a read or write occurs, what happens in real time could have happened if each transaction had executed
instantaneously at the moment of its timestamp.
• If not, we say the behavior is physically unrealizable.
![Page 4: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/4.jpg)
What is Physically Unrealizable?• Read Too Late: Transaction T tries to read X, but TS(T)<WT(X).
• Write Too Late: Transaction T tries to write X, but TS(T)<RT(X)
![Page 5: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/5.jpg)
But Wait if Data is Dirty?• T tries to read X, and TS(T)>WT(X), but C(X) = false.
• T wants to write X, and TS(T)>WT(X), but C(X) = false.
![Page 6: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/6.jpg)
Abort/Update Decision• Legal = Physically Realizable.
• Illegal = Physically Unrealizable.
• If illegal, rollback T = abort T and restart it with a new timestamp.
• When a transaction finishes with no rollback, commit the transaction by changing all C(X) bits to true.
![Page 7: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/7.jpg)
Rules, in detail…Suppose the scheduler receives a request rT(X),
(a) If TS(T) WT(X), the read is physically realizable.
i. If C(X)=true, grant the request.
If TS(T) > RT(X), set RT(X) := TS(T);
otherwise do not change RT(X).
ii. If C(X)=false, delay T until C(X) becomes true, or the transaction that wrote X aborts.
(b) If TS(T) < WT(X), the read is physically unrealizable.
Rollback T; that is, abort T and restart it with a new, larger timestamp.
![Page 8: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/8.jpg)
Rules, in detail…Suppose the scheduler receives a request wT(X),
(a) If TS(T) RT(X) the write is physically realizable If TS(T) WT(X), the write must be performed.i. Write the new value for X,ii. Set WT(X) := TS(T), andiii. Set C(X) := false.
If TS(T) < WT(X), then there is already a later value in X. If C(X)=true, then the previous writer of X is committed, and we simply ignore the write by T; Otherwise, if C(X)=false, then we must delay T.
(b) If TS(T) < RT(X), then the write is physically unrealizable, and T must be rolled back.
![Page 9: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/9.jpg)
Rules, in detail…Suppose the scheduler receives a request to commit T.
• It must find all the database elements X written by T, and set c(X) := true.
• If any transactions are waiting for X to be committed, these transactions are allowed to proceed.
Suppose the scheduler receives a request to abort T or decides to rollback T.
• Then any transaction that was waiting on an element X that T wrote must repeat its attempt to read or write, and see whether the action is now legal after T's writes are cancelled.
![Page 10: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/10.jpg)
Exercise Ist1; st2; r1(A); r2(B); w2(A); w1(B);
T1 T2 A B
TS=1
TS=2
r1(A) RT=1
r2(B) RT=2
w2(A) WT=2
w1(B) – illegal
Rollback T1
![Page 11: Concurrency III (Timestamps)](https://reader036.vdocuments.us/reader036/viewer/2022082422/56813c24550346895da59d11/html5/thumbnails/11.jpg)
Exercise IIst1; st3; st2; r1(A); r2(B); w1(C); r3(B); r3(C); w2(B); w3(A)
T1 T2 T3 A B C
TS=1
TS=2
TS2=3
r1(A) RT=1
r2(B) RT=3
w1(C) WT=1
r3(B) RT=2
r3(C) RT=2
w2(B) WT=3
w3(A) - Skip if C(X)=1. Wait otherwise.