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):

ClassSQL AllowedServers per SQL StatementServers per TransactionKey Requirement / Property
1. Remote request (Slide 32)Read-only (SELECT only)1 remote server1 remote serverSimplest remote access
2. Remote transaction (Slide 32)Any SQL command1 remote server1 remote serverLocal ACID only
3. Distributed transaction (Slide 33)Any SQL command1 server per statementMultiple serversRequires global atomicity via 2-Phase Commit (2PC)
4. Distributed request (Slide 33)Any SQL commandMultiple servers in a single statementMultiple serversRequires 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 — because Account is not explicitly partitioned in the SQL, the DBMS must map the query onto A1 and A2 using fragmentation transparency.
  • Written explicitly against A1 and A2: Distributed transaction — each SQL statement addresses one single server (A1 on Node 1, A2 on Node 2), and the transaction as a whole spans two servers.
  • If both updates target only A1 (e.g., Acc# = 3000 and Acc# = 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 A1 and A2 explicitly, without specifying @Node1 or @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 as TM.
    • Participants — Resource Managers (RMs): The DBMS servers holding transaction data.
  • Wedding analogy (Slide 41): The TM is like the priest coordinating the agreement, and the RMs are the couple saying “I do”.
    • Limit of the analogy: Real nodes crash and packets drop, so the TM and every RM must persist decisions in separate private logs (Slides 43–44).

New 2PC log records (Slides 43–44)

  • In the TM log (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 RM log (Slide 44):
    • Ready: indicates the RM is willing to commit. Critical consequences:
      1. The RM cannot change this decision afterward.
      2. The node must already be in a reliable state (WAL and Commit Precedence enforced, resources locked).
      3. 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):

  1. TM: Writes Prepare to its log, sends Prepare msg to all RMs, and sets a timeout.
  2. RMs: Wait for Prepare msg.
    • If in a reliable state → write Ready in RM log and reply Ready msg.
    • If not in a reliable state → reply Not ready msg, terminate the protocol, and perform local rollback.
    • If crashed → sends no answer.
  3. TM: Collects replies.
    • If all RMs reply Ready → writes Global commit in TM log.
    • If one or more reply Not ready or timeout expires → writes Global abort in TM log.

Phase II (Execution / Decision) (Slides 51–55):

  1. TM: Sends the Global decision to all RMs and sets a timeout for RM answers.
  2. RMs: Receive the Global decision, write Commit or Abort in the RM log, update the database (and release locks), and send an ACK msg to the TM.
  3. TM: Collects ACKs.
    • When all ACKs arrive → writes Complete in TM log.
    • If timeout expires with missing ACKs → sets a new timeout and resends the global decision to the silent RMs until all ACKs are received.

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 READY list (alongside UNDO and REDO).
  • Any transaction whose last log record is Ready does not know the TM’s decision, so it is placed in READY (it must not be placed in UNDO, 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 the Global decision and finish Phase II (meanwhile, if the TM was still waiting on the RM’s ACK, the TM keeps timing out and resending the decision until the RM replies with ACK).

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): write Global abort in 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 for ACKs).

3. Network failures (Slide 60)

  • Any network problem in Phase I (Prepare or Ready lost) → causes Global abort (via TM timeout).
  • Any network problem in Phase II (Global decision or ACK lost) → causes repetition of Phase II until all ACKs arrive.

Common confusions

  • Putting a Ready transaction into UNDO after an RM crash: Never unilaterally abort a transaction after Ready is logged; the TM may have already written Global commit and told other RMs to commit. Use the READY list and ask the TM.
  • Confusing Distributed Transaction vs. Distributed Request: If a single SQL query references an unfragmented logical table Account that 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 commit is 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.