Preventing deadlock with
timestamps
:
wound-wait
scheme
Recall:
timestamping transaction
Timestamped transactions:
Each
transaction
is
assigned
a
unique
increasing
timestamp
:
T
1
,
T
2
,
T
3
, ...
Earlier
transactions
receives a
smaller
timestamp
Purpose
of the
time stamp
:
To
give
older
transactions
(=
transactions
with
smaller
timestamps
) a
higher
priority
Wound(kill)-wait
locking rule for transactions
The
Wound(kill)-wait
locking
rule
:
When an
older
transaction
tries to
lock a DB element
that has been
locked
by a
younger
transaction
:
The
older
transaction
will
wound (= kill/abort)
the
younger transaction
When a
younger
transaction
tries to
lock a DB element
that has been
locked
by a
older
transaction
:
The
younger
transaction
wait
until the
lock is released
(by the
older transaction
)
Graphically:
The
wound-wait
rule
will
prevent (forbid)
the
development
of
deadlock
because:
T
1
will
wound (= kill/abort)
the (younger)
T
n
:
(The
wait
direction
in
wound-wait
is
opposite
from a
wait-die
locking rule
!!!)
Note:
In
both
schemes
(
wait-die
and
wound-wait
), the
younger
transaction
will get
aborted
The
older
transaction
is
not
be
aborted
!!!
Example: wound-wait locking
Transactions:
Example
execution that
obeys
the
wound-wait
rule:
Note:
When a
transaction
is
aborted
and
restarts
, the
transaction
will
retain
its
transaction
timestamp
!!!