Information Technology Reference
In-Depth Information
Algorithm 13.4
Procedure
prepare-to-commit
.s
0
;T
0
;L/, executed at s
i
if
the active-transaction table contains a record for a forward-rolling subtransaction T
i
of
transaction T
0
coordinated by s
0
then
log
.n;hT
i
;
prepare
;s
0
;T
0
;Li/
flush-the-log
./
other-participants
.T
i
/ L
state
.T
i
/ “prepared-to-commit”
return with vote “ready”
else
return with vote “aborting”
end if
Algorithm 13.5
Procedure
coordinate-decision-phase
.T
0
;L;V/, exec. at s
0
if
V contains “ready” votes from all the participants in L
then
commit
.T
0
/
for
all participants s
i
2 L
do
send the request
terminate
.s
0
;T
0
; “commit”/ to s
i
end for
else
rollback
.T
0
/
for
all participants s
i
2 L with a “ready” vote in V
do
send the request
terminate
.s
0
;T
0
; “abort”/ to s
i
end for
end if
Algorithm 13.6
Procedure
terminate
.s
0
;T
0
;D/, executed at s
i
if
the active-transaction table contains a record for a forward-rolling subtransaction T
i
of
transaction T
0
coordinated by s
0
then
if
D D “commit”
then
commit
.T
i
/
else
rollback
.T
i
/
end if
end if
Example 13.2
Consider the actions involved in executing the
commit
statement in
Example
13.1
when distributed transactions are coordinated using the two-phase
commit protocol.
In the voting phase, the coordinator s
0
first prepares to commit its own subtrans-
action T
0
by writing the prepare-to-commit log record
h
T
0
;
prepare
i
, by flushing
the log, and by setting
state
.T
0
/
“prepared-to-commit.” Then the coordinator
sends the request
prepare-to-commit
.s
0
;T
0
;L
i
/ to each participant s
i
, i
D
1;:::;k,
where L
i
Df
s
1
;:::;s
i1
;s
iC1
;:::;s
k
g
. Participant s
i
responds by writing the log