DISTRIBUTED SYSTEM
CHAPTER 10 : CASE STUDY
LAB WORK SOLUTION- DISTRIBUTED SYSTEM
DISTRIBUTED SYSTEM -BCA -ALL SLIDES
MCQ- DISTRIBUTED SYSTEM

DISTRIBUTED COMMIT 

A distributed commit in a distributed system is a protocol that ensures all participating nodes in a distributed transaction either commit the transaction (making permanent changes) or abort it (undoing any partial changes). This is crucial to maintaining consistency across the system, even in the presence of failures. Two commonly used distributed commit protocols are the Two-Phase Commit (2PC) and Three-Phase Commit (3PC) protocols.

Two-Phase Commit (2PC)

The Two-Phase Commit protocol is a classic method for achieving atomicity in distributed transactions. It consists of two phases: the prepare phase and the commit phase.

Phases of 2PC

  1. Prepare Phase:

    • The coordinator node sends a prepare message to all participating nodes (participants).
    • Each participant writes the transaction to a temporary storage (log) and replies with either a vote to commit or a vote to abort.
    • If all participants vote to commit, the coordinator proceeds to the commit phase. If any participant votes to abort, the coordinator aborts the transaction.
  2. Commit Phase:

    • If all participants voted to commit, the coordinator sends a commit message to all participants.
    • Each participant then commits the transaction and sends an acknowledgment to the coordinator.
    • If any participant fails to commit, the coordinator sends an abort message to all participants, ensuring the transaction is rolled back.

Advantages and Disadvantages of 2PC

  • Advantages:

    • Simple and widely used.
    • Guarantees atomicity and consistency across distributed systems.
  • Disadvantages:

    • Blocking: If the coordinator crashes after sending a prepare message but before sending a commit/abort message, participants are left in an uncertain state.
    • Communication overhead: Requires multiple rounds of message exchanges.

Three-Phase Commit (3PC)

The Three-Phase Commit protocol is an extension of 2PC that introduces an additional phase to avoid the blocking problem inherent in 2PC. This protocol ensures that participants never have to wait indefinitely in uncertain states.

Phases of 3PC

  1. Prepare Phase (same as 2PC):

    • The coordinator sends a prepare message to all participants.
    • Participants vote to commit or abort.
  2. Pre-Commit Phase:

    • If all participants vote to commit, the coordinator sends a pre-commit message (also called a prepare-to-commit message) to all participants.
    • Participants acknowledge receipt of the pre-commit message, which means they are ready to commit but haven’t done so yet.
    • If any participant fails to acknowledge, the coordinator aborts the transaction.
  3. Commit Phase:

    • Upon receiving all acknowledgments for the pre-commit message, the coordinator sends a commit message.
    • Participants then commit the transaction and send an acknowledgment.
    • If any participant fails to commit, the coordinator sends an abort message.