Lecture: Lecture 19 - Distributed Database Management Systems
Related: Distributed Architectures Fragmentation Allocation and Transparency · X-Open-DTP Optimizations Parallel DBMS and TPC Benchmarks · Warm Restart Problem Solving and Cold Restart · Two-Phase Locking and Strict 2PL · Replication CAP Theorem ACID vs BASE and Conflict Resolution
Transaction classification (Slides 30–36)
A client submits a transaction to one DBMS server, which is responsible for redistributing work across servers when needed (Slide 31). Based on the SQL commands allowed and how many servers each statement and transaction touch, distributed transactions fall into four complexity classes (Slides 32–33):
| Class | SQL Allowed | Servers per SQL Statement | Servers per Transaction | Key Requirement / Property |
|---|---|---|---|---|
| 1. Remote request (Slide 32) | Read-only (SELECT only) | 1 remote server | 1 remote server | Simplest remote access |
| 2. Remote transaction (Slide 32) | Any SQL command | 1 remote server | 1 remote server | Local ACID only |
| 3. Distributed transaction (Slide 33) | Any SQL command | 1 server per statement | Multiple servers | Requires global atomicity via 2-Phase Commit (2PC) |
| 4. Distributed request (Slide 33) | Any SQL command | Multiple servers in a single statement | Multiple servers | Requires distributed query optimization; ONLY class supporting fragmentation transparency |
Worked source example: Bank transfer (Slides 34–36)
Given Account(Acc#, Name, Balance) horizontally fragmented across two nodes:
- on Node 1
- on Node 2
Consider transferring 100 from Acc# = 3000 to Acc# = 13000:
BoT
UPDATE Account SET Balance = Balance - 100 WHERE Acc# = 3000
UPDATE Account SET Balance = Balance + 100 WHERE Acc# = 13000
EoT- Written against
Account(as above): Distributed request — becauseAccountis not explicitly partitioned in the SQL, the DBMS must map the query ontoA1andA2using fragmentation transparency. - Written explicitly against
A1andA2: Distributed transaction — each SQL statement addresses one single server (A1on Node 1,A2on Node 2), and the transaction as a whole spans two servers. - If both updates target only
A1(e.g.,Acc# = 3000andAcc# = 9000): Remote transaction — all work stays on Node 1.
Added practice example from the study session (outside the PDF)
(Added example outside the source PDF): Using the same Account fragmentation (A1 on Node 1, A2 on Node 2), classify:
BoT
SELECT Balance FROM A1 WHERE Acc# = 5000
UPDATE A2 SET Balance = Balance + 50 WHERE Acc# = 12000
EoT- Transaction class: Distributed transaction (not read-only, each statement hits one single server, and the transaction spans Node 1 and Node 2).
- Transparency level: Allocation transparency (the code names fragments
A1andA2explicitly, without specifying@Node1or@Node2).
Distributed ACID and query optimization (Slides 38–39)
Supporting transactions across autonomous nodes changes how each ACID property works (Slide 38):
- Atomicity: Requires distributed coordination via 2-Phase Commit (2PC).
- Consistency: Integrity constraints are currently enforced only locally at each node.
- Isolation: Requires Strict 2PL locally combined with 2-Phase Commit (so locks stay held until the global decision is safe).
- Durability: Extends local recovery procedures so node/network failures never break global atomicity.
(Supporting — Slide 39): Distributed query optimization is performed by the DBMS receiving the request. It splits the query into single-DBMS subqueries, chooses execution order both within and across nodes (where network transmission cost can dominate), optionally selects a replica, and coordinates execution and data exchange.
Two-Phase Commit (2PC) protocol (Slides 40–57)
The problem and roles (Slides 40–42)
All DBMS servers participating in a distributed transaction must execute the same final decision (commit or rollback), even when node failures, network failures (lost messages, mitigated via ACKs and timeouts), or network partitioning occur (Slide 40).
- Roles (Slide 42):
- One Coordinator — Transaction Manager (
TM): Coordinates the commit agreement. Any participant (including the client requesting execution) may act asTM. - Participants — Resource Managers (
RMs): The DBMS servers holding transaction data.
- One Coordinator — Transaction Manager (
- Wedding analogy (Slide 41): The
TMis like the priest coordinating the agreement, and theRMs are the couple saying “I do”.- Limit of the analogy: Real nodes crash and packets drop, so the
TMand everyRMmust persist decisions in separate private logs (Slides 43–44).
- Limit of the analogy: Real nodes crash and packets drop, so the
New 2PC log records (Slides 43–44)
- In the
TMlog (Slide 43):Prepare: records the identity (Node ID + Process ID) of all participating RMs.Global commit / Global abort: the final binding outcome for the transaction.Complete: written at the very end once all RMs acknowledge completion.
- In each
RMlog (Slide 44):Ready: indicates the RM is willing to commit. Critical consequences:- The RM cannot change this decision afterward.
- The node must already be in a reliable state (WAL and Commit Precedence enforced, resources locked).
- After writing
Ready, the RM loses its local autonomy for this transaction.
Protocol sequence and the uncertainty window (Slides 45–57)
RM (Participant) TM (Coordinator)
──────────────── ────────────────
[Log: Prepare]
◄────────────── 1. Prepare msg ──────────── (set timeout)
[Log: Ready]*
────────────── 2. Ready / Not ready ──────►
╔════╗ [Log: Global Commit/Abort]
║UN- ║ ◄───────────── 3. Global decision ──────── (set timeout)
║CER-║
║TAIN║
╚════╝
[Log: Commit/Abort]
[Update DB & unlock]
────────────── 4. ACK msg ────────────────►
[Log: Complete]Phase I (Voting / Prepare) (Slides 45–50):
- TM: Writes
Prepareto its log, sendsPrepare msgto all RMs, and sets a timeout. - RMs: Wait for
Prepare msg.- If in a reliable state → write
Readyin RM log and replyReady msg. - If not in a reliable state → reply
Not ready msg, terminate the protocol, and perform local rollback. - If crashed → sends no answer.
- If in a reliable state → write
- TM: Collects replies.
- If all RMs reply
Ready→ writesGlobal commitin TM log. - If one or more reply
Not readyor timeout expires → writesGlobal abortin TM log.
- If all RMs reply
Phase II (Execution / Decision) (Slides 51–55):
- TM: Sends the
Global decisionto all RMs and sets a timeout for RM answers. - RMs: Receive the
Global decision, writeCommitorAbortin the RM log, update the database (and release locks), and send anACK msgto the TM. - TM: Collects
ACKs.- When all
ACKs arrive → writesCompletein TM log. - If timeout expires with missing
ACKs → sets a new timeout and resends the global decision to the silent RMs until allACKs are received.
- When all
The uncertainty window (Slides 56–57)
For each RM, the uncertainty window begins right after it sends Ready msg and ends when it receives the Global decision. During this interval, the RM has surrendered autonomy and keeps its local resources locked—so if the TM crashes, those locks remain stuck until TM recovery. Keeping this window small is essential for availability.
Failure handling in 2PC (Slides 58–60)
1. Failure of a participant (RM) (Slide 58)
- The local Warm Restart procedure (see Warm Restart Problem Solving and Cold Restart) is extended with a third list: the
READYlist (alongsideUNDOandREDO). - Any transaction whose last log record is
Readydoes not know the TM’s decision, so it is placed inREADY(it must not be placed inUNDO, because the TM might have committed on other nodes!). - At restart, for every transaction in
READY, the RM sends a remote recovery request to the TM to learn theGlobal decisionand finish Phase II (meanwhile, if the TM was still waiting on the RM’sACK, the TM keeps timing out and resending the decision until the RM replies withACK).
2. Failure of the coordinator (TM) (Slide 59)
Messages that can be lost span Phase I (Prepare outgoing, Ready incoming) and Phase II (Global decision outgoing):
- Last TM log record is
Prepare(TM crashed in Phase I before deciding): writeGlobal abortin the TM log and send it to all participants. (Alternative: redo Phase I—not implemented in practice.) - Last TM log record is
Global decision(TM crashed in Phase II): repeat Phase II (resend the decision to all RMs and wait forACKs).
3. Network failures (Slide 60)
- Any network problem in Phase I (
PrepareorReadylost) → causes Global abort (via TM timeout). - Any network problem in Phase II (
Global decisionorACKlost) → causes repetition of Phase II until allACKs arrive.
Common confusions
- Putting a
Readytransaction intoUNDOafter an RM crash: Never unilaterally abort a transaction afterReadyis logged; the TM may have already writtenGlobal commitand told other RMs to commit. Use theREADYlist and ask the TM. - Confusing Distributed Transaction vs. Distributed Request: If a single SQL query references an unfragmented logical table
Accountthat spans multiple nodes, that single statement requires distributed optimization and fragmentation transparency → Distributed request. Only when each individual statement hits one server (while the transaction spans multiple servers) is it a Distributed transaction. - Forgetting Phase II recovery is repetition, not abort: Once
Global commitis logged by the TM, no timeout or network drop can turn it into an abort—Phase II simply retries until every RM acknowledges.
Retrieval questions with answers
1. An RM has already written Ready to its log and sent Ready to the TM, then crashes before receiving the global decision. Why can’t local Warm Restart simply put that transaction in UNDO?
Because Ready means the RM promised to follow the TM’s decision and gave up autonomy. The TM may have received Ready from all other RMs and logged Global commit. Unilaterally undoing locally would violate global atomicity. Instead, the RM puts the transaction in its READY list and sends a remote recovery request to the TM (while the TM also retries Phase II until it gets the RM’s ACK).
2. Why does the uncertainty window create a concurrency bottleneck if the TM fails?
During the uncertainty window (between sending Ready and receiving Global decision), the RM holds locks on all local resources touched by the transaction under Strict 2PL. If the TM crashes, the RM cannot release those locks on its own, blocking other transactions until the TM recovers.
3. Classify BoT; SELECT * FROM Account WHERE Balance > 1000; EoT if Account is horizontally fragmented into A1 (Node 1) and A2 (Node 2).
It is a Distributed request, because a single SQL statement accesses data distributed across multiple servers and relies on fragmentation transparency (referencing Account rather than A1/A2), requiring distributed query optimization.