- System failed before step 1 is complete:
x and y unchanged - no problem
|
- System failed before step 2 is complete:
x and y unchanged - no problem
|
- System failed before step 3 is complete:
x and y
(in the database)
unchanged - no problem
|
- System failed before step 4 is complete:
- If system fail
before
writing of the log record ,
then x and y
(in the database)
are unchanged - no problem
- If system fail
after
writing of the log record ,
but
before
writing of the database,
then:
- x and y
(in the database)
are unchanged
- However, the log contains
old x = 4000
We are
NOT certain
whether x was modified... but we need to
make sure that
x gets back its original value !!!
To make certain
that the transaction is
atomic ,
we
restore
the value of
x
to its old x = 4000
- If system fail
after
writing of the database,
then:
- x = 3000
and y
is unchanged
- We has lost $1000 !!!
- Fortunately
the log contains
old x = 4000
We again
use the log record to
restore
x
to its orginal old x = 4000
|
NOTE:
- Here we see why we
must write the log
before
updating the data in the database
- If the data item x is
updated first ,
and the system fails
before the log is written ,
then
we
CANNOT restore x to its old value
(because we don't have the log record - which could not be
written because the system failed before it could write the log)
|
- System failed before step 5 is complete:
x = 3000
and y = 6000
- We has lost $1000 !!!
Fortunately
the log contains
old x = 4000
We
use the log record to
restore (UNDO)
x
to its orginal old x = 4000
|
- System failed before step 6 is complete:
Ditto: x = 3000
and y = 6000
- We has lost $1000 !!!
Fortunately
the log contains
old x = 4000
We
use the log record to
restore (UNDO)
x
to its orginal old x = 4000
|
- System failed before step 7
is complete:
- If system fail
before
writing of the log record
(for y),
then x = 3000
and y = 6000
We can use the log record for x to
restore (UNDO)
x
to its orginal old x = 4000
We don't need to restore y !
- If system fail
after
writing of the log record
(for y),
but
before
writing y,
then:
- x = 3000
and y = 6000
(in the database)
We are
NOT certain
whether y was modified... but we need to
make sure that
BOTH
x AND y
gets back its original value !!!
To make certain
that the transaction is
atomic ,
we
restore
the values of
x
to its old x = 4000
and
y
to its old y = 6000
- If system fail
after
writing of the database,
then:
Although it is correct, we
do NOT have any way of know
that y was updated
To make certain
that the transaction is
atomic ,
we
must mkae this choice:
restore
the values of
x
to its old x = 4000
and
y
to its old y = 6000
That's the only safe option.
|
- System failed before step 8 is complete:
There are 2 possibilities:
- System failed
before the COMMIT record
was written
In this case, we don't have any way of knowing
that both x and y
were updated for certain .
We do have both old values, so:
restore
the values of
x
to its old x = 4000
and
y
to its old y = 6000
- System failed
after the COMMIT record
was written
In this case, we
DO have the commit record to tell
us
that both x and y
were updated for certain !!!.
So when we see a
[commit, T]
record,
we
do NOT undo the transaction T
(using the old values)
|
|