318,741 views
21 votes
21 votes
Three transactions to update inventory A, B, and C:

Time
Operations
T1
T2
T3
Item A
Item B
Item C
1
Begin Transaction T1
Begin
20
20
20
2
T1 reads item A
Read(A)
3
T1 write item A
A=A+1
4
Begin Transaction T2
Begin
5
T2 reads item B
Read(B)
6
T2 write item B
B=B+5
7
Begin Transaction T3
Begin
8
T1 COMMITS
Commit
9
T3 reads item C
Read(C)
10
T3 write item C
C=C+4
11
T2 reads item B
Read(B)
12
T2 write item B
B=B+2
13
T2 Commit***
Commit
14
T3 COMMITS
Commit
The number of final inventory of Items A, B, and C
?
?
?
Suppose that a crash occurs right after the log record with asterisks (***) next to it is written to disk, and the recovery procedure is then run.
a) Please replace question market (?) with the number inventory for products A, B, and C (6 points)
b) Which transactions get roll back? Which ones get roll forward? (3 points)

User Piegames
by
2.6k points

1 Answer

18 votes
18 votes

Answer:

a) After the recovery procedure is run, the final inventory of items A, B, and C will be as follows:

Item A: 21 (Transaction T1 was committed and its update to item A was applied)

Item B: 27 (Transaction T2 was not committed and its updates to item B were not applied)

Item C: 24 (Transaction T3 was committed and its update to item C was applied)

b) Transaction T2 will be rolled back because it was not committed at the time of the crash. Transactions T1 and T3 will be rolled forward because they were committed before the crash.

User Max Cascone
by
3.6k points