Testing Serializability of a Schedule
๐ Concept: Testing Serializability of a Schedule
๐ What is the Goal?
To determine whether a given schedule (interleaving of transactions) behaves like a serial execution.
๐ง Basic Idea
Instead of rearranging operations, we:
๐ Build a precedence graph
๐ Check for dependency cycles
๐ Precedence Graph
- Nodes → Transactions (T1, T2, …)
- Edges → Dependency due to conflicting operations
⚠️ What are Conflicts?
Two operations conflict if:
- They belong to different transactions
- They access the same data item
- At least one is a write
Types:
- Write → Read
- Read → Write
- Write → Write
๐ Meaning of an Edge
If:
๐ Transaction Ti must execute before Tj
๐ Final Decision
✅ No Cycle
- Schedule is conflict serializable
- Equivalent serial order exists
❌ Cycle Exists
- Schedule is not serializable
- No valid serial execution possible
๐งฉ Why Cycles Matter?
A cycle means:
๐ Circular dependency → impossible ordering
๐ฏ Key Insight
The algorithm works by:
๐งพ Algorithm : Testing Conflict Serializability
Steps
- For each transaction in schedule , create a node labeled in the precedence graph.
For each case where executes read_item(X) after executes write_item(X), create an edge:
For each case where executes write_item(X) after executes read_item(X), create an edge:
For each case where executes write_item(X) after executes write_item(X), create an edge:
- The schedule is conflict serializable if and only if the precedence graph has no cycles.
Step 1: Create nodes
For each transaction Ti in schedule S, create a node Ti.
✅ Meaning:
- Each transaction becomes a node in the graph
- Example: T1, T2, T3 → nodes
Step 2: Write → Read conflict
If Tj reads X after Ti writes X, add edge (Ti → Tj).
๐ Condition:
✅ Meaning:
-
Tj is reading a value written by Ti
๐ So Ti must come before Tj
Step 3: Read → Write conflict
If Tj writes X after Ti reads X, add edge (Ti → Tj).
๐ Condition:
✅ Meaning:
-
Tj overwrites a value read by Ti
๐ So Ti must come before Tj
Step 4: Write → Write conflict
If Tj writes X after Ti writes X, add edge (Ti → Tj).
๐ Condition:
✅ Meaning:
-
Two writes on same data
๐ Order must be preserved
๐ซ Important:
- Ignore Read–Read (R–R) → no conflict
Step 5: Check for cycles
Schedule is serializable if and only if graph has no cycles.
๐ What is a Cycle?
A cycle is a loop like:
❌ Meaning:
- T1 must come before T2
- T2 before T3
- T3 before T1
๐ Impossible → Not Serializable
✅ If NO cycle:
- Schedule is conflict serializable
- We can find a valid serial order
๐งฉ If No Cycle → How to Find Serial Order?
Use the graph:
- Follow direction of edges
-
Arrange transactions so that:
๐ This is called topological ordering
Key Insight
๐ Each edge means:
๐ If all such constraints can be satisfied → serializable
๐ Summary Table
| Step | Action |
|---|---|
| 1 | Create node for each transaction |
| 2 | Add edges for conflicts (W-R, R-W, W-W) |
| 3 | Check graph |
| 4 | Cycle? → ❌ Not serializable |
| No cycle? → ✅ Serializable |
Example
Problem
(i) Schedule S1: check whether the schedule conflict serializable
๐น Step 1: Transactions
T1, T2, T3
๐น Step 2–4: Find conflicts and add edges
On data item X:
-
R2(X) before W1(X) → Read–Write conflict
→ Edge: T2 → T1
On data item Y:
-
R1(Y) before W2(Y) → Read–Write conflict
→ Edge: T1 → T2 -
R3(Y) before W2(Y) → Read–Write conflict
→ Edge: T3 → T2
๐น Step 5: Precedence Graph
Edges:
- T2 → T1
- T1 → T2
- T3 → T2
๐ Check Cycle
We have:
❌ Final Answer (S1):
Not conflict serializable
(ii) Schedule S2
๐น Step 1: Transactions
T1, T2
๐น Step 2–4: Find conflicts
On X:
-
R2(X) before W1(X) → Read–Write conflict
→ Edge: T2 → T1
On Y:
-
W2(Y) before R1(Y) → Write–Read conflict
→ Edge: T2 → T1
๐น Step 5: Precedence Graph
Edges:
- T2 → T1
๐ Check Cycle
- No cycle
✅ Final Answer (S2):
Conflict serializable
Equivalent serial order:




Comments
Post a Comment