Give full details of the centralized two-phase commit protocol in a distributed environment. Outline the algorithms for both coordinator and participants.

Algorithm (a) 2PC coordinator algorithm
Algorithm (b) 2PC participants algorithm
Algorithm Cooperative termination protocol for 2PC
Algorithm 2PC participant restart following failure


```
Algorithm (a) 2PC coordinator algorithm
begin

STEP C1 VOTE INSTRUCTION
write ‘begin global commit’ message to log
send ‘vote’ message to all participants
do until votes received from all participants
wait
on timeout go to STEP C2b
enddo
STEP C2a GLOBAL COMMIT
if all votes are ‘commit’
then begin
write ‘global commit’ record to log
send ‘global commit’ to all participants
end
STEP C2b GLOBAL ABORT
at least one participant has voted abort or coordinator has timed out
else begin
write ‘global abort’ record to log
send ‘global abort’ to all participants
end
endif
STEP C3 TERMINATION
do until acknowledgement received from all participants
wait
enddo
write ‘end global transaction record’ to log
finish
end

Algorithm (b) 2PC participants algorithm
begin

STEP P0 WAIT FOR VOTE INSTRUCTION
do until ‘vote’ instruction received from coordinator
wait
enddo
STEP P1 VOTE
if vote = ‘commit’ then send ‘commit’ to coordinator
else send ‘abort’ and go to STEP P2b
do until global vote received from coordinator
wait
enddo
STEP P2a COMMIT
if global vote = ‘commit’
then perform local commit processing

STEP P2b ABORT
at least one participant has voted abort
else perform local abort processing
end-if
STEP P3 TERMINATION
send acknowledgement to coordinator
finish
end

Algorithm Cooperative termination protocol for 2PC
begin
do while P0 is blocked
STEP 1 HELP REQUESTED FROM Pi
P0 sends a message to Pi asking for help to unblock
if Pi knows the decision (Pi received global commit/abort or Pi unilaterally aborted)
then begin
Pi conveys decision to P0
P0 unblocks and finishes
end
endif
STEP 2 HAS Pi VOTED?
if Pi has not voted
then begin
Pi unilaterally aborts
P0 told to abort
P0 unblocks and finishes
end
endif
STEP 3 Pi CANNOT HELP; TRY Pi+1

next Pi
enddo
end
Algorithm 2PC participant restart following failure
begin
do while Pr is blocked
STEP 1 ASCERTAIN STATUS OF Pr IMMEDIATELY PRIOR TO FAILURE if Pr voted

‘commit’
then go to STEP 2
else begin
Pr voted ‘abort’ prior to failure or had not voted
Pr aborts unilaterally
Pr recovers independently and finishes
end
endif
STEP 2 IS GLOBAL DECISION KNOWN?
if Pr knows global decision
then begin
Pr takes action in accordance with global decision
Pr recovers independently and finishes
end
endif
STEP 3 Pr CANNOT RECOVER INDEPENDENTLY AND ASKS FOR HELP
Pr asks for help from participant Pr+1 using the cooperative termination protocol
enddo
end
```

Computer Science & Information Technology

You might also like to view...

Class variables begin with the ____ character.

A. @ B. @@ C. $ D. _

Computer Science & Information Technology

A pointer variable can be passed as a parameter to a function either by value or by  ____.

A. retention B. reference C. approximation D. referral

Computer Science & Information Technology

The advantage to using colored clays is that they ____________.

a. are easy to work with b. have color only on the surface c. fire at lower temperatures d. are uniform throughout the piece

Computer Science & Information Technology

Which of the following statements is true regarding the differences between a 32-bit and 64-bit OS?

A. A 32-bit version of the OS will not run on 64-bit hardware, but a 64-bit OS will run on 32-bit hardware. B. A 32-bit version of the OS requires twice the number of CPU clock cycles to write the same amount of data as a 64-bit OS. C. A 64-bit version of the OS will address memory in eight octets. D. A 64-bit version of the OS will write data to disk in block sizes of eight octets

Computer Science & Information Technology