












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













(X) mode
. Data item can be both read as well as written. X-lock is requested using
lock-X
instruction.
2_._^ shared
(S) mode
. Data item can only be read. S-lock is requested using
lock-S^
instruction.
-^ Lock requests are made to concurrency-control manager.Transaction can proceed only after request is granted.
T :^ lock-S^2
(A) ; read (A) ; unlock (A) ; lock-S (B) ; read (B) ; unlock (B) ; display (A+B)
-^ Locking as above is not sufficient to guarantee serializability ā if
A^ and^ B
get updated in-between the read of
A^ and^ B , the displayed sum would be
wrong. ⢠A^ locking protocol
is a set of rules followed by all transactions while requesting and releasing locks. Locking protocols restrict the set ofpossible schedules.
T nor^ T^3
can make progress ā executing
lock-S (B)
causes^ T^4
to wait for
T to release its lock on^3
B , while executing
lock-X (A)
causes^ T^3
to wait for
T to release its lock on^4
A.
-^ Such a situation is called a
deadlock
.
-^ To handle a deadlock one of
T or^ T must be rolled back^3 and its locks released.
transaction may obtain locks ⢠transaction may not release locks ⢠Phase 2: Shrinking Phase ⢠transaction may release locks ⢠transaction may not obtain locks ⢠The protocol assures serializability. It can be proved thatthe transactions can be serialized in the order of their
lock
points^ (i.e. the point where a transaction acquired itsfinal lock).
does not
ensure freedom from
deadlocks ⢠Cascading roll-back is possible under two-phase locking.To avoid this, follow a modified protocol called
strict
two-phase locking
. Here^ a transaction must hold all its exclusive locks till it commits/aborts
-^ Rigorous two-phase locking
is even stricter: here
all
locks are held till commit/abort
. In this protocol
transactions can be serialized in the order in which theycommit.
serializability
. But still relies on the
programmer to insert the various locking instructions.
T issues the standard read/write instruction,i^ without explicit locking calls. ⢠The operation
read ( D ) is processed as: if T has a lock on i^
then^ read(
else begin^ if necessary wait until no other
transaction has a
lock-X^
on^ D
grant^ T a i^
lock-S^
on^ D ; read( D ) end
can be implemented as a
separate process
to which transactions send lock and unlock requests ⢠The lock manager
replies to a lock request by sending a lock grant messages
(or a message asking the transaction to roll back, in case of a deadlock) ⢠The requesting transaction
waits until its request
is answered
-^ The lock manager maintains a data-structure called a
lock
table^ to record granted locks and pending requests ⢠The lock table is usually implemented as an in-memory hashtable indexed on the name of the data item being locked
-^ Black rectangles indicate granted locks,^ white ones indicate waiting requests. ā¢^ Lock table also
records the type of lock granted or requested
.
-^ New request is added to the end of thequeue^ of requests for the data item, andgranted^
if^ it^ is^ compatible
with^ all earlier locks. ⢠Unlock requests result in the requestbeing deleted, and later requests arechecked^ to
see^ if^ they
can^ now^
be
granted. ⢠If^ transaction
aborts,^ all
waiting^
or
granted requests of the transaction aredeleted.^ ā¢^ lock manager may keep a list oflocks held by each transaction
, to
implement this efficiently GrantedWaiting
1.Only exclusive locks are allowed. 2.The first lock by
T may be on any data item. Subsequently, a i^ data^ Q^
can be locked by
T only if the parent of i^
Q^ is
currently locked by
T. i 3.Data items may be unlocked at any time. 4.A data item that has been locked and unlocked by
T cannot i^
subsequently be relocked by
Ti
protocol
ensures
conflict
serializability
as^ well
as
freedom from deadlock. ⢠Unlocking may occur earlier in the tree-locking protocol than inthe two-phase locking protocol.^ ā¢^ shorter waiting times, and increase in concurrency^ ā¢^ protocol is deadlock-free, no rollbacks are required ⢠Drawbacks^ ā¢^ Protocol does not guarantee recoverability or cascade freedom^ ā¢^ Need
to^ introduce
commit
dependencies
to^ ensure
recoverability ⢠Transactions may have to lock data items that they do notaccess. ⢠increased locking overhead, and additional waiting time ⢠potential decrease in concurrency ⢠Schedules not possible under two-phase locking are possibleunder tree protocol, and vice versa.
The levels, starting from the coarsest (top) level are ⢠database ⢠area ⢠file ⢠record
modes,
there are
three
additional lock modes with multiple granularity:^ ā¢^ intention-shared
(IS): indicates explicit
locking at a
lower level
of the tree but only with shared locks.
-^ intention - exclusive
(IX): indicates explicit
locking at a
lower level
with exclusive or shared locks
-^ shared
and^ intention
- exclusive
the^ sub-tree
rooted^ by that node is
locked explicitly in shared mode and explicit locking is being done at a
lower level with
exclusive-mode locks. ⢠intention locks allow a higher level node to be locked in Sor X mode without having to check all descendent nodes.