Database Reference
In-Depth Information
LEVELS
0
DATABASE
1
FILE-1
FILE-2
FILE-3
2
BLOCK-1
BLOCK-2
BLOCK-3
3
RECORD-1
RECORD-2
RECORD-3
4
FIELD-1
FIELD-2
FIELD-3
Figure 15-18
Hierarchy of locking levels.
locking protocol is a set of rules to be followed by transactions and enforced by the
DBMS to enable interleaving of database operations.
The lock manager component of the DBMS keeps track of all active locks by
maintaining a lock table. Usually, a lock table is a hash table with the identifier of
the data item as the key. The DBMS keeps a descriptive record for each active trans-
action in a transaction table, and this record in the transaction table contains a
pointer to the list of locks currently held by the transaction. Generally, the lock table
record for a data item contains the following: the number of transactions currently
holding a lock on the data item (more than one possible in shared mode), the nature
of the lock (S or X), and a pointer to a queue of lock requests for the data item.
The lock manager responds to lock and unlock requests by using the lock table
records and the queues of lock requests.
Let us briefly trace how the lock manager handles lock and unlock requests.
Assume a transaction T making lock and unlock requests on a data item D.
If T requests an S-lock(D), the queue of lock requests is empty, and D is not
currently in X-mode, the lock manager grants S-lock(D) and updates the lock
table record for D.
If T requests an X-lock(D) and no transaction currently holds a lock on D indi-
cated by an empty queue of lock requests, the lock manager grants X-lock(D)
and updates the lock table record for D.
Otherwise, the lock manager does not grant the request immediately and adds
the request to the queue for D (T is suspended.) When a transaction that was
holding D aborts or commits, it releases all locks. When a lock is released, the
lock manager updates the lock table record for D and inspects the lock request
at the head of the queue for D. If the lock request at the head of the queue can
be granted, the lock manager wakes up the transaction (T) at the head of the
queue and grants the lock.
When a transaction requests a lock on a data item D in a particular mode and
no other transaction has a lock on the same data item in a conflicting mode, the lock
manager grants the lock. Now, follow the sequence of a set of lock requests on data
item D and observe the predicament of one of the transactions:
Search WWH ::




Custom Search