Sub topic 2
Testing conflict serializability with a precedence graph
This chapter assumes you know basic transaction notation, such as R1(A) for transaction T1 reading item A, and you can read a directed graph. It covers how to test a schedule for serializability, how that test relates to view serializability, how to classify recoverability, and how lock modes work.
Conflict serializability
Two operations conflict when they come from different transactions, touch the same item, and at least one is a write. A schedule is conflict serializable if you can reorder its non-conflicting operations until it becomes a serial schedule.
To test this, build a precedence graph. Draw one node per transaction. Add an edge Ti → Tj when an operation of Ti conflicts with a later operation of Tj. The schedule is conflict serializable if and only if the graph has no cycle. A topological order of the graph gives an equivalent serial order.
def precedence_edges(schedule):
edges = set()
for i, (ti, oi, xi) in enumerate(schedule):
for tj, oj, xj in schedule[i + 1:]:
if ti != tj and xi == xj and 'W' in (oi, oj):
edges.add((ti, tj))
return edges
s = [('T1', 'R', 'A'), ('T2', 'W', 'A'), ('T1', 'W', 'A')]
print(precedence_edges(s)) # {('T1', 'T2'), ('T2', 'T1')}: a cycle, so not serializableView serializability
A schedule is view serializable when some serial schedule gives every transaction the same reads-from relation and the same final writes. Every conflict serializable schedule is view serializable. The converse does not hold. Schedules with blind writes can be view serializable without being conflict serializable. GATE questions usually test conflict serializability because it is easier to check.
Recoverability
- Recoverable: a transaction commits only after every transaction it read from has committed.
- Cascadeless: transactions read only values written by committed transactions, so one abort does not force other aborts.
- Strict: no item is read or overwritten until the transaction that last wrote it commits or aborts.
Every strict schedule is cascadeless, and every cascadeless schedule is recoverable.
Shared and exclusive locks
A shared (S) lock allows reads. An exclusive (X) lock allows reads and writes. The compatibility matrix says which requests can be granted alongside a held lock.
| Held lock \ Requested | S | X |
|---|---|---|
| None | Yes | Yes |
| S | Yes | No |
| X | No | No |
Exercise
Exercise
Is the schedule R1(A), W2(A), W1(A) conflict serializable? Justify your answer using the precedence graph.
Show answer
No. The conflicts give T1 → T2 (R1(A) before W2(A)) and T2 → T1 (W2(A) before W1(A)). This forms a cycle, so no topological order exists.