Timestamp Ordering
Timestamp Ordering
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
- 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.
- 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:
- If TS(T) < WTS(X), the read is rejected, as T is trying to read data overwritten by a newer
- If TS(T) < RTS(X), the write is rejected, as T is attempting to overwrite data already read by a
- If TS(T) < WTS(X), the write is rejected, as T is trying to overwrite data written by a newer
transaction. T is aborted.
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:
- Starvation: Older transactions may repeatedly abort if they conflict with newer ones, leading to
potential starvation.
6. Example:
- 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:
This method ensures serializability by enforcing that transactions execute in a logical order
corresponding to their timestamps.