Professional Documents
Culture Documents
JACK INTIATES HIS TRANSACTION, THE PROGRAM PLACES A READ LOCK ON HIS RECORD SINCE
HE IS READING THE RECORD TO CHECK THE ACCOUNT BALANCE. WHEN HE REQUESTS A
WITHDRAWAL THE PROGRAM ATTEMPTS TO PLACE A WRITE LOCK. HOWEVER JILL HAD
ALREADY PLACED A SHARED LOCK ON THE RECORD. AS A RESULT HIS REQUEST IS DENIED
SINCE IF A RECORD HAS A READ LOCK ANOTHER USER CANNOT OBTAIN A WRITE LOCK
LOCKING LEVEL (GRANULARITY)
This is the extent of the database resource that
is included with each lock; locks are
implemented at the following levels:
Database- entire database is locked and becomes unavailable to other users
Table- entire table containing a requested record is locked; this level is appropriate
mainly for bulk updates such giving all employees a 5% raise
Block or page- the physical storage block(or page) containing a requested record is
locked
Record- only the requested record or row is locked; all other records are available to
other users
Field- only the particular field or column in a requested record is locked; this level is
appropriate when the updates affect only one or two fields in a records e.g you
want to update price column
PROBLEMS ASSOCIATED WITH
LOCKING
As much as locking ensures that transactions do
not collide it results in deadlocks which is an
impasse that results when two or more
transactions have locked a common resource
and each waits for the other to unlock that
resource
Deadlock may be avoided using either deadlock
prevention or deadlock resolution
DEADLOCK PREVENTION
This is used when the user programs must lock
all records they will require at the beginning of a
transaction
Two Phase locking protocol is used in this case.
It has 2 phases:
i) Growing phase- where all the necessary
locks are acquired
ii) Shrinking phase- where locks are released
DEADLOCK RESOLUTION
It allows deadlocks to occur but builds mechanisms into
the DBMS for detecting and breaking the deadlocks
The DBMS maintains a matrix of resource usage which at
a given instant indicates what users (subjects) are using
what resources (objects); by scanning the matrix the
computer can detect deadlocks as they occur; it then
resolves the deadlocks by “backing up” one of the
deadlocks as they occur; any changes made by that
transaction up to the time of deadlock are removed and
the transaction is restarted when the required resources
become available
OPTIMISTIC APPROACH:
VERSIONING
• There is no form of locking but each transaction is
restricted to a view of the database as of the time
that the transaction started and when a transaction
modifies a record the DBMS creates a new record
version instead of overwriting the old record
• In cases of a conflict, changes made by one of the
users are updated in this case since they are time
stamped the earlier transaction is given priority; the
other user’s transaction is aborted or rolled back
EXAMPLE OF VERSIONING
TIME JACK’S TRANSACTION JILL’S TRANSACTION
T1 BEGIN TRANSACTION
T2 READ BAL BEGIN TRANSACTION
T3 READ BAL
T4 BAL = BAL-50 BAL = BAL+100
T5 WRITE BAL WRITE BAL
T6 COMMIT ROLL BACK
T7 RESTART TRANSACTION
T8
T9