Beta Phase: Square45 is currently in beta testing. Expect some features or content to be incomplete or missing.
45

Two-Phase Commit (2PC)

A protocol guaranteeing atomicity across multiple resources, involving a prepare and commit phase.
📜

The statement of the theorem

Let C={Coordinator,Participant1,,Participantk}\mathcal{C} = \{\text{Coordinator}, \text{Participant}_1, \dots, \text{Participant}_k\} be the set of nodes. The Two-Phase Commit protocol proceeds through two phases:\n\n**Phase 1: Prepare (Voting)**\n1. CoordinatorPREPAREParticipanti\text{Coordinator} \xrightarrow{\text{PREPARE}} \text{Participant}_i. \n2. Participanti\text{Participant}_i writes all necessary changes to stable storage (undo/redo logs) and replies VOTEYES\text{VOTE}_{YES} if successful, or VOTENO\text{VOTE}_{NO} otherwise.\n\n**Phase 2: Commit/Abort (Decision)**\n1. If Coordinator\text{Coordinator} receives VOTEYES\text{VOTE}_{YES} from all Participanti\text{Participant}_i: CoordinatorCOMMITParticipanti\text{Coordinator} \xrightarrow{\text{COMMIT}} \text{Participant}_i. Participanti\text{Participant}_i makes changes permanent.\n2. Otherwise: CoordinatorABORTParticipanti\text{Coordinator} \xrightarrow{\text{ABORT}} \text{Participant}_i. Participanti\text{Participant}_i rolls back changes.
Source: Wikipedia