Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concurrency control by Timestamps (Section18.8) Varun Gupta Department of Computer Science ID-216 CS 257.

Similar presentations


Presentation on theme: "Concurrency control by Timestamps (Section18.8) Varun Gupta Department of Computer Science ID-216 CS 257."— Presentation transcript:

1 Concurrency control by Timestamps (Section18.8) Varun Gupta Department of Computer Science ID-216 CS 257

2 Outline….. What is Timestamping? Two methods of generating Timestamping Physically Unrealizable Behaviors Dirty Data Rules for Timestamp-based Scheduling Multiversion Timestamps CS 257

3 What is Timestamping? Timestamp-based concurrency control is a non-lock concurrency control method, used in relational databases to safely handle transactions, using timestamps. Each transaction is given a unique timestamp. CS 257

4 Two methods of generating Timestamping Using a system clock. Using a counter. Note: Scheduler maintains a table of currently active transactions and their timestamps irrespective of the method used. CS 257

5 Contd…. Scheduler assigns each transaction T a timestamp of its starting time TS(T). Each database element is associated with two timestamps and an additional bit: – RT(X):- Read time of X – WT(X):- Write time of X – C(X):- Commit bit for X CS 257

6 Physically Unrealizable Behavior CS 257

7 Dirty Data Commit bit is used for dealing with various problems:  Dirty Read is performed if T Reads X. So to avoid this,delay T until U commits or abort by checking the commit bit.  A write is cancelled because of a write with a later timestamp but the writer then aborts. CS 257

8 Rules for Timestamp-based Scheduling Rule 1 If scheduler receives a request R T (X): 1) If TS(T)>=WT(X),the read is physically realizable. If C(X) is true, grant the request. IF TS(T) > RT(X), set RT(X):= TS(T); otherwise don’t change RT(X). If C(X) is false, delay T until C(X) becomes true or transaction that wrote X aborts. 2) If TS(T) < WT(X), the read is physically unrealizable. So Rollback T. CS 257

9 Rule 2 If scheduler receives a request W T (X): 1)If TS(T)>=WT(X) and TS(T)>=RT(X),the write is physically realizable. So write the new value of X. 2)If TS(T)>=RT(X) but TS(T) < WT(X), the write is physically realizable. But there is already a later value in X. If C(X) is true then previous writer of X is committed. And If C(X) is false then we must delay T until C(X) becomes true. 3)If TS(T) < RT(X), the write is physically unrealizable. So Rollback T. CS 257

10 Rule 3 If scheduler receives a request to commit T then any transactions that are waiting for an element X written by T to be committed,should be allowed to proceed. Rule 4 If scheduler receives a request to abort T then any transactions that are waiting on an element X written by T,should repeat its attempt to read or write and see if the action is legal now or not. CS 257

11 Multiversion Timestamps Maintain old versions of database elements. Allow read r T (X) that would cause T to abort to proceed by reading the version of X. CS 257

12 A multiversion timestamping scheduler differs from the normal scheduler in following ways: When W T (X) occurs, if it’s legal, a new version of X, X T where t = TS(T), is created. When r T (X) occurs, find the version X T of X such that t <= TS(T), but no X T ’ with t < t’ <= TS(T) Write times are associated with versions of an element, and they never change. Read times are also associated with versions. When X T has a write time t such that no active transaction has a timestamp less than t, we can delete any version of X previous to X T. CS 257

13 Thank You !!!!! CS 257


Download ppt "Concurrency control by Timestamps (Section18.8) Varun Gupta Department of Computer Science ID-216 CS 257."

Similar presentations


Ads by Google