Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transactions Examples

Similar presentations


Presentation on theme: "Transactions Examples"— Presentation transcript:

1 Transactions Examples

2 Rules for Two Phase Locking
Transaction must get a read or write lock on data item d before reading d and must get a write lock on d before writing to d. A read lock can be shared with other read locks. A write lock is an exclusive lock. After a transaction relinquishes a lock, it may not acquire any new locks.

3 Example One Is this schedule serializable and would it be permitted under the rules of two phase locking?

4 Example Two Is this schedule serializable and would it be permitted under the rules of two phase locking?

5 Pessimistic Timestamp Ordering
Every transaction gets a (Lamport, totally ordered) timestamp when it starts. Every data item has a read ts and a write ts and a commit bit c. The read ts is the ts of the transaction that most recently read the data item. The write ts is the ts of the transaction that most recently wrote to the item. The commit bit c is true if and only if the most recent transaction to write to that item has committed.

6 TS Ordering Rules When scheduler receives a read request from transaction T, if ts(T)>= write-ts(X) and c(X) is true, grant request and set read-ts(X) to MAX{ts(T),read-ts(X)} if ts(T)>= write-ts(X) and c(X) is false, delay T until c(X) becomes true or txn aborts. If ts(T)< write-ts(X), abort T and restart with new timestamp.

7 TS Ordering Rules, continued
When scheduler receives a write request from transaction T, if ts(T)>= read-ts(X) and ts(T)>= write-ts(X), grant request, set write-ts(X) to ts(T) and c(X)=false if ts(T)>= read-ts(X) and ts(T)< write-ts(X), don’t do the operation but allow T to continue as if done (Thomas write rule). If ts(T)< read-ts(X), abort T and restart with new timestamp.

8 Example One Is this schedule serializable and how would it be handled in timestamp ordering?

9 Example Two Is this schedule serializable and how would it be handled in timestamp ordering?


Download ppt "Transactions Examples"

Similar presentations


Ads by Google