DBMS & SQLLevel 17
PART 4 • DATABASE SYSTEMS

Keep Concurrent Changes Correct and Recoverable

Reason about interleaved operations, prevent unsafe observations, resolve lock cycles and restore committed state after failure.

Level 17 of 18Concurrency & Recovery200–240 minutes
BY THE END, YOU CAN
  • Explain each ACID guarantee.
  • Trace concurrent schedules.
  • Build a precedence graph.
  • Apply two-phase locking.
  • Recognize isolation anomalies.
  • Use WAL reasoning for recovery.
01 • DEFINE THE UNIT OF WORK

A Transaction Moves the Database between Valid States

BEFOREA = ₹1,000B = ₹500Total = ₹1,500
BEGINA = A − ₹200B = B + ₹200COMMIT
AFTERA = ₹800B = ₹700Total = ₹1,500
A

Atomicity

All transaction effects become durable together, or none remain after rollback/recovery.

C

Consistency

A correctly written transaction preserves declared constraints and application invariants.

I

Isolation

Concurrent execution is controlled so transactions do not observe disallowed intermediate effects.

D

Durability

After commit succeeds, recovery mechanisms preserve the transaction despite later failure.

02 • INTERLEAVE WITHOUT REORDERING EACH TRANSACTION

A Schedule Preserves Each Transaction's Internal Order

SERIAL
T1: R(X)T1: W(X)T1: CT2: R(X)T2: W(X)T2: C

One transaction finishes before another begins. Simple but restricts concurrency.

INTERLEAVED
T1: R(X)T2: R(Y)T1: W(X)T2: W(Y)T1: CT2: C

Operations overlap while each transaction's own program order remains intact.

Recoverable

If T2 reads a value written by T1, T2 commits only after T1 commits.

Cascadeless

Transactions read only committed values, avoiding cascading rollback from dirty dependencies.

Strict

No other transaction reads or writes an item written by an uncommitted transaction.

03 • NAME THE FAILURE PATTERN

Concurrency Anomalies Reveal Which Guarantee Was Missing

DIRTY READ

Read uncommitted data

T2 uses T1's new value, but T1 later rolls back.

NON-REPEATABLE READ

One row changes

T1 reads the same row twice and sees a committed update by T2 between reads.

PHANTOM

The qualifying row set changes

T1 repeats a predicate query and sees inserted, deleted or newly qualifying rows.

LOST UPDATE

One write overwrites another

Two transactions derive new values from stale reads; the later write erases earlier work.

DIRTY WRITE

Overwrite uncommitted data

T2 overwrites a value written by active T1, making rollback unsafe.

WRITE SKEW

Separate rows break one invariant

Transactions read the same condition, update different rows and jointly violate a constraint.

04 • TEST EQUIVALENCE TO A SERIAL ORDER

Conflict Serializability Becomes a Graph Problem

SAME DATA ITEMBoth operations touch X
+
DIFFERENT TRANSACTIONST1 and T2
+
AT LEAST ONE WRITER/W, W/R or W/W
=
CONFLICTOrder matters
  1. Create one node per transaction.
  2. Scan conflicting operation pairs in schedule order.
  3. Add edge Ti → Tj when Ti's conflicting operation occurs first.
  4. If the graph has no directed cycle, the schedule is conflict-serializable.
  5. A topological order gives an equivalent serial order.
EXAMPLE EDGEST1 → T2T2 → T3No cycle → serial order T1, T2, T3
05 • CONTROL CONFLICTING ACCESS

Locks Coordinate Readers and Writers

Requested / HeldShared (S)Exclusive (X)
Shared (S)CompatibleWait
Exclusive (X)WaitWait
SHARED LOCK

Multiple transactions can read the same item when none holds an exclusive lock.

EXCLUSIVE LOCK

A writer excludes other readers/writers under this simplified compatibility model.

LOCK UPGRADE

Moving S → X may wait if another shared holder remains and can contribute to deadlock.

GRANULARITY

Row locks improve concurrency; page/table locks reduce lock-management overhead.

GROWING PHASEAcquire or upgrade locks

No lock has yet been released.

LOCK POINT
SHRINKING PHASERelease locks

Basic 2PL acquires no new lock after the first release.

Strict 2PL: hold exclusive locks until commit or rollback. This prevents dirty reads of written items and simplifies recovery. Two-phase locking ensures conflict serializability but can create deadlocks.

06 • CHOOSE AN ACCEPTABLE VISIBILITY GUARANTEE

Isolation Levels Balance Anomaly Protection and Concurrency

SQL levelDirty readNon-repeatable readPhantomTypical idea
READ UNCOMMITTEDPossiblePossiblePossibleWeakest standard level
READ COMMITTEDPreventedPossiblePossibleEach statement sees committed data
REPEATABLE READPreventedPreventedStandard permits phantomsRepeated row reads remain stable
SERIALIZABLEPreventedPreventedPreventedOutcome equivalent to serial execution
ROW V1₹500visible to older snapshot
→ update creates →
ROW V2₹650visible to eligible newer snapshot

MVCC

Multi-version concurrency control lets readers use appropriate row versions instead of always blocking writers. Visibility rules, isolation semantics and cleanup differ by database product.

07 • MAKE COMMIT SURVIVE FAILURE

Write-Ahead Logging Records Intent before Data Pages

1 • UPDATE REQUEST

T7 changes account A from 500 to 650.

2 • LOG RECORD<T7, A, old=500, new=650>

Required log information reaches stable storage before the changed data page.

3 • COMMIT RECORD

Commit is acknowledged only after required log records are durable.

4 • DATA PAGE

The changed page may be written later.

UNDO

Remove incomplete effects

Use before-images or inverse information for transactions without a durable commit.

REDO

Repeat committed effects

Use after-images for committed work not yet reflected in recovered data pages.

CHECKPOINT

Bound recovery work

Records recovery metadata so restart need not reason from the beginning of the entire log.

ARIES IDEA

Analysis, redo, undo

Widely taught recovery approach using WAL, repeating history and compensation log records.

Transaction failure rollback that transactionSystem crash use durable log during restartMedia failure restore backup, then apply archived/logged changes
08 • TRACE EVERY OPERATION

Interactive Schedule & Serializability Simulator

Choose a schedule and step through reads, writes, commits and aborts. Watch values, dependencies and the final diagnosis change.

DATABASE VALUE
STEP
STATUS
09 • FIND THE WAIT CYCLE

Deadlock Detection Laboratory

Build each wait-for graph step by step. A directed cycle means the transactions cannot all proceed without intervention.

10 • CHECK YOUR UNDERSTANDING

Ten Formative Concept Checks

1. Atomicity means:

2. T2 reads T1's uncommitted write and T1 later aborts. This is:

3. Two operations conflict when they are from different transactions, access the same item and:

4. A precedence graph with a directed cycle is:

5. Shared locks are normally compatible with:

6. Basic two-phase locking requires:

7. In a wait-for graph, a directed cycle indicates:

8. Under SQL-standard READ COMMITTED, which anomaly is prevented?

9. Write-ahead logging requires the relevant log record to be durable:

10. After a crash, REDO is used mainly to:

Answered correctly: 0 of 10
11 • EXPLAIN & PREPARE

University and Interview Questions

2-MARK
  1. Define ACID.
  2. What is a schedule?
  3. Define deadlock.
  4. What is WAL?
5-MARK / PRACTICAL
  1. Test conflict serializability.
  2. Compare recoverable, cascadeless and strict schedules.
  3. Explain two-phase locking.
  4. Trace undo and redo after a crash.
INTERVIEW
  1. Why can serializable transactions still retry?
  2. How does MVCC reduce reader/writer blocking?
  3. How would you investigate a deadlock?
  4. What does a checkpoint guarantee?
Show the transaction answer framework
  1. Name every transaction, item and operation.
  2. Preserve each transaction's program order.
  3. Identify conflicting pairs and dirty dependencies.
  4. Draw precedence or wait-for edges.
  5. Check cycles and commit/abort order.
  6. State the anomaly or correctness property.
  7. Choose isolation, locking or recovery action and explain the trade-off.

You Can Now Reason about Concurrent Failure

  • ACID defines transaction correctness and survival.
  • Schedules interleave operations while preserving local order.
  • Conflict graphs test serializability.
  • Locks control access but may deadlock.
  • Isolation defines permitted visibility.
  • WAL, checkpoints, undo and redo support recovery.
COURSE CHECKPOINT

Mark this level when you can trace schedules, diagnose cycles and explain recovery decisions.

Saved in this browser only.