Review Questions
20.1 In a distributed environment, locking-based algorithms can be classified as centralized, primary
copy, or distributed. Compare and contrast these algorithms.
See Section 20.2.3.
20.2 One of the most well-known methods for distributed deadlock detection was developed by
Obermarck. Explain how Obermarck’s method works and how deadlock is detected and resolved.
See Section 20.3 under Distributed Deadlock Detection.
20.3 Outline two alternative two-phase commit topologies to the centralized topology.
Alternative topologies: linear and distributed 2PC. See end of Section 20.4.3.
20.4 Explain the term non-blocking protocol and explain why two-phase commit protocol is not a non-
blocking protocol.
A non-blocking protocol should cater for both site and communication failures to ensure that the failure of one site will not affect processing at another site. In other words, operational sites should not be left blocked.
In the event that a participant has voted COMMIT but has not received global decision and is unable to communicate with any other site that knows the decision, that site is blocked. Although 2PC has a cooperative termination protocol that reduces the likelihood of blocking, blocking is still possible and the blocked process will just have to keep on trying to unblock as failures are repaired.
20.5 Discuss how the three-phase commit protocol is a non-blocking protocol in the absence of
complete site failure.
See Section 20.4.4.
The basic idea of 3PC is to remove the uncertainty period for participants who have voted commit and are waiting for the global abort or global commit from the coordinator. 3PC introduces a third phase, called pre-commit, between voting and global decision.
20.6 Compare and contrast the different ownership models for replication. Give examples to
illustrate your answer.
The main types of ownership are master/slave, workflow, and update-anywhere, sometimes referred to as peer-to-peer or symmetric replication. See Section 20.6.1.
20.7 Compare and contrast the database mechanisms for replication.
Discuss table snapshots versus database triggers - see Section 20.6.1 under both these headings. Exercises
20.8 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 (a) 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
68 wait
on timeout go to STEP C2b end-do
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
end-if
STEP C3 TERMINATION
do until acknowledgement received from all participants wait
end-do
write 'end global transaction record' to log finish
end
Algorithm (b) 2PC participants algorithm (b) begin
STEP P0 WAIT FOR VOTE INSTRUCTION
do until 'vote' instruction received from coordinator wait
end-do
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
end-do
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
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 un-block
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
end-if
STEP 2 HAS Pi VOTED? if Pi has not voted then begin
Pi unilaterally aborts P0 told to abort
P0 unblocks and finishes end
end-if
STEP 3 Pi CANNOT HELP; TRY Pi+1 next Pi
end-do 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
end-if
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 end-if
STEP 3 Pr CANNOT RECOVER INDEPENDENTLY AND ASKS FOR HELP Pr asks for help from participant Pr+1 using the cooperative termination protocol end-do
70
20.9 Give full details of the three-phase commit protocol in a distributed environment. Outline the
algorithms for both coordinator and participants.
Algorithm (a) 3PC coordinator algorithm (a) 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 end-do
STEP C2a PRE-COMMIT if all votes are 'commit' then begin
write 'pre-commit' message to log
send 'pre-commit' message 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 go to STEP 4
end end-if
STEP C3 GLOBAL COMMIT
do until all (pre-commit) acknowledgements received wait
end-do
write 'global commit' record to log send 'global commit' to all participants end
STEP C4 TERMINATION
do until acknowledgement received from all participants wait
end-do
write 'end global transaction record' to log finish
end
Algorithm (b) 3PC participants algorithm (b) begin
STEP P0 WAIT FOR VOTE INSTRUCTION
do until 'vote' instruction received from coordinator wait
end-do
STEP P1 VOTE
if participant is prepared to commit then send 'commit' message to coordinator
else send 'abort' message to coordinator and go to STEP P2b do until global vote received from coordinator
wait end-do
STEP P2a PRE-COMMIT
if global instruction = 'pre-commit'
then go to STEP P3 (and wait for global commit) end-if
STEP P2b ABORT
at least one participant has voted abort
perform local abort processing go to STEP P4
STEP P3 COMMIT
do until 'global commit' received from coordintaor wait
end-do
perform local commit processing STEP P4 TERMINATION
send acknowledgement to coordinator finish
end
20.10 Analyze the DBMSs that you are currently using and determine the support each provides for
the X/Open DTP model and for data replication.
This is a small student project, the result of which is dependent on the system analyzed.
20.11 You have been asked by the Managing Director of DreamHome to investigate the data distribution requirements of the organization and to prepare a report on the potential use of a distributed DBMS. The report should compare the technology of the centralized DBMS with that of the distributed DBMS, and should address the advantages and disadvantages of implementing a DDBMS within the organization, and any perceived problem areas. The report should also address the possibility of using a replication server to address the distribution requirements. Finally, the report should contain a fully justified set of recommendations proposing an appropriate solution.
A well-presented report is expected. Justification must be given for any recommendations made.
20.12 Consider six transactions T1, T2, T3, T4, and T5 with:
T1 initiated at site S1 and spawning an agent at site S2,
T2 initiated at site S3 and spawning an agent at site S1,
T3 initiated at site S1 and spawning an agent at site S3,
T4 initiated at site S2 and spawning an agent at site S3,
T5 initiated at site S3.
72
Transaction Data items locked by
transaction
Data items transaction is waiting for Site involved in operations T1 x1 x8 S1 T1 x6 x2 S2 T2 x4 x1 S1 T2 x5 S3 T3 x2 x7 S1 T3 x3 S3 T4 x7 S2 T4 x8 x5 S3 T5 x3 x7 S3 Table 1
(a) Produce the local wait-for-graphs (WFGs) for each of the sites. What can you conclude from the local WFGs?
Conclusion: There is no local deadlock at any site.
(b)Using the above transactions, demonstrate how Obermarck's method for distributed deadlock detection works. What can you conclude from the global WFG?
Cycle at site 1, so move WFG from Site 1 to site 3. The resulting WFG shows a cycle:
which implies system is in global deadlock and one of the transactions must be selected to be aborted and restarted.
T1 T2
T3
T1 T4 T2 T3
T4 T5
Site 1 Site 2 Site 3
T1 T2
T3
T1 T4 T2 T3
T4 T5
Site 1 Site 2 Site 3
Text Text Text Sites 1 and 3 T1 T 2 T3 T4 T5 Text