Sie sind auf Seite 1von 3

Consistency & Concurrency

Timestamp-Based Protocol & Thomas Write Rule

Timestamp-Based Protocol:
Serializability is decided as per the timestamp of a transaction (Time when a transaction starts) Timestamp is based on system clock or a logical counter Each data item Q has two timestamps: W- TS(Q) largest TS of transaction that executed W(Q) successfully R-TS(Q) largest TS of transaction that executed R(Q) successfully This protocol implements conflict serializability based on the timestamp of the transaction If TS(Ti) < TS(Tj) < TS(Tk) then Ti is the oldest transaction and Tk the youngest. As per conflict serializability, the serializability order of transactions should be <Ti, Tj, Tk> Assigning of R-TS and W-TS is as follows: Sr. No. 1. 2. 3. 4. 5. 6. 7. 1) 2) 3) 4) 5) 6) 7) Ti R(Q) W(Q) R(Q) W(Q) R(Q) W(Q) Tj Tk

R(Q)

R-TS(Q) = TS(Ti) W-TS(Q) = TS(Ti) R-TS(Q) = TS(Tj) R-TS(Q) = TS(Tj) Does not change as TS(Ti) < TS(Tj) W-TS(Q) = TS(Tj) R-TS(Q) = TS(Tk) W-TS(Q) = TS(Tk)

Rules for the Timestamp-Based Protocol: Suppose a transaction requests for R(Q): Sr. No. 1. 2. 3. Ti R(Q) R(Q) R(Q) Tj W(Q) Tk

As per serializability, after swapping we should get a serial schedule <Ti, Tj, Tk>. When (2) occurs i.e. a read request of Ti, a write of Q has already been completed by Tj, and so this request should be rejected as we cannot swap them.

Ms. Anjali Ganesh Jivani The M. S. University of Baroda

Consistency & Concurrency

Timestamp-Based Protocol & Thomas Write Rule

a. If TS(Ti) < W-TS(Q) reject the read request and rollback Ti. b. When (3) occurs, Tj is trying to read its own change (allowed): If TS(Tj) = W-TS(Q) then, R-TS(Q) = TS(Tj) c. When (3) occurs, Tk is trying to read the value written by Tj (which came before it) and so is allowed the read the value. If TS(Tk) > W-TS(Q) then, R-TS(Q) = TS(Tk) Suppose a transaction requests for W(Q) Sr. No. 1. 2. 3. Ti W(Q) W(Q) Tj R(Q) or W(Q) Tk

As per serializability, Ti should complete before Tj. If a read or a write on a data item by Tj has occurred, then Ti cannot request for a write request on the same data item. (swapping not possible). a. If TS(Ti) < R-TS(Q) reject the write request and rollback Ti. b. If TS(Ti) < W-TS(Q) reject the write request and rollback Ti. c. Otherwise, allow the read operation and change the W-TS(Q) accordingly. i.e. when (3) occurs TS(Tk) >= R-TS(Q) and W-TS(Q). W-TS(Q) = TS(Tk) Advantages: Deadlocks will not occur because of rollbacks Disadvantages: Does not ensure recoverability and cascadelessness There is a possibility of starvation The disadvantages can be resolved implementing commit dependencies or not allowing uncommitted reads.

Ms. Anjali Ganesh Jivani The M. S. University of Baroda

Consistency & Concurrency

Timestamp-Based Protocol & Thomas Write Rule

Thomas Write Rule:


Modification of Timestamp-Based Protocol for better concurrency Based on the concept of view serializability Sr. No. 1. 2. 3. 4. 5. 6. 7. Ti R(Q) Q=10 W(Q) Q=12 Ignore R(Q) Q=15 R(Q) Q=15 R(Q) Rollback W(Q) Q=20 Tj W(Q) Q=15 Tk

The rule when a read request comes is same as that of Timestamp Based Protocol Suppose a transaction requests for W(Q) The second rule of Timestamp Based Protocol changes. As per that rule, If TS(Ti) < W-TS(Q) reject the write request and rollback Ti. We reject the request if a write of the younger transaction has already taken place (writes cannot be swapped). Thomas Write rule says ignore the write instead of a rollback of Ti because: If Tj wants to read Q, it will read the value (Q=15) which it has written. If Ti wants to read Q, as per timestamping since write of Tj is already executed, Ti will rollback (will not read the value Q=12) If Tk wants to read Q it will read the value (Q=15) written by Tj. In short, the value written by Ti (Q=12) will never be read by any transaction and so we can ignore the write and continue with the schedule without a rollback of Ti. (i.e. view serializability) _____________________

Ms. Anjali Ganesh Jivani The M. S. University of Baroda

Das könnte Ihnen auch gefallen