Information Technology Reference
In-Depth Information
4.2
Partial and Total Rollbacks
The execution of the
SQL
rollback
statement in transaction T is given as Algo-
rithm
4.1
(for our key-range transaction model). First, the state of T is changed to
“backward-rolling” in the transaction record of T in the active-transaction table,
and the abort log record
h
T; A
i
is written to the log (Algorithm
4.2
). Then the
U
NDO
-N
EXT
-LSN
chain for T is traversed, starting from the
U
NDO
-N
EXT
-LSN
value
stored in T 's transaction record in the active-transaction table, fetching from the
log the records with the
LSN
s in the chain, and executing the undo actions of the
update actions recorded with those log records (by calling one of
undo-insert
and
undo-delete
). Any set-savepoint log records encountered are just passed by. The
rollback is finished when the begin-transaction log record
h
T; B
i
is encountered;
then the transaction is recorded as having completed its rollback by executing the
call
commit
.T / (see Algorithm
3.3
).
Algorithm 4.1
Procedure
rollback
.T /
abort
.T /
r
get-log-record
.U
NDO
-N
EXT
-LSN.T //
while
r is not “n WhT; Bi”
do
if
r is “n WhT; I; p; x;
v
;n
0
i”
then
undo-insert
.n;T;p;x;n
0
/
else if
r is “n WhT; D; p; x;
v
;n
0
i”
then
undo-delete
.n;T;p;x;
v
;n
0
/
else if
r is “n WhT; SŒP ; n
0
i”
then
U
NDO
-N
EXT
-LSN.T / n
0
end if
r
get-log-record
.U
NDO
-N
EXT
-LSN.T //
end while
commit
.T /
Algorithm 4.2
Procedure
abort
.T /
state
.T / “backward-rolling”
log
.n;hT; Ai/
The call
get-log-record
.n/ returns the log record with
LSN
n. The call
undo-insert
.n;T;p;x;n
0
/ executes the undo action I
1
Œx;
v
, and the call
undo-
delete
.n;T;p;x;
v
;n
0
/ executes the undo action D
1
Œx;
v
. The latter two calls both
include the assignment
U
NDO
-N
EXT
-LSN
.T /
n
0
in the active-transaction table;
recall that n
0
is the value of
U
NDO
-N
EXT
-LSN
.T / at the point when the corresponding
forward-rolling action was performed. Also note that in the case in which the log
record r encountered is one for a set-savepoint action (
h
T; SŒP ; n
0
i
), nothing is
done besides the assignment of
U
NDO
-N
EXT
-LSN
.T /.