Chapter 7

Transactions and concurrency controlCS

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 anomaliesCS

Past papers · CS 2014–2026 (23 papers): 4 questions, 4 marks

PropertyRequired behaviour
AtomicityEither the transaction's effects all take effect or none do
ConsistencyA correctly written transaction takes a valid state to a valid state
IsolationConcurrent execution respects the promised isolation model; full serializability corresponds to a serial execution
DurabilityEffects 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.

AnomalyWhat goes wrong
Lost updateTwo transactions compute from the same old value; one overwrites the other's change
Dirty readA transaction reads another's uncommitted write
Non-repeatable readRe-reading a row sees an intervening committed change
PhantomRe-running a predicate query sees a changed qualifying row set
Inconsistent analysisAn 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 countsCS

Past papers · CS 2014–2026 (23 papers): 12 questions, 22 marks

Write ri(x),wi(x),ci,air_i(x),w_i(x),c_i,a_i for transaction TiT_i 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.A precedence graph with three serial orders: only the edge from T2 to T3 is forced.

7.3 View equivalence and blind writesCS

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 strictnessCS

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 preventionCS

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.

ProtocolRule beyond compatible lockingGuarantees
Basic 2PLAfter the first release, acquire no further lockConflict serializability; deadlocks and cascading aborts remain possible
Strict 2PLBasic 2PL; keep X locks until commit/abortConflict serializability and strict schedules
Rigorous 2PLKeep both S and X locks until commit/abortSame guarantees; commit order is a serial order
Conservative 2PLAcquire all needed locks together before execution; otherwise wait holding noneConflict 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:

PolicyOlder requester, younger holderYounger requester, older holder
Wait–dieRequester waitsRequester aborts
Wound–waitHolder abortsRequester 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 ruleCS

Let TSiTS_i be the unique timestamp of TiT_i. For item xx, RTS(x)RTS(x) is the largest timestamp of any successful reader and WTS(x)WTS(x) that of any successful writer. Start them below all transaction timestamps.

Thomas' write rule changes the write test in this order: first abort if TSi<RTS(x)TS_i<RTS(x); otherwise, if TSi<WTS(x)TS_i<WTS(x), ignore the obsolete write and continue; otherwise perform it and update WTSWTS. 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 ideasCS

Optimistic control runs a read phase on a private workspace, validates for conflicts and then publishes writes. Denote transaction TiT_i's read and write sets by RSi,WSiRS_i,WS_i, and its start, validation and finish instants by si,vi,fis_i,v_i,f_i.

Multiversion timestamp ordering keeps versions labelled by write timestamps. A read by TiT_i uses the version with greatest write timestamp not exceeding TSiTS_i. In basic multiversion timestamp ordering, if a write targets that version and its read timestamp exceeds TSiTS_i, 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 recoveryCS

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 policyConsequence after a crash
STEAL: uncommitted dirty pages may reach diskUNDO may be necessary
NO-STEALUncommitted changes need not be undone on disk
FORCE: transaction's data pages durable at commitREDO of that transaction's data is unnecessary
NO-FORCEREDO 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.

Revise offline: the whole Databases and Data Warehousing handbook as one PDF

58 pages · 2.7 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections