1 / 11

Concurrency III (Timestamps)

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.

marla
Télécharger la présentation

Concurrency III (Timestamps)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Concurrency III (Timestamps)

  2. 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.

  3. 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.

  4. 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)

  5. 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.

  6. 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.

  7. 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.

  8. 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), and iii. 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.

  9. 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.

  10. Exercise I st1; 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

  11. Exercise II st1; 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.

More Related