Preventing deadlock with
timestamps
: the
wait-die
method
Timestamping transaction
Timestamped transactions:
Each
transaction
is
assigned
a
unique
increasing
timestamp
:
T
1
,
T
2
,
T
3
, ...
Important fact:
An
earlier
transactions
receives a
smaller
timestamp
Purpose
of the
time stamp
:
To
give
older
transactions
(=
transactions
with
smaller
timestamps
) a
higher
priority
over
"younger" transactions
Wait-die locking rule for
deadlock
avoidance
The
Wait-die
locking
rule
:
When an
older
transaction
tries to
lock a DB element
that has been
locked
by a
younger
transaction
:
The
older
transaction
will
wait
until the
lock is released
(by the
younger transaction
)
When a
younger
transaction
tries to
lock a DB element
that has been
locked
by a
older
transaction
:
The
younger
transaction
will
die
(= abort)
Graphically:
The
wait-die
rule
will
prevent
the
development
of
deadlock
because:
T
n
cannot wait for
T
1
:
So
there
cannot
be a
cycle
in the
wait-for graph
:
No deadlock
possible
!!!
Example: wait-die locking
Transactions:
Example
execution that
obeys
the
wait-die
rule:
Important note:
When a
transaction
is
aborted
and
restarts
:
The
transaction
will
retain
its
(old) transaction
timestamp
!!!
Therefore:
Eventually
, a
transaction
will
become
the
"oldest" transaction
and
will
complete execution
!!!