Discussion 11
Distributed Transactions
Announcements
Vitamin 11 (Distributed Transactions) due 11/25
Final Exam date and time is confirmed: Wed 12/18 11.30am-2.30pm. 1 alternate exam will be available right after the main time. More details on weekly ed post.
Section plans for next week: <insert section-specific announcements>
TA specific feedback response <3
Agenda
Distributed Consensus
Distributed Computing
Distributed Computing
Two-Phase Commit (2PC)
Two-Phase Commit (2PC)
Two-Phase Commit (2PC)
Two-Phase Commit (2PC) [Abort Example]
Phase 1: Coordinator asks Participants to vote (YES, commit the transaction, or NO, abort the transaction), and collects the votes
Coord
P
P
P
PREPARE
PREPARE
PREPARE
Two-Phase Commit (2PC) [Abort Example]
Phase 1: Coordinator asks Participants to vote (YES, commit the transaction, or NO, abort the transaction), and collects the votes
Coord
P
P
P
YES
YES
NO
Not a unanimous agreement!
Two-Phase Commit (2PC) [Abort Example]
Phase 2: Coordinator tells Participants the result of the vote
Coord
P
P
P
ABORT
ABORT
ABORT
Two-Phase Commit (2PC) [Abort Example]
Phase 2: Coordinator tells Participants the result of the vote
Coord
P
P
P
ACK
ACK
ACK
Two-Phase Commit (2PC) [Commit Example]
Phase 1: Coordinator asks Participants to vote (YES, commit the transaction, or NO, abort the transaction), and collects the votes
Coord
P
P
P
PREPARE
PREPARE
PREPARE
Two-Phase Commit (2PC) [Commit Example]
Phase 1: Coordinator asks Participants to vote (YES, commit the transaction, or NO, abort the transaction), and collects the votes
Coord
P
P
P
YES
YES
YES
A unanimous agreement!
Two-Phase Commit (2PC) [Commit Example]
Phase 2: Coordinator tells Participants the result of the vote
Coord
P
P
P
COMMIT
COMMIT
COMMIT
Two-Phase Commit (2PC) [Commit Example]
Phase 2: Coordinator tells Participants the result of the vote
Coord
P
P
P
ACK
ACK
ACK
Two-Phase Commit (2PC): Logging
Two-Phase Commit (2PC): Logging
Two-Phase Commit (2PC) [Abort Example]
Phase 1:
Coord
P
P
P
PREPARE
PREPARE
PREPARE
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Abort Example]
Phase 1:
Coord
P
P
P
PREPARE
PREPARE
PREPARE
PREPARE
PREPARE
ABORT
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Abort Example]
Phase 1:
Coord
P
P
P
YES
YES
NO
PREPARE
PREPARE
ABORT
Not a unanimous agreement!
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Abort Example]
Phase 1:
Coord
P
P
P
YES
YES
NO
PREPARE
PREPARE
ABORT
ABORT
Not a unanimous agreement!
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Abort Example]
Phase 2:
Coord
P
P
P
ABORT
ABORT
ABORT
PREPARE
PREPARE
ABORT
ABORT
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Abort Example]
Phase 2:
Coord
P
P
P
ABORT
ABORT
ABORT
PREPARE
ABORT
PREPARE
ABORT
ABORT
ABORT
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Abort Example]
Phase 2:
Coord
P
P
P
ACK
ACK
ACK
PREPARE
ABORT
PREPARE
ABORT
ABORT
ABORT
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Abort Example]
Phase 2:
Coord
P
P
P
ACK
ACK
ACK
PREPARE
ABORT
PREPARE
ABORT
ABORT
ABORT
END
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Commit Example]
Phase 1:
Coord
P
P
P
PREPARE
PREPARE
PREPARE
Two-Phase Commit (2PC) [Commit Example]
Phase 1:
Coord
P
P
P
PREPARE
PREPARE
PREPARE
PREPARE
PREPARE
PREPARE
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Commit Example]
Phase 1:
Coord
P
P
P
YES
YES
YES
PREPARE
PREPARE
PREPARE
A unanimous agreement!
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Commit Example]
Phase 1:
Coord
P
P
P
YES
YES
YES
PREPARE
PREPARE
PREPARE
COMMIT
A unanimous agreement!
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Commit Example]
Phase 2:
Coord
P
P
P
COMMIT
COMMIT
COMMIT
PREPARE
PREPARE
PREPARE
COMMIT
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Commit Example]
Phase 2:
Coord
P
P
P
COMMIT
COMMIT
COMMIT
PREPARE
COMMIT
PREPARE
COMMIT
PREPARE
COMMIT
COMMIT
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Commit Example]
Phase 2:
Coord
P
P
P
ACK
ACK
ACK
PREPARE
COMMIT
PREPARE
COMMIT
PREPARE
COMMIT
COMMIT
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC) [Commit Example]
Phase 2:
Coord
P
P
P
ACK
ACK
ACK
PREPARE
COMMIT
PREPARE
COMMIT
PREPARE
COMMIT
COMMIT
END
Bolded: log record immediately flushed to disk
Two-Phase Commit (2PC): Logging
Coordinator
commit* or abort*
(with participant IDs)
end
Participant
prepare* or abort*
(with coordinator ID)
commit* or abort*
* indicates that the record must be flushed to disk immediately
PREPARE
VOTE YES/NO
COMMIT/ABORT
ACK
We have one coordinator and three participants. It takes 30ms for a coordinator to send messages to all participants; 5, 10, and 15ms for participant 1, 2, and 3 to send a message to the coordinator respectively; and 10ms for each machine to flush a record.
Assume for the same message, each participant receives it from the coordinator at the same time. Under proper 2PC and logging protocols, how long does the whole 2PC process take (from start until all log records on the coordinator for the transaction have been flushed) for a successful commit in the best case?
Worksheet #1
We have one coordinator and three participants. It takes 30ms for a coordinator to send messages to all participants; 5, 10, and 15ms for participant 1, 2, and 3 to send a message to the coordinator respectively; and 10ms for each machine to flush a record.
Assume for the same message, each participant receives it from the coordinator at the same time. Under proper 2PC and logging protocols, how long does the whole 2PC process take (from start until all log records on the coordinator for the transaction have been flushed) for a successful commit in the best case?
Phase 1: 30ms (PREPARE) + 10ms (flush particip. prepare record) + 15ms (max time for VOTE YES messages) + 10ms (flush coord. commit record)
Phase 2: 30ms (COMMIT) + 10ms (flush particip. commit record) + 15ms (max time for ACK messages) + 10ms (flush coord. end record)
Total: 130ms (note: can take longer, since END may be flushed whenever)
Worksheet #1
Two-Phase Commit (2PC): Handling Failures
Two-Phase Commit (2PC): Handling Failures
We assume that all machines eventually recover
Coord
P
P
P
YES
YES
????
PREPARE
PREPARE
????
ABORT
Two-Phase Commit (2PC): Handling Failures
We assume that all machines eventually recover
Coord
P
P
P
ACK
ACK
????
PREPARE
COMMIT
PREPARE
COMMIT
PREPARE
????
COMMIT
Time to perform recovery!
Two-Phase Commit (2PC): Handling Failures
We assume that all machines eventually recover
Coord
P
P
P
PREPARE
PREPARE
????
PREPARE
PREPARE
ABORT
Two-Phase Commit (2PC): Handling Failures
We assume that all machines eventually recover
Coord
P
P
P
YES
YES
NO
PREPARE
PREPARE
ABORT
Two-Phase Commit (2PC): Handling Failures
We assume that all machines eventually recover
Coord
P
P
P
ABORT
ABORT
????
PREPARE
ABORT
PREPARE
????
ABORT
Time to perform recovery!
Two-Phase Commit (2PC): Handling Failures
We assume that all machines eventually recover
Coord
P
P
P
ABORT
ABORT
????
PREPARE
ABORT
PREPARE
????
ABORT
Participant 3 only has access to its own status and information!
Two-Phase Commit (2PC): Recovery
Describe what happens in the 2PC protocol if a participant receives a PREPARE message, replies with a YES vote, crashes, and restarts (assume all other participants voted yes and did not crash).
Worksheet #2
Describe what happens in the 2PC protocol if a participant receives a PREPARE message, replies with a YES vote, crashes, and restarts (assume all other participants voted yes and did not crash).
The participant will send a message to the coordinator asking about the state of the transaction (committing), and then write (and flush) a COMMIT record and send an ACK message to the coordinator.
Worksheet #2
Two-Phase Commit (2PC): Optimization
Two-Phase Commit (2PC): Optimization
2PC Presumed Abort [Abort Example]
Phase 1:
Coord
P
P
P
PREPARE
PREPARE
PREPARE
Bolded: log record flushed to disk
2PC Presumed Abort [Abort Example]
Phase 1:
Coord
P
P
P
PREPARE
PREPARE
PREPARE
PREPARE
PREPARE
ABORT
Bolded: log record flushed to disk
2PC Presumed Abort [Abort Example]
Phase 1:
Coord
P
P
P
YES
YES
NO
PREPARE
PREPARE
ABORT
Not a unanimous agreement!
Bolded: log record flushed to disk
2PC Presumed Abort [Abort Example]
Phase 1:
Coord
P
P
P
YES
YES
NO
PREPARE
PREPARE
ABORT
ABORT
Not a unanimous agreement!
Bolded: log record flushed to disk
2PC Presumed Abort [Abort Example]
Phase 2:
Coord
P
P
P
ABORT
ABORT
ABORT
PREPARE
PREPARE
ABORT
ABORT
Bolded: log record flushed to disk
2PC Presumed Abort [Abort Example]
Phase 2:
Coord
P
P
P
ABORT
ABORT
ABORT
PREPARE
ABORT
PREPARE
ABORT
ABORT
ABORT
Bolded: log record flushed to disk
Two-Phase Commit (2PC): Optimization
Coordinator
commit*
(with participant IDs)
or abort
end
(if commit)
Participant
prepare* or abort
(with coordinator ID)
commit* or abort
* indicates that the record must be flushed to disk immediately
PREPARE
VOTE YES/NO
COMMIT/ABORT
ACK (if commit)
Two-Phase Commit (2PC): Blocking
Suppose that the coordinator sends PREPARE message to Participants 1 and 2. Participant 1 sends a "VOTE YES" message, and Participant 2 sends a "VOTE NO" message back to the coordinator.
Worksheet #3
Suppose that the coordinator sends PREPARE message to Participants 1 and 2. Participant 1 sends a "VOTE YES" message, and Participant 2 sends a "VOTE NO" message back to the coordinator.
Worksheet #3
Upon recovery, Participant 1 will find a PREPARE message for this transaction in their log. In both cases, Participant 1 sends an inquiry to the coordinator for the status of this transaction and sees that the transaction aborted. Participant 1 will abort the transaction locally.
Suppose that the coordinator sends PREPARE message to Participants 1 and 2. Participant 1 sends a "VOTE YES" message, and Participant 2 sends a "VOTE NO" message back to the coordinator.
Worksheet #3
Suppose that the coordinator sends PREPARE message to Participants 1 and 2. Participant 1 sends a "VOTE YES" message, and Participant 2 sends a "VOTE NO" message back to the coordinator.
Worksheet #3
Without presumed abort: Upon recovery, Participant 2 sees an abort record for this transaction in their log and sends the "VOTE NO" messages back to the coordinator.
With presumed abort: Upon recovery, Participant 2 sees no log records for this transaction, and they do not need to send any messages to the coordinator.
Suppose we are running 2PC with presumed abort. The coordinator sent PREPARE messages to the participants and crashed, before receiving any votes.
Worksheet #4
Suppose we are running 2PC with presumed abort. The coordinator sent PREPARE messages to the participants and crashed, before receiving any votes.
Will see transaction running at time of crash, no commit log record, and abort locally (presumed abort - no ABORT message is sent across the network).
An ABORT record is written to log (no log flush required) and CLRs are emitted as needed (from recovery).
Worksheet #4
Suppose we are running 2PC with presumed abort. The coordinator sent PREPARE messages to the participants and crashed, before receiving any votes.
Worksheet #4
Suppose we are running 2PC with presumed abort. The coordinator sent PREPARE messages to the participants and crashed, before receiving any votes.
The transaction aborts the local effects of the transaction without caring that the coordinator crashed.
Worksheet #4
Suppose we are running 2PC with presumed abort. The coordinator sent PREPARE messages to the participants and crashed, before receiving any votes.
Worksheet #4
Suppose we are running 2PC with presumed abort. The coordinator sent PREPARE messages to the participants and crashed, before receiving any votes.
The transaction cannot make any unilateral decisions. After the coordinator has recovered (as detected via timeout or some other mechanism), the participant will ask the coordinator about the state of the transaction (aborted). The recovery process will abort the transaction locally (not sending an ABORT message) by undoing its actions, if any, using the UNDO log records, and writing an abort record.
Worksheet #4
Worksheet #4
For part (a) - What sequence of operations does the coordinator take after it recovers?
No change because the coordinator likewise sees no log records for the transaction. The recovery process will abort the transaction locally, and since there is no information about the participant IDs in the log, the coordinator cannot send abort records to the participants.
Worksheet #4
For part (b) - What sequence of operations does a participant who received the message and replied NO before the coordinator crashed take?
No change because with presumed abort, even if the participant itself crashes after sending the NO vote, the participant will proceed with abort since that is the presumption given no log records.
Worksheet #4
For part (c) - What sequence of operations does a participant who received the message and replied YES before the coordinator crashed take?
No change because with presumed abort, when the coordinator comes back online and sees no information about the transaction in its log, the transaction is unilaterally aborted. This change is communicated when participants who voted YES ping the coordinator to find out how the transaction should be resolved, and the coordinator will respond with an ABORT message.
Worksheet #4
Attendance Link