Skip to main content

Short note: Flat versus nested locks

Short answer

Flat locks are held by a single transaction and released at commit/abort, conflicting with any other transaction. Nested locks allow sub-transactions to acquire locks; a child can lock if conflicting holders are ancestors, and upon commit locks are inherited by the parent, increasing intra-transaction concurrency while maintaining serial equivalence.

Write a short note on flat versus nested locks.

In a flat transaction locks are held by one transaction, and the usual rules apply: locks are acquired as objects are accessed (growing phase), and under strict 2PL all are released together at commit or abort. Two locks conflict if they are from different transactions and at least one is a write.

In nested transactions, locks belong to sub-transactions, and the following rules are used (Moss):

  • A sub-transaction can acquire a read lock if every other holder of a write lock on the object is an ancestor.
  • It can acquire a write lock if every other holder of a read or write lock is an ancestor.
  • When a sub-transaction commits, its locks are inherited by its parent (the parent now holds them).
  • When a sub-transaction aborts, its locks are discarded; if the parent held the lock earlier, it still holds it.
PointFlat locksNested locks
HolderOne transactionSub-transaction (and parent by inheritance)
ReleaseAt commit/abortPassed to parent at child commit; final release at top level
ConcurrencyBetween top-level transactionsAlso between siblings, within a transaction
Conflict ruleAny other transactionNon-ancestors only

Nested locking increases concurrency inside a transaction while keeping serial equivalence among siblings.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Distributed System chapter 8 questions →