24.6 KB · commit 40bb182
← Previous: T11.5: Wait-Die vs. Wound-Wait Deadlock Prevention | 🏠 Index | Next: T12.1: Failure Classification and Recovery Precautions →
Topic: T11 — Concurrency Control Protocols | Priority: 🟠 | Exam Frequency: 3/7 finals (11 marks) Sources: Silberschatz 7e Ch. 18 (§18.5, pp. 861–865) · Lecture Deck 08 (Slides 26–30) · Raidah Notes (pp. 31–32)
The Timestamp-Ordering (TSO) protocol offers a lock-free way to manage concurrent transactions. By locking in the serialization order before transactions even run, TSO guarantees conflict serializability and completely eliminates deadlocks. This topic shows up regularly in RUET semester finals, both as conceptual questions about why rolled-back transactions need new timestamps and as step-by-step schedule traces. Once you understand the read/write rules, Thomas' Write Rule, and the timestamp reassignment trap, these questions become straightforward marks.
Timestamp-Ordering Protocol (TSO): A lock-free concurrency control protocol that assigns each transaction Ti a unique startup timestamp TS(Ti). It checks data item timestamps on every read and write so conflicting operations run in timestamp order. This guarantees conflict serializability and prevents deadlocks because transactions never wait.
Data Item Timestamps (
W-timestampandR-timestamp): Two timestamp values stored on each data item Q to track recent access. W-timestamp(Q) is the largest timestamp of any transaction that successfully wrote Q. R-timestamp(Q) is the largest timestamp of any transaction that successfully read Q.
Thomas' Write Rule: An extension to the Timestamp-Ordering protocol that skips outdated writes instead of rolling the transaction back. If transaction Ti tries to write Q when TS(Ti)<W-timestamp(Q) and TS(Ti)≥R-timestamp(Q), the write is ignored and Ti continues. This allows view-serializable schedules that are not conflict serializable.
Instead of making transactions wait in lock queues when conflicts happen, timestamp-based protocols decide the equivalent serial order up front:
Each transaction Ti gets a unique, fixed timestamp TS(Ti) right when it starts:
The golden rule of the protocol is simple:
Timestamp Order=Serializability Order
So if TS(Ti)<TS(Tj), the final schedule must behave just like a serial schedule where Ti ran completely before Tj.
How does the database know if a transaction is acting out of order? Every data item Q keeps two "high-water mark" stickers on itself:
Both stickers start at 0 when the database boots up. Whenever a transaction Ti tries to read or write Q, the database compares TS(Ti) against these two stickers to check if a younger transaction has already moved Q "into the future."
When transaction Ti tries to read or write data item Q, the concurrency control manager checks whether Ti is arriving "too late":
TS(Ti)<W-timestamp(Q)
TS(Ti)≥W-timestamp(Q)
R-timestamp(Q):=max(R-timestamp(Q),TS(Ti))
TS(Ti)<R-timestamp(Q)
TS(Ti)<W-timestamp(Q)
TS(Ti)≥R-timestamp(Q)andTS(Ti)≥W-timestamp(Q)
W-timestamp(Q):=TS(Ti)
Figure 18.17: Schedule 3 executing under the timestamp-ordering protocol (Source: Silberschatz 7e, Figure 18.17).
Both 2018 Q.6(b) and 2024 Q.8(b) ask why a rolled-back transaction must get a new timestamp under TSO instead of keeping its old one:
| Protocol Category | Protocol Name | Restart Timestamp Policy | Architectural Reason |
|---|---|---|---|
| Deadlock Prevention | Wait-Die / Wound-Wait | Keeps OLD (Original) Timestamp | An old timestamp increases seniority over time, ensuring the transaction eventually runs without dying. |
| Concurrency Control | Timestamp Ordering (TSO) | Receives NEW (Higher) Timestamp | An old timestamp would keep clashing with the higher timestamps already recorded on data items, causing permanent starvation. |
What if an older transaction Ti tries to write to Q after a younger transaction Tj has already written to Q, and nobody has read Q in between? In a serial schedule where Ti ran before Tj, Ti's write would have been immediately overwritten by Tj's write anyway! Thomas' Write Rule uses this insight to avoid unnecessary rollbacks:
Figure 18.18: Schedule 4 illustrating Thomas' write rule where obsolete write is ignored (Source: Silberschatz 7e, Figure 18.18).
When transaction Ti issues write(Q):
Before tackling the full 3-transaction past exam problem in GQ2, let's trace a compact 5-step schedule on a single data item X with two transactions:
TS(T1)=5,TS(T2)=8
Initially, data item X has R-TS(X)=0 and W-TS(X)=0.
| Step | Txn | Operation | Protocol Condition Check | Decision | Updated Timestamp State |
|---|---|---|---|---|---|
| 1 | T1 | R(X) | TS(T1)≥W-TS(X)⟹5≥0 | Execute | R-TS(X)=max(0,5)=5,W-TS(X)=0 |
| 2 | T2 | W(X) | TS(T2)≥R-TS(X) (8≥5) and ≥W-TS(X) (8≥0) | Execute | R-TS(X)=5,W-TS(X)=8 |
| 3 | T2 | R(X) | TS(T2)≥W-TS(X)⟹8≥8 | Execute | R-TS(X)=max(5,8)=8,W-TS(X)=8 |
| 4 | T1 | W(X) | TS(T1)<R-TS(X)⟹5<8 (Violated!) | REJECTED | T1 is rolled back |
| 5 | T1 (new) | W(X) | Restarted with new TS(T1)=10≥8 | Execute | R-TS(X)=8,W-TS(X)=10 |
| Year & Question | Marks | Scenario / Data Given | Key Result / Answer Summary |
|---|---|---|---|
| 2018 Q.6(b) | 4 | Conceptual question from Textbook Exercise 18.26 | Stated read/write rollback conditions; proved why keeping old timestamp causes repeat failure and starvation |
| 2023 Q.8(c) | 4 | 7-step schedule on items A,B,C with T1(100),T2(200),T3(300) | Traced step-by-step; caught Step 6 read-conflict on B; rolled back T2 and assigned new timestamp |
| 2024 Q.8(b) | 3 | Identical repeat of 2018 Q.6(b) | Concisely stated rollback conditions and proved necessity of new timestamp assignment |
Appeared: 2018 Q.6(b) (04 marks), 2024 Q.8(b) (03 marks, CO3) — Identical repeat question
Question:
When a transaction is rolled back under timestamp ordering and it is assigned a new timestamp? Why can it not simply keep its old timestamp?
Full Answer:
1. When a Transaction is Rolled Back Under Timestamp Ordering: Under the Timestamp Ordering (TSO) protocol, an active transaction Ti with timestamp TS(Ti) is rejected and rolled back whenever it attempts an out-of-order operation that violates the serialization schedule:
read(Q) Operation:
TS(Ti)<W-timestamp(Q)
Transaction Ti is attempting to read an old value of data item Q that has already been overwritten by a younger transaction. The read operation is rejected, and Ti is rolled back.write(Q) Operation:
2. Assigning a New Timestamp Upon Restart: When Ti is rolled back, the system aborts it and undoes its updates. When Ti is restarted, the concurrency control manager assigns it a new, larger timestamp using the current system clock or incremented logical counter.
3. Why It Cannot Keep Its Old Timestamp: A rolled-back transaction cannot retain its old timestamp for three critical reasons:
Appeared: 2023 Q.8(c) — (04 marks, CLO3)
Question:
Discuss the given schedule based on Timestamp ordering protocol.
| T1(100) | T2(200) | T3(300) |
|---|---|---|
| R(A) | ||
| R(B) | ||
| W(C) | ||
| R(B) | ||
| R(C) | ||
| W(B) | ||
| W(A) | ||
| (Note: In the original paper schedule, W(C) of T1 and R(B) of T3 occupy essentially the same vertical tier. Since C and B are disjoint data items, the concurrency protocol evaluation remains unaffected). |
Full Answer:
1. Initial Configuration:
2. Step-by-Step Operation Trace:
| Step | Transaction | Operation | Condition Checked | Protocol Action | State of Timestamps |
|---|---|---|---|---|---|
| 1 | T1 | R(A) | TS(T1)≥W-TS(A)⟹100≥0 | Valid (Execute) | R-TS(A)=max(0,100)=100 |
| 2 | T2 | R(B) | TS(T2)≥W-TS(B)⟹200≥0 | Valid (Execute) | R-TS(B)=max(0,200)=200 |
| 3 | T1 | W(C) | TS(T1)≥R-TS(C),W-TS(C)⟹100≥0 | Valid (Execute) | W-TS(C)=100 |
| 4 | T3 | R(B) | TS(T3)≥W-TS(B)⟹300≥0 | Valid (Execute) | R-TS(B)=max(200,300)=300 |
| 5 | T1 | R(C) | TS(T1)≥W-TS(C)⟹100≥100 | Valid (Execute) | R-TS(C)=max(0,100)=100 |
| 6 | T2 | W(B) | TS(T2)<R-TS(B)⟹200<300 | REJECTED | T2 is rolled back |
| 7 | T3 | W(A) | TS(T3)≥R-TS(A),W-TS(A)⟹300≥100 | Valid (Execute) | W-TS(A)=300 |
3. Detailed Analysis of Execution Steps:
Conclusion: The schedule is not accepted without rollback. At Step 6, transaction T2 violates the timestamp-ordering protocol and is rolled back. When restarted, transaction T2 must be assigned a new timestamp greater than 300.
Source: Silberschatz 7e · Chapter 18 (Practice Exercise 18.8)
Exam Relevance: Prime Overdue Mathematical Trace Drill
Key Tested Concept: Step-by-step evaluation of read and write operations against R-TS(Q) and W-TS(Q) under the Timestamp Ordering protocol.
Problem Statement:
Transactions T1,T2,T3 enter the database system with assigned timestamps:
TS(T1)=100,TS(T2)=200,TS(T3)=300Initial read and write timestamps of data items A and B are:
R-TS(A)=0,W-TS(A)=0,R-TS(B)=0,W-TS(B)=0Trace the following sequence of operations under the standard Timestamp Ordering (TSO) protocol. For each operation, specify whether it is allowed or aborted/rolled back, and update R-TS and W-TS:
- T1:read(A)
- T2:write(A)
- T3:read(A)
- T1:write(A)
- T2:write(B)
- T1:read(B)
Model Exam-Style Solution:
Step 1: T1:read(A) [TS(T1)=100]
Step 2: T2:write(A) [TS(T2)=200]
Step 3: T3:read(A) [TS(T3)=300]
Step 4: T1:write(A) [TS(T1)=100]
Step 5: T2:write(B) [TS(T2)=200]
Step 6: T1:read(B)
Summary State Table:
| Step | Operation | Condition Evaluated | Outcome | New R-TS | New W-TS |
|---|---|---|---|---|---|
| 1 | T1:read(A) | 100≥W-TS(A)=0 | Allowed | R-TS(A)=100 | W-TS(A)=0 |
| 2 | T2:write(A) | 200≥100 and 200≥0 | Allowed | R-TS(A)=100 | W-TS(A)=200 |
| 3 | T3:read(A) | 300≥W-TS(A)=200 | Allowed | R-TS(A)=300 | W-TS(A)=200 |
| 4 | T1:write(A) | 100<R-TS(A)=300 | Aborted | — | — |
| 5 | T2:write(B) | 200≥0 and 200≥0 | Allowed | R-TS(B)=0 | W-TS(B)=200 |
💡 RUET Exam Takeaway: In TSO traces, when testing a write, check both R-TS and W-TS. If TS(Ti)<R-TS(Q), an operation that should have read Ti's value has already executed, triggering an immediate abort.
← Previous: T11.5: Wait-Die vs. Wound-Wait Deadlock Prevention | 🏠 Index | Next: T12.1: Failure Classification and Recovery Precautions →