1. Gyanastra
  2. Database Systems
  3. Recoverability
  4. Recoverable vs Unrecoverable Schedules
Free lesson, no account needed 8 min read 9 practice questions after it
Asked in past papers7 times
  • GATE CSE20212016201520142003
  • ISRO2009
  • UGC NET2023

Database Systems · Recoverability

Recoverable vs Unrecoverable Schedules

Overview

Recoverability of a schedule is determined by where the commit and abort/rollback operations of the involved transactions are placed.
A schedule is recoverable only if every transaction that performs a dirty read commits after the transaction that wrote the data commits; otherwise the schedule is unrecoverable.

Key concepts

  • Recoverable schedule: If a transaction reads a value written by another transaction that has not yet committed (a dirty read), it must not commit until the other transaction commits.
    If the other transaction rolls back, this transaction must also be able to roll back.
  • Unrecoverable schedule: A transaction performs a dirty read and commits before the transaction that wrote the data commits.
    If the writer later aborts/rolls back, the reader's committed changes would have to be undone, which is not allowed.
  • Dirty read: Reading data that has been written by a transaction that is not yet committed.
  • Cascading rollback: If the transaction that wrote the uncommitted data rolls back, the transaction that read that data also rolls back. Having this chance to roll back is what makes a schedule recoverable.
  • Commit: Whatever changes a transaction made should be permanently available and must not be undone.
  • Atomicity: If a transaction fails, it must roll back all its changes.

How it works

  1. T1 starts and reads A = 100.
  2. T1 makes its local copy A − 50 = 50.
  3. T1 writes this value back into the database, so A = 50 in the database.
  4. T1 has not committed yet.
  5. T2 reads A from the database. Since T1 has already written A = 50, T2 reads 50 instead of 100. This is a dirty read.
  6. T2 increments the value by 4%: 4% of 50 = 2, so A becomes 52.
  7. T2 writes A = 52 into the database.
  8. T2 commits.
  9. After executing for some time, T1 decides to roll back because of some failure — for example, a hard disk failure, hardware failure, power failure, or any other failure.
    According to the atomicity rule, T1 must undo all its changes.
  10. T1 therefore tries to reset A from 50 back to 100.
  11. But T2 has already committed. If T1's rollback is allowed, then the change made by T2 is lost. T2's commit promised that its actions would remain permanent, but T1's rollback removes them. This violates the meaning of commit.
  12. Therefore, this schedule is unrecoverable.

The rule that makes a schedule recoverable: whenever a transaction reads data that is not committed, it should not commit until the other transaction has committed.
If the other transaction rolls back, this transaction must also roll back. Only then is consistency maintained.
When a transaction performs a dirty read, its commit must be ordered after the commit of the transaction that wrote the data.

Formulas

  • Anew=Aold−50A_{new} = A_{old} - 50 — T1's transfer from A; AoldA_{old} is the value of A before T1 writes.
  • Anew=Aold+0.04×Aold=1.04×AoldA_{new} = A_{old} + 0.04 \times A_{old} = 1.04 \times A_{old} — T2's 4% increase of A; AoldA_{old} is the value T2 reads from the database.

Worked examples

Bank transfer example: T1 transfers 50 from account A to account B; initially A = 100. T2 increases A by 4%, i.e. T2 computes A = A + 4% of A.

StepOperationValue of A
1T1 reads A100
2T1 computes A − 5050
3T1 writes A50
4T2 reads A (dirty read, because T1 has not committed)50
5T2 computes A + 4% of A = 50 + 252
6T2 writes A52
7T2 commits52 permanently
8T1 rolls back and tries to restore A100

If T1's rollback is allowed, A becomes 100 and T2's committed value 52 is lost. Since T2 has already committed, its changes cannot be undone. Hence the schedule is unrecoverable.

In operation notation, the unrecoverable sequence is:

R1(A)   -- T1 reads A = 100
W1(A)   -- T1 writes A = 50
R2(A)   -- T2 reads A = 50 (dirty read)
W2(A)   -- T2 writes A = 52
C2      -- T2 commits
Rollback1 -- T1 aborts and tries to restore A = 100

Recoverable version of the same idea:

R1(A)
W1(A)
R2(A)   -- dirty read by T2
        -- T2 must wait; it cannot commit yet
C1      -- T1 commits first
C2      -- then T2 commits

If T1 instead rolls back:

R1(A)
W1(A)
R2(A)
Rollback1
Rollback2   -- T2 also rolls back because it read T1's uncommitted data

This is a cascading rollback, and because T2 had the chance to roll back, the schedule is recoverable.

Exam analogy: Two people are cheating in an exam. One person writes an answer and the other copies it. Before the first person submits the answer paper, the second person submits the paper and leaves.
Later, the first person changes the answer. The second person has already submitted the copied answer, so the second person loses marks.
To avoid losing marks, the copier must not submit the answer paper until the other person has submitted. If the other person changes the answer, the copier must also change the answer.

Comparison

FeatureRecoverable scheduleUnrecoverable schedule
Dirty readMay occurMay occur
Commit order after dirty readReader commits only after writer commitsReader commits before writer commits or aborts
If writer rolls backReader can also roll backReader has already committed and cannot roll back
Effect on consistencyConsistency is preservedCommitted changes of the reader are lost if the writer rolls back
Rollback possibilityCascading rollback is possibleNo chance to undo the reader's committed change

Revision summary

  • Recoverability depends on where commit and abort/rollback are placed in the schedule.
  • A dirty read occurs when a transaction reads data written by another transaction that has not committed.
  • Commit means the transaction's changes must never be undone.
  • If a transaction fails, atomicity requires it to roll back all its changes.
  • If a transaction reads uncommitted data and commits, and the writer later rolls back, the schedule is unrecoverable.
  • Rule: after a dirty read, do not commit until the transaction that wrote the data commits.
  • The commit of the reader must be ordered after the commit of the writer.
  • If the writer rolls back, the reader must also roll back — this is cascading rollback; if this rollback chance exists, the schedule is recoverable, and if the reader has already committed, it is unrecoverable.

Previous-year exam insights

  • A schedule is recoverable iff for every pair of transactions Ti, Tj such that Tj reads a data item previously written by Ti, the commit operation of Ti appears before the commit operation of Tj.
    Asked inGATE 2016GATE 2015GATE 2014
  • Cascadeless (avoid cascading aborts) schedules are a strictly stronger class than recoverable schedules: Tj may read a data item only after Ti (the writer) has committed; every cascadeless schedule is recoverable, but not conversely.
    Asked inGATE 2016
  • Strict schedules are stronger still: a transaction may neither read nor write a data item until the last transaction that wrote it has committed or aborted; every strict schedule is cascadeless and hence recoverable.
    Asked inGATE 2016
  • Recoverability and conflict-serializability are independent properties: a schedule can be conflict-serializable but unrecoverable, or recoverable but not conflict-serializable, so both must be checked separately.
    Asked inGATE 2014
  • A dirty read (reading a data item written by an uncommitted transaction) is the only pattern that can make a schedule unrecoverable; reading data written by a committed transaction, or reading data that another uncommitted transaction has only read, never causes irrecoverability.
    Asked inGATE 2003UGC NET 2023ISRO 2009
  • In a recoverable schedule, if the writer aborts, every transaction that read its uncommitted data must abort too (cascading abort); the reader's commit must be delayed until the writer's commit, which is why the reader's commit is ordered after the writer's commit.
    Asked inGATE 2016GATE 2015
Pages 1–2 of 2