Locks-Granularity, Types, 2PL
Locks-Granularity, Types, 2PL
Row Level
Field Level
In a database-level lock, the entire
database is locked, thus preventing
the use of any tables in the database
by transaction T2 while transaction
Tl is being executed.
Although the row-level locking approach improves the availability of data, its
management requires high overhead because a lock exists for each row in a
table of the database involved in a conflicting transaction.
Row Level lock when the application session requests multiple locks on the same page.
The field-level lock allows concurrent
transactions to access the same row as long as they
require the use of different fields (attributes)
within that row.
These operations are automatically managed and scheduled by DBMS; the user
does not need to be concerned about locking or unlocking data items. (Every
DBMS has a default locking mechanism. If the user wants to override the
default, LOCK TABLE and other SQL commands are available for that purpose.)
Lock Types
The lock and unlock features in the figure eliminate the
lost update problem because the lock is not released
until the WRITE statement is completed.
Solutions :
serializability is guaranteed through a locking protocol known
as two-phase locking, and
No data are affected until all locks are obtained—that is, until the
transaction is in its locked point
In this example, the transaction acquires all of the locks
it needs until it reaches its locked point. (In this example,
Lock and unlock instructions: Execution of these transactions can result in deadlock.
For example, consider the following partial schedule:
T31: lock-S(A) T32: lock-S(B)
read(A) read(B)
lock-X(B) lock-X(A)
read(B) read(A)
if A = 0 then B := B + 1 if B = 0 then A := A + 1
write(B) write(A)
unlock(A) unlock(B)
unlock(B) unlock(A)