0
6.7kviews
Describe concurrency control based on timestamp ordering
1 Answer
0
338views

• Isolation is one of the fundamental properties of transaction. When several transactions execute concurrently in the database, however, the isolation property may no longer be preserved.

• To ensure that it is, the system must control the interaction among the concurrent transactions; this control is achieved through one of a variety of mechanisms called concurrency-control schemes.

• Thus, concurrent execution of transactions can be ensured through various protocols like lock based protocol, timestamp based protocols, validation based protocols etc.

Timestamp Ordering Protocol

i. The basic idea here is to order the transactions based on their timestamps.

ii. This protocol ensures that any conflicting read and write operations are executed in timestamp order.

iii. This protocol works as follows:

Suppose that transaction Ti issues read (Q).

● If TS(Ti) < W-timestamp(Q), then Ti needs to read a value of Q that was already overwritten. Hence, the read operation is rejected, and Ti is rolled back.

Here, W-timestamp(Q) denotes the largest timestamp of any transaction that executed write(Q) successfully.

● If TS(Ti) ≥ W-timestamp(Q), then the read operation is executed, and R-timestamp( Q) is set to the maximum of R-timestamp(Q) and TS(Ti).

Suppose that transaction Ti issues write(Q).

● If TS(Ti) < R-timestamp(Q), then the value of Q that Ti is producing was needed previously, and the system assumed that that value would never be produced.

Hence, the system rejects the write operation and rolls Ti back.

● If TS(Ti) < W-timestamp(Q), then Ti is attempting to write an obsolete value of Q.

Hence, the system rejects this write operation and rolls Ti back.

● Otherwise, the system executes the write operation and sets W-timestamp(Q) to TS(Ti)

Example:

Suppose there are 2 transactions T1 and T2. T1 displays the contents of accounts A and B whereas T2 transfers Rs 100 from account A to account B and displays sum of both. The two transactions T1 and T2 can be illustrated as follows:

T1: read(A)

read(B)

display(A+B)

T2: read(B)

B: = B-100

write(B)

read(A)

A: = A+100

write(A)

display(A+B)

Here, the assumption is that that a transaction is assigned a timestamp immediately before its first instruction. Thus, a schedule, TS(T1)<ts(t2) which="" is="" shown="" below="" can="" be="" obtained,="" under="" the="" time="" stamp="" protocol.<="" p="">

T1 T2
Read(B) Read(B)
B=B-100
Write(B)
Read(A)
Read(A)
Display(A+B)
A=A+100
Write(A)
Display(A+B)

Advantages of timestamp ordering protocol:

● The timestamp-ordering protocol ensures conflict serializability. This is because conflicting operations are processed in timestamp order.

● The protocol ensures freedom from deadlock, since no transaction ever waits.

Disadvantages of timestamp ordering protocol:

● However, there is a possibility of starvation of long transactions if a sequence of conflicting short transactions causes repeated restarting of the long transaction.

● This protocol can generate schedules that are not recoverable.

Please log in to add an answer.