- Model question
Transaction, nested transaction, atomicity
Short answer
A transaction is an indivisible unit of operations with ACID properties, e.g., a bank transfer. Nested transactions are trees of sub-transactions that commit provisionally; a parent can retry if a child aborts. Atomicity is enforced by tentative updates, write-ahead logs for undo/redo, and strict two-phase locking with atomic commit.
Define transaction and nested transaction with examples. Explain how an atomicity is gained in transactions.
Transaction
A transaction is a sequence of operations on shared data that the system treats as one indivisible unit of work: either all operations take effect or none does. It is described by the ACID properties:
- Atomicity: all or nothing.
- Consistency: it moves the data from one consistent state to another.
- Isolation: concurrent transactions do not see each other's intermediate results (appear serial).
- Durability: once committed, results survive crashes (stored in permanent storage).
Example: a bank transfer debit A; credit B in one transaction.
Nested transaction
- Nested transaction: a transaction made of sub-transactions in a tree. The top-level transaction contains child transactions, which may contain their own children. Sub-transactions at the same level can run concurrently, and a sub-transaction can abort without aborting its parent; the parent may retry or choose another action. Example: a book trip transaction with sub-transactions book flight, book hotel, book taxi. If the taxi booking fails, the parent can try another company.
Rules of nested transactions:
- A sub-transaction commits only provisionally; its result becomes permanent only when all its ancestors commit up to the top level.
- If a parent aborts, all its sub-transactions abort, even those that provisionally committed.
- A child sees the parent's changes, but the parent does not see the child's until the child commits.
How atomicity is gained
Atomicity means that after a failure or abort no partial effect remains. It is achieved by:
- Private workspace / tentative versions: updates are made on tentative copies, and they become permanent only at commit.
- Write-ahead log: before any change, the old and new values are written to a log on stable storage. On abort or crash, uncommitted changes are undone, and committed ones redone from the log.
- Shadow paging: the database is switched to the new page table atomically at commit.
- Atomic commit (two-phase commit) for distributed transactions, so all servers commit or all abort.
- Concurrency control (strict 2PL), which stops other transactions from seeing uncommitted data and so avoids cascading aborts.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Flat/nested transactions; optimistic CC · Distributed System, chapter 8
- Nested vs distributed transaction; 2PC · Distributed System, chapter 8 · asked 2×
- Flat/nested transactions; concurrency control · Distributed System, chapter 8
- Nested transactions; optimistic CC advantages · Distributed System, chapter 8
- Distributed and nested distributed transactions · Distributed System, chapter 8
- Locks in transactions; lost update · Distributed System, chapter 8
- Apriori on 8 transactions, 25% support · Data Mining, chapter 4
- Apriori on four transactions, support 2 · Data Mining, chapter 4