Unit-4 Concurrency Control
Unit-4 Concurrency Control
Exclusive mode
► If a transaction Ti has obtained an exclusive-mode lock
(denoted by X) on item Q, then Ti can both read and write
on Q.
Lock-compatibility matrix
• The use of these two lock (shared and exclusive) modes allows
multiple transactions to read a data item but limits write
access to just one transaction at a time.
Lock-compatibility matrix
Compatibility function –
• Let A and B represent arbitrary
lock modes.
• Suppose that a transaction Ti
requests a lock of mode A on item
Q on which transaction Tj (Ti = Tj ) Lock-compatibility
currently holds a lock of mode B. matrix comp
• If transaction Ti can be granted a
An element comp(A, B)
lock on Q immediately, in spite of of the matrix has the
the presence of the mode B lock, value true if and only if
then we say mode A is compatible mode A is compatible
with mode B. with mode B.
Lock-compatibility matrix
► Note that shared mode is compatible with shared mode, but not
with exclusive mode.
► At any time, several shared-mode locks can be held
simultaneously (by diffèrent transactions) on a particular data
item.
► A subséquent exclusive-mode lock request has to wait until the
currently held shared-mode locks are released.
► A transaction requests a shared lock on data item Q by executing
the lock- S(Q) instruction.
► Similarly, a transaction requests an exclusive lock through the
lock-X(Q) instruction.
► A transaction can unlock a data item Q by the unlock(Q)
instruction.
Locking Protocol
► Each transaction in the system follow a set of rules, called a
locking protocol, indicating when a transaction may lock and
unlock each of the data items.
► Locking protocols restrict the number of possible schedules.
► The set of all such schedules is a proper subset of all possible
serializable schedules.
► We shall present several locking protocols that allow only
conflict-serializable schedules, and thereby ensure isolation.
► When a transaction requests a lock on a data item in a
particular mode, and no other transaction has a lock on the
same data item in a conflicting mode, the lock can be granted.
Starvation condition
► Validation Phase –
► The validation test is applied to transaction Ti .
This determines whether Ti is allowed to
proceed to the write phase without causing a
violation of serializability. If a transaction fails
the validation test, the system aborts the
transaction.
► Write Phase – If the validation test succeeds for
transaction Ti, the temporary local variables that hold the
results of any write operations performed by Ti are copied
to the database. Read-only transactions omit this phase.
► To perform validation we must know phases of
transaction, hence associate TimeStamp with
transaction Ti