Information Technology Reference
In-Depth Information
transactions cannot get any locks on x. A write lock on x allows both reading and
writing x.
In practice, there are usually other lock modes in addition to S and X locks. For
instance, there is a U lock for preparing for an update and intention locks IS, IX,
and SIX for locking multi-granular data items; the meaning of those locks will be
described later in Chap. 9 .
The duration of a lock can be long or short. A lock that is held until the
transaction commits or completes a total rollback is called a long-duration lock or
commit-duration lock . Releasing the commit-duration locks is part of the protocol
for committing or completing the rollback of a transaction, that is, among the last
steps performed in the call commit .T / (Algorithm 3.3 ), after the commit log record
h T; C i has been appended to the log buffer and the log has been flushed from the log
buffer onto the log disk. A short-duration lock is one that is released immediately
after completing the database action for which the lock was acquired. Such a lock is
released just after unlatching the target page of the action.
In the presence of partial rollbacks, a lock acquired for commit duration after
setting a savepoint may already be released when the transaction has completed a
rollback to that savepoint. Such a lock is still called a commit-duration lock, even
though it is released before the transaction has committed or completed its total
rollback.
The lock owner is always some transaction. This is in contrast to latches, which
are owned by processes or process threads. The server-process thread that executes
the database actions on behalf of a transaction T owns the latches it acquires on
database pages, while T owns the locks acquired on data items read or written on
data pages.
Thus, the full representation of a lock is the four-tuple
.T;x;m;d/,
where x is the lock name, m isthelockmode(S,X,IS,IX,SIX,U,etc.),d is the
duration of the lock (commit duration, short duration), and T is the identifier of the
transaction that owns the lock.
Locks .T;x;m;d/are stored in a main-memory data structure called a lock table ,
managed by the lock manager of the database management system. The lock table is
created and initialized to empty when the system is starting up. The lock table only
exists when an instance of the system is running: in the event of a system failure or
when shutting down the system, the lock table will disappear along with the other
main-memory structures of the system, such as the database and log buffers.
The lock table is organized as a hash table (or a balanced binary tree), indexed
by the lock name. In this way, finding out what locks exist on a given data item is
efficient. In addition, the locks held by each transaction T are chained together in
a two-way-linked list in the order of their acquisition. The two-way linking allows
any lock to be released efficiently, given a pointer to it.
The transaction record for T in the active-transaction table includes, besides
the transaction identifier, the transaction state and the U NDO -N EXT -LSN value, also
Search WWH ::




Custom Search