Docsity

Two Phase Commit-Transaction Process For ECommerce-Lecture Slides, Slides of Transaction Processing for E Commerce

Partial preview of the text

Download Two Phase Commit-Transaction Process For ECommerce-Lecture Slides and more Slides Transaction Processing for E Commerce in PDF only on Docsity!

Distributed Systems

  • Failures
    • Links and nodes
    • Models
  • Algorithms
    • Correctness
    • Termination

A B

docsity.com

Introduction

  • Goal - ensure the atomicity of a transaction that

accesses multiple resource managers.

  • (Recall, resource abstracts data, messages, and other

items that are shared by transactions.)

  • Why is this hard?
    • After a transaction commits at RMa,what if resource manager RMb fails?
    • When RMb recovers, what to do if other resource managers are down?
    • What if a transaction thinks a resource manager failed and therefore aborted, when it actually is still running? docsity.com

Problem Statement

  • Transaction T accessed data at resource managers

R 1 , … Rn.

  • The goal is to either
    • Commit T at all of R 1 , … Rn, or
    • Abort T at all of R 1 , … Rn
    • Even if resource managers, nodes and communications links fail during the commit or abort activity.
  • That is, never commit at Ri but abort at Rk.

docsity.com

Outline

1. Introduction

2. The Two-Phase Commit (2PC) Protocol

3. 2PC Failure Handling

4. 2PC Optimizations

5. Process Structuring

6. Three Phase Commit

docsity.com

The Protocol

1 (Begin Phase 1) The coordinator sends a

Request-to-Prepare message to each participant.

2 The coordinator waits for all participants to vote.

3 Each participant

 Votes Prepared if it’s ready to commit  May vote No for any reason  May delay voting indefinitely.

4 (Begin Phase 2) If coordinator receives Prepared

from all participants, it decides to commit.

(The transaction is now committed.)

Otherwise, it decides to abort. docsity.com

The Protocol (cont’d)

5 The coordinator sends its decision to all

participants (i.e., Commit or Abort ).

6 Participants acknowledge receipt of Commit or

Abort by replying Done.

docsity.com

Case 2: Abort

Coordinator

Request-to-Prepare

No

Abort

Done

Participant

docsity.com

Performance

  • In the absence of failures, 2PC requires 3

rounds of messages before the decision is made

known to RM’s.

  • Request-to-prepare
  • Votes ( Prepared, No)
  • Decision (Commit, Abort).
  • Done messages are just for bookkeeping.
  • They don’t affect response time.
  • They can be batched. docsity.com

Uncertainty (cont’d)

  • The coordinator is never uncertain.
  • If a participant fails or is disconnected from

the coordinator while it’s uncertain,

at recovery it must find out the decision.

docsity.com

The Bad News Theorems

  • Uncertainty periods are unavoidable.
  • Blocking - a participant must await a repair before

continuing. Blocking is bad.

  • Theorem 1 - For every possible commit protocol

(not just 2PC), a communications failure can cause

a participant to become blocked.

  • Independent recovery - a recovered participant can

decide to commit or abort without communicating

with other nodes.

  • Theorem 2 - No commit protocol can guarantee

independent recovery of failed participants. docsity.com

2PC Failure Handling (cont’d)

  • A participant that voted Prepared times out waiting

for the coordinator’s decision

  • It’s blocked.
  • Use a termination protocol to decide what to do.
  • Naïve termination protocol - wait till the coordinator recovers.
  • The coordinator times out waiting for Done.
  • It must resolicit them, so it can forget the decision.

docsity.com

Forgetting Transactions

  • After a participant receives the decision, it may

forget the transaction.

  • After the coordinator receives Done from all

participants, it may forget the transaction.

  • A participant must not reply Done until its commit

or abort log record is stable.

  • Else, if it fails, then recovers, then asks the coordinator for a decision, the coordinator may not know.

docsity.com

Coordinator Recovery

  • If the coordinator fails and later recovers, it must know the decision. It must therefore log: - The fact that it began T’s 2PC protocol, including the list of participants, and - Commit or Abort, before sending Commit or Abort to any participant (so it knows whether to commit or abort after it recovers).
  • If the coordinator fails and recovers, it resends the decision to participants from which it doesn’t remember getting Done - If the participant forgot the transaction, it replies Done - The coordinator should therefore log Done after it has received them all. docsity.com

Participant Recovery

  • If a participant P fails and later recovers, it first performs centralized recovery (Restart).
  • For each distributed transaction T that was active at the time of failure: - If P is not uncertain about T, then it unilaterally aborts T - If P is uncertain, it runs the termination protocol (which may leave P blocked).
  • To ensure it can tell whether it’s uncertain, P must log its vote before sending it to the coordinator.
  • To avoid becoming totally blocked due to one blocked transaction, P should reacquire T’s locks during Restart and allow Restart to finish before T is resolved. docsity.com