Sub topic 8
Recoverable, cascadeless and strict schedules
This chapter assumes you know the following from earlier chapters:
- How to write a schedule in the notation Ri(X), Wi(X), Ci, Ai.
- What a dirty read is.
- The idea of a conflict between two operations.
Serializability asks whether a schedule gives the same result as some serial one. Recoverability asks a different question: what happens if a transaction aborts after others have already seen or overwritten its data? A schedule can be serializable and still be impossible to undo safely.
Why recoverability is a separate property
Atomicity says an aborted transaction must leave no effect. Durability says a committed transaction must never be undone. If T2 reads a value written by T1, and T1 later aborts, the system faces two bad choices:
- Keep T2's result, which was computed from data that officially never existed.
- Undo T2, which is impossible if T2 has already committed.
The definitions below limit how interleaving may touch uncommitted data. They are checked on the order of reads, writes, commits and aborts. Conflict cycles do not matter here.
Reads-from
Transaction Tj reads X from Ti if Ti wrote X, Tj later read X, Ti had not aborted before that read, and no other transaction wrote X in between. Everything in this chapter is built on this relation.
The three classes
Recoverable
A schedule is recoverable if, whenever Tj reads from Ti (with i ≠ j), Ti commits before Tj commits.
The rule constrains only the order of commits. T2 may read dirty data, but it must wait to commit until the writer has committed.
S1: W1(A) R2(A) C2 C1 not recoverable
S2: W1(A) R2(A) C1 C2 recoverableIn S1, T2 commits after reading T1's uncommitted value. If T1 now aborts, T2's commit cannot be undone, and durability and atomicity collide.
Cascadeless (avoids cascading aborts)
A schedule is cascadeless (ACA) if every read Tj(X) happens only after the transaction that last wrote X has committed. No transaction ever reads uncommitted data.
S2 above is recoverable but not cascadeless. If T1 aborts before committing, T2 must be aborted too, and so must anyone who read from T2. That chain of forced aborts is a cascading rollback, and it wastes work.
Strict
A schedule is strict if no transaction reads or overwrites X until the last transaction that wrote X has committed or aborted.
Strictness adds the write-write case. Consider this schedule:
S3: W1(A) W2(A) C1 C2S3 has no reads, so it is recoverable and cascadeless. It is not strict, because T2 overwrote A while T1 was still active. Systems recover by restoring before-images (the old value). If T1 aborts, restoring its before-image wipes out T2's write. If T2 had aborted first, restoring T2's before-image would reinstate a value T1 may not have committed. Strict schedules make before-image recovery safe.
The hierarchy
strict ⊂ cascadeless ⊂ recoverable ⊂ all schedulesEvery serial schedule is strict. Each property is a strictly stronger restriction than the one outside it.
| Property | Forbids | Consequence if it holds |
|---|---|---|
| Recoverable | Commit before the writer you read from commits | No committed transaction ever has to be undone |
| Cascadeless | Reading uncommitted data | Also no cascading aborts |
| Strict | Reading or overwriting uncommitted data | Also simple before-image rollback |
Worked classification
Take this schedule:
W1(A) R2(A) W2(B) C1 C2- T2 reads A from T1 while T1 is still active. So the schedule is not cascadeless, and so not strict.
- T1 commits before T2. So the reads-from rule holds and the schedule is recoverable.
- Answer: recoverable, not cascadeless.
Now change the order to W1(A) C1 R2(A) W2(A) C2. Every access to A happens after the previous writer committed, so the schedule is strict.
A classifier you can run
The function below walks a schedule once. It tracks the most recent live write per item, flags reads and overwrites of uncommitted data, and checks commit order for every reads-from pair. Operations are (txn, op, item) where op is R, W, C or A. For C and A the item is None.
def classify(schedule):
status = {} # txn -> 'active', 'committed' or 'aborted'
commit_pos = {} # txn -> position of its commit
writers = {} # item -> transactions that wrote it, in order
reads_from = set() # (reader, writer)
strict = True
cascadeless = True
for pos, (t, op, x) in enumerate(schedule):
status.setdefault(t, 'active')
if op == 'C':
status[t] = 'committed'
commit_pos[t] = pos
elif op == 'A':
status[t] = 'aborted'
else:
live = [w for w in writers.get(x, [])
if status.get(w, 'active') != 'aborted']
last = live[-1] if live else None
if last is not None and last != t:
if status[last] == 'active':
strict = False
if op == 'R':
cascadeless = False
if op == 'R':
reads_from.add((t, last))
if op == 'W':
writers.setdefault(x, []).append(t)
for reader, writer in reads_from:
if status[reader] == 'committed':
if status[writer] != 'committed' or \
commit_pos[writer] > commit_pos[reader]:
return 'not recoverable'
if strict:
return 'strict'
if cascadeless:
return 'cascadeless'
return 'recoverable'
C = None
s1 = [(1,'W','A'), (2,'R','A'), (2,'C',C), (1,'C',C)]
s2 = [(1,'W','A'), (2,'R','A'), (1,'C',C), (2,'C',C)]
s3 = [(1,'W','A'), (2,'W','A'), (1,'C',C), (2,'C',C)]
s4 = [(1,'W','A'), (1,'C',C), (2,'R','A'), (2,'W','A'), (2,'C',C)]
for s in (s1, s2, s3, s4):
print(classify(s))
# not recoverable
# recoverable
# cascadeless
# strictThe code ignores a writer once it has aborted, because its writes are rolled back. A reader that read from a writer that later aborts is caught as not recoverable only if the reader has committed. If the reader is still active, it would need a cascading abort, which the class recoverable permits.
Independence from serializability
Serializability and recoverability are separate properties. All four combinations exist.
- Serial schedule: serializable and strict.
- S1 above:
W1(A) R2(A) C2 C1is conflict serializable (only the edge T1→T2) but not recoverable. - Strict but not serializable:
R1(A) W2(A) C2 W1(A) C1has no reads-from pair, and every write finds the previous writer committed. So it is strict. But the precedence graph has the edges T1→T2 and T2→T1, so it is not conflict serializable. T1's update is lost. - Neither: a schedule that both breaks the commit order and contains a cycle.
How concurrency control produces these schedules
Locking protocols give recoverability properties as a side effect of when they release locks. You will see the details in the two-phase locking chapter. The summary:
| Protocol | Releases locks | Guarantees about recovery |
|---|---|---|
| Basic 2PL | Any time after the last lock is acquired | Serializable, but may be non-recoverable |
| Strict 2PL | Exclusive locks held until commit or abort | Strict schedules, hence cascadeless and recoverable |
| Rigorous 2PL | All locks held until commit or abort | Strict, and serial order equals commit order |
Holding exclusive locks to the end blocks both a dirty read and a dirty overwrite. That is exactly the strictness condition.
Common errors in GATE questions
- Counting commits wrongly. Recoverability concerns only reads-from pairs. A write-write pair with out-of-order commits does not break recoverability.
- Forgetting the overwrite case for strict. A schedule with no dirty reads is cascadeless. It is strict only if there are also no dirty overwrites.
- Missing commits. If a schedule shows no commit or abort operations, read the question's assumptions. Often every transaction commits at the end, in the order stated.
- Assuming a cascading rollback means a bug in the schedule. A recoverable schedule that is not cascadeless is legal. It is only expensive to roll back.
- Reading from your own write. Tj reading its own value is not a reads-from pair with another transaction, so it never creates a constraint.
Exercise
Classify each schedule as not recoverable, recoverable only, cascadeless but not strict, or strict. (a) W1(X) R2(X) C1 C2 (b) W1(X) W2(X) C2 C1 (c) R1(X) W2(X) C2 W1(X) C1 (d) W1(X) R2(X) C2 A1
Show answer
(a) Recoverable only: T2 reads uncommitted X but commits after T1. (b) Cascadeless but not strict: no reads, but T2 overwrites T1's uncommitted write. (c) Strict: T1 only reads, and T1's later write follows T2's commit. (d) Not recoverable: T2 read from T1 and committed, then T1 aborted.
Exercise
For the schedule W1(A) W2(A) A1 C2, explain why before-image recovery fails, and name the class the schedule falls in if no reads occur and the commit order is respected.
Show answer
Aborting T1 restores A to the value before T1's write. That erases T2's write, even though T2 later commits. The schedule has no reads, so it is recoverable and cascadeless, but it is not strict because T2 overwrote A while T1 was active.
Exercise
Give a schedule of T1 and T2 that is strict but not conflict serializable.
Show answer
R1(A) W2(A) C2 W1(A) C1. T1 never reads or overwrites uncommitted data, so the schedule is strict. The precedence graph has T1→T2 (R1(A) before W2(A)) and T2→T1 (W2(A) before W1(A)), which is a cycle.