Transactions and concurrency control
Serializability preserves a possible serial outcome; recovery rules govern what may be committed or read after failures. Test these independently. A schedule can satisfy one property and fail the other.
7.1 ACID, states and anomalies
Past papers · CS 2014–2026 (23 papers): 4 questions, 4 marks
| Property | Required behaviour |
|---|---|
| Atomicity | Either the transaction's effects all take effect or none do |
| Consistency | A correctly written transaction takes a valid state to a valid state |
| Isolation | Concurrent execution respects the promised isolation model; full serializability corresponds to a serial execution |
| Durability | Effects acknowledged as committed survive the assumed failures |
A transaction proceeds through active, partially committed and committed states; failures lead to failed and aborted states, after which it may restart. Finishing the final statement is not necessarily durable commit. Deadlock freedom is not an ACID property.
| Anomaly | What goes wrong |
|---|---|
| Lost update | Two transactions compute from the same old value; one overwrites the other's change |
| Dirty read | A transaction reads another's uncommitted write |
| Non-repeatable read | Re-reading a row sees an intervening committed change |
| Phantom | Re-running a predicate query sees a changed qualifying row set |
| Inconsistent analysis | An aggregate mixes states from different moments |
The standard isolation-level progression forbids dirty reads at READ COMMITTED, additionally non-repeatable reads at REPEATABLE READ, and phantoms at SERIALIZABLE. Implementations may offer stronger behaviour. Row locks alone need not prevent phantoms; predicate or range protection, or an equivalent serializable mechanism, is needed.
7.2 Conflicts, precedence graphs and schedule counts
Past papers · CS 2014–2026 (23 papers): 12 questions, 22 marks
Write for transaction reading, writing, committing and aborting. Operations conflict when they belong to different transactions, touch the same item and at least one is a write. Read–read is not a conflict. A schedule must preserve the given operation order inside each transaction.
A precedence graph with three serial orders: only the edge from T2 to T3 is forced.
7.3 View equivalence and blind writes
View equivalence preserves three items for every data object: which reads see its initial value, which exact transaction write supplies each read, and which transaction performs its final write. View serializable means view-equivalent to some serial schedule. Conflict serializability implies view serializability; the converse can fail with blind writes, meaning writes not preceded by a read of that item in the transaction.
To test a small schedule, record a reads-from table and final writer for each item, then check candidate serial orders. A view-serializable but non-conflict-serializable schedule must contain blind writes; merely having a blind write does not guarantee such a schedule.
7.4 Recoverability, cascadelessness and strictness
Past papers · CS 2014–2026 (23 papers): 3 questions, 5 marks
A read sees the most recent preceding write to that item in a single-version schedule, or the initial value if there is none. Determine this actual source before testing recovery properties; an earlier overwritten write is not the source.
A recoverable schedule can contain dirty reads if readers wait to commit. If the source aborts, all direct and indirect readers of its uncommitted result must abort: propagate through the reads-from graph. A cascadeless schedule may still allow a dirty write, so it need not be strict. These implications do not establish serializability.
7.5 Locks, two phases and deadlock prevention
Past papers · CS 2014–2026 (23 papers): 4 questions, 6 marks
Shared locks permit reads; exclusive locks permit writes and reads. Different transactions can share S locks; an X lock conflicts with every other S or X lock on that item. A lock upgrade S→X must occur during growth; an X→S downgrade begins or belongs to shrinking in 2PL.
| Protocol | Rule beyond compatible locking | Guarantees |
|---|---|---|
| Basic 2PL | After the first release, acquire no further lock | Conflict serializability; deadlocks and cascading aborts remain possible |
| Strict 2PL | Basic 2PL; keep X locks until commit/abort | Conflict serializability and strict schedules |
| Rigorous 2PL | Keep both S and X locks until commit/abort | Same guarantees; commit order is a serial order |
| Conservative 2PL | Acquire all needed locks together before execution; otherwise wait holding none | Conflict serializability and no deadlock; not automatically strict |
A 2PL transaction's lock point is its last acquisition. Ordering transactions by lock points gives a conflict-equivalent serial order. Some texts call rigorous 2PL “strict 2PL”; check which locks the definition retains. Two-phase locking is unrelated to distributed two-phase commit.
A wait-for graph has edge requester→holder for a blocking incompatible lock. A cycle detects deadlock under the usual single-item lock model. Requiring all lock acquisitions in one fixed global object order prevents such cycles. Starvation is repeated indefinite delay; deadlock freedom alone does not eliminate it.
Let older mean smaller transaction timestamp. For a conflicting request:
| Policy | Older requester, younger holder | Younger requester, older holder |
|---|---|---|
| Wait–die | Requester waits | Requester aborts |
| Wound–wait | Holder aborts | Requester waits |
Keep the original timestamp on restart. Waiting edges then follow one strict age direction, preventing cycles. With fair service and eventual completion of older transactions, retaining age prevents perpetual victimisation by newcomers.
7.6 Timestamp ordering and Thomas' write rule
Let be the unique timestamp of . For item , is the largest timestamp of any successful reader and that of any successful writer. Start them below all transaction timestamps.
Thomas' write rule changes the write test in this order: first abort if ; otherwise, if , ignore the obsolete write and continue; otherwise perform it and update . Reads follow the basic rule. Ignoring obsolete writes admits some view-serializable schedules that are not conflict serializable; do not silently discard an obsolete read.
7.7 Validation and multiversion ideas
Optimistic control runs a read phase on a private workspace, validates for conflicts and then publishes writes. Denote transaction 's read and write sets by , and its start, validation and finish instants by .
Multiversion timestamp ordering keeps versions labelled by write timestamps. A read by uses the version with greatest write timestamp not exceeding . In basic multiversion timestamp ordering, if a write targets that version and its read timestamp exceeds , abort; otherwise create a new version (or update the version written by the same timestamp). This can reduce read–write waiting but requires version storage and cleanup.
Snapshot isolation reads a consistent snapshot and typically checks write–write conflicts. It is not automatically serializable: two transactions can read a common invariant and update different rows, producing write skew. Distinguish this from protocols that explicitly enforce multiversion serializability.
7.8 Logging, checkpoints and recovery
Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks
A physical update log records the transaction, item, old value and new value. Write-ahead logging requires the relevant log record to reach stable storage before the changed data page; the commit log record and preceding transaction log records must be durable before commit is acknowledged. This allows recovery even when committed data pages have not yet been written.
| Buffer policy | Consequence after a crash |
|---|---|
| STEAL: uncommitted dirty pages may reach disk | UNDO may be necessary |
| NO-STEAL | Uncommitted changes need not be undone on disk |
| FORCE: transaction's data pages durable at commit | REDO of that transaction's data is unnecessary |
| NO-FORCE | REDO may be necessary |
STEAL/NO-FORCE needs both undo and redo information. Deferred database updates normally avoid disk undo; immediate updates may need it. UNDO restores before-images in reverse log order; REDO restores after-images in forward order. Reapplying a value is idempotent; blindly reapplying an increment is not.
For a simple checkpoint that forces relevant log records and dirty pages and records active transactions, pre-checkpoint completed transactions need no replay. Transactions active at the checkpoint can still need earlier records for undo. Redo committed transactions whose effects may not be durable; undo incomplete transactions. A fuzzy checkpoint does not imply that all dirty pages are forced, so its log-start rule differs.
If recovery itself crashes, restart from durable recovery metadata. In the simple model with no new checkpoint or progress log, the original lists can be replayed using idempotent actions. More advanced recovery logs undo progress; do not assume it repeats identical lists. No log needed for active recovery may be discarded merely because a checkpoint exists.
Last-minute recall
- Conflict means same item, different transactions, and at least one write.
- An acyclic precedence graph is exactly the conflict-serializability test.
- View equivalence preserves reads-from and final writers.
- Strict ⇒ cascadeless ⇒ recoverable; serializability is a separate axis.
- Basic 2PL can deadlock and need not be recoverable.
- Wait–die aborts a younger requester; wound–wait aborts a younger holder.
- Thomas' rule ignores an obsolete write only after checking the read timestamp.
- STEAL calls for UNDO; NO-FORCE calls for REDO.