0% found this document useful (0 votes)
17 views3 pages

Timestamp Ordering

Uploaded by

ff4649994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Timestamp Ordering

Uploaded by

ff4649994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Concurrency Control Based on Timestamp Ordering

Concurrency Control Based on Timestamp Ordering is a technique used in database systems to

ensure serializability of

transactions while allowing concurrent execution. It uses timestamps to order transactions and

resolve conflicts in

a non-blocking manner.

1. Timestamps:

- Each transaction is assigned a unique timestamp TS(T) when it begins. This timestamp

represents the transaction's logical "start time."

- Older transactions have smaller timestamps, and newer transactions have larger timestamps.

2. Key Ideas:

- Operations (read/write) are executed based on the timestamp ordering of the transactions.

- The serializability order of transactions corresponds to their timestamp order.

3. Rules for Timestamp Ordering:

For every data item X, the following timestamps are maintained:

- Read Timestamp (RTS(X)): The largest timestamp of any transaction that successfully read X.

- Write Timestamp (WTS(X)): The largest timestamp of any transaction that successfully wrote X.

When a transaction T attempts to read or write X, the following checks are made:

- Read Operation (T attempts to read X):

- If TS(T) < WTS(X), the read is rejected, as T is trying to read data overwritten by a newer

transaction. T is aborted and restarted.

- Otherwise, the read is allowed, and RTS(X) is updated to max(RTS(X), TS(T)).


- Write Operation (T attempts to write X):

- If TS(T) < RTS(X), the write is rejected, as T is attempting to overwrite data already read by a

newer transaction. T is aborted.

- If TS(T) < WTS(X), the write is rejected, as T is trying to overwrite data written by a newer

transaction. T is aborted.

- Otherwise, the write is allowed, and WTS(X) is updated to TS(T).

4. Advantages:

- Non-Blocking: Transactions are not delayed by locks, making the system efficient for read-heavy

workloads.

- Deadlock-Free: Since transactions are aborted rather than delayed, deadlocks cannot occur.

5. Disadvantages:

- Restarts: Frequent transaction aborts can occur in high-contention scenarios.

- Starvation: Older transactions may repeatedly abort if they conflict with newer ones, leading to

potential starvation.

- Overhead: Maintaining and comparing timestamps adds computational overhead.

6. Example:

Suppose T1 (timestamp = 5) and T2 (timestamp = 10) access a data item X:

- T1 writes X (WTS(X) = 5).

- T2 attempts to write X:

- Since TS(T2) > WTS(X), the write is allowed, and WTS(X) is updated to 10.

- T1 tries to read X:

- Since TS(T1) < WTS(X), T1's read is rejected, and T1 is aborted.

This method ensures serializability by enforcing that transactions execute in a logical order
corresponding to their timestamps.

You might also like