Demo Video
This video demonstrates the 2 Phase Commit Protocol.
Project Overview: Two-Phase Commit Protocol in Rust
This project implements a Two-Phase Commit (2PC) simulation using Rust. The implementation features three classes of interacting agents: client threads that submit requests, a coordinator thread that handles the 2PC protocol, and participant threads that execute operations. These threads communicate via Rust's crossbeam channels, with participants and coordinator writing to separate log files to document their actions.
Implementation Challenges:
- Operation Failures: Handling arbitrary success/failure of operations at participants (controlled by the -s parameter).
- Communication Failures: Handling unreliable message transmission between participants and coordinator (controlled by the -S parameter).
- Extra Credit: Support for coordinator failure and recovery.
Architecture & Component Interaction
The system consists of three primary components that interact through message passing:
System Components:
- Client Threads: Submit requests to the coordinator and wait for results.
- Coordinator Thread: Manages the 2PC protocol, interacting with both clients and participants.
- Participant Threads: Execute operations and participate in the voting process of 2PC.
Control Flow:
Each component operates as a state machine with distinct states:
- Coordinator States: Quiescent, CollectingVotes, Committing, and Aborting.
- Participant States: Quiescent, Voting, Committed, and Aborted.
- Client Protocol: Loops through requests, sending operations and receiving results.
Implementation Details
Communication Mechanism:
- Crossbeam Channels: Used for thread communication, providing sender and receiver ends for message passing.
- Arc Pattern: Implemented shared data between threads using Rust's Arc (Atomic Reference Counting).
- Timeout Mechanisms: Created robust timeout systems to handle slow or failed participants.
Failure Handling:
- Operation Failures: Simulated using probability-based failure of local operations at participants.
- Message Failures: Implemented unreliable message sending to simulate network issues.
- Coordinator Failures: Added support for coordinator crashes and recovery through logging.
Results & Verification
Verification Output:
omagr@parcheesi:~/concurrency/lab4$ ./target/debug/concurrency-2pc -s 0.95 -c 4 -p 4 -r 4 -m check -v 0 participant_0 OK: C:13 == 13(C-global), A:3 <= 3(A-global) participant_1 OK: C:13 == 13(C-global), A:3 <= 3(A-global) participant_3 OK: C:13 == 13(C-global), A:3 <= 3(A-global) participant_2 OK: C:13 == 13(C-global), A:3 <= 3(A-global)
Coordinator Recovery (Extra Credit)
The extra credit implementation supports coordinator failure through:
- Log-Based Recovery: Processing logs to rebuild coordinator state after crashes.
- Transaction Handling: Gracefully handling incomplete transactions by aborting them.
- Command Examples:
Simulate coordinator crash ./target/debug/concurrency-2pc -F 0.1 -c 3 -p 3 -r 3 -m run -v5 Run recovery ./target/debug/concurrency-2pc -R -c 3 -p 3 -r 3 -m run -v5
Key Learnings
- Rust Language Features: Gained experience with Rust's ownership model, Arc pattern, mutability control, and thread handling.
- Distributed Systems: Deeper understanding of Two-Phase Commit protocol mechanics and failure handling strategies.
- Robust Design: Created effective timeout mechanisms and recovery procedures for distributed systems.
This project successfully implemented a robust Two-Phase Commit protocol in Rust, handling various failure scenarios while leveraging Rust's unique features for concurrency and safety.