0% found this document useful (0 votes)
60 views

Unit 11 Concurrency Control Techniques: Structure

This document discusses concurrency control techniques in database management systems. It describes different types of locks used for concurrency control, including binary locks, shared locks, and exclusive locks. Binary locks can be in a locked or unlocked state, while shared locks allow concurrent read access and exclusive locks allow a single transaction to modify data. The document provides examples of how each lock type works and the rules for locking data items in transaction processing.

Uploaded by

gaardi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Unit 11 Concurrency Control Techniques: Structure

This document discusses concurrency control techniques in database management systems. It describes different types of locks used for concurrency control, including binary locks, shared locks, and exclusive locks. Binary locks can be in a locked or unlocked state, while shared locks allow concurrent read access and exclusive locks allow a single transaction to modify data. The document provides examples of how each lock type works and the rules for locking data items in transaction processing.

Uploaded by

gaardi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Database Management Systems Unit 11

Sikkim Manipal University Page No.: 199


Unit 11 Concurrency Control Techniques
Structure
11.1 Introduction
Objectives
Self Assessment Question(s) (SAQs)
11.2 Types of Locks: Locking Technique for Concurrency Control
Self Assessment Question(s) (SAQs)
11.3 Summary
11.4 Terminal Questions (TQs)
11.5 Multiple Choice Questions (MCQs)
11.6 Answers to SAQs, TQs, and MCQs
11.6.1 Answers to Self Assessment Questions (SAQs)
11.6.2 Answers to Terminal Questions (TQs)
11.6.3 Answers to Multiple Choice Questions (MCQs)
11.1 Introduction
Some of the main techniques used to control concurrent execution of
transactions are based on the concept of locking data items. A lock is a
restriction on access to data in a multi-user environment. It prevents
multiple users from changing the same data simultaneously. If locking is not
used, data within the database may become logically incorrect and may
produce unexpected results.
Objectives
To Know About
Types of Locks: Locking Technique for Concurrency Control
Self Assessment Question(s) (SAQs) (For section 11.1)
1. Define lock and what is the advantage of it?
Database Management Systems Unit 11
Sikkim Manipal University Page No.: 200
11.2 Types of Locks: Locking Technique for Concurrency
Control
Several types of locks are used in concurrency control, to introduce locking
concepts gradually. We shall first discuss binary locks, which are simple but
restrictive and so are not used in practice. We shall then discuss
shared/exclusive locks, which provide more general locking capabilities and
are used in practical database locking schemes.
Binary Locks: A binary lock can have two states or values: locked and
unlocked (or 1 and 0, for simplicity). A distinct lock is associated with each
database item X. If the value of the lock on X is 1, item X cannot be
accessed by a database operation that requests the item. If the value of the
lock on X is 0, the item can be accessed when requested.
Two operations, lock_item and unlock_item, are used with binarylocking. A
transaction requests access to an item X by first issuing a lock_item(X)
operation. If LOCK(X)=1, the transaction if forced to wait. If LOCK(X)=0, it
is set to 1 and the transaction is allowed to access item X. When the
transaction is through using the item, it issues an unlock_item(X) operation,
which sets LOCK(X) to 0 (unlocks the item), so that X may be accessed by
another transaction. Hence a binary lock enforces mutual-exclusion on the
data item.
Lock_item(D):
B: if LOCK(X)=0 ("item is unlocked")
Then LOCK(X)1 ("lock the item")
else begin
wait (until lock(X)=0 and
the lock manager wakes up the transaction);
goto B
end;
Database Management Systems Unit 11
Sikkim Manipal University Page No.: 201
unlock_item(X):
LOCK(X)0; ('unlock the item")
If any transactions are waiting
Then wake up one of the waiting transactions:
If the simple binary locking scheme described here is used, every
transaction must obey the following rules:
1. A transaction T must issue the operation loci_item(X) before any
read_item(X) or write_item(X) operations are performed in T,
2. A transaction T must issue the operation unlock_item(X) after all
read_item(X) and write_item(X) operations are completed in T.
3. A transaction T will not issue a lock_item(X) operation if it already holds
the lock on item X
4. A transaction T will not issue an unlock_item(X) operation unless it
already holds the lock on item X.
Shared Locks: It is used for read only operations, i.e., used for operations
that do not change or update the data.
E.G., SELECT statement:,
Shared locks allow concurrent transaction to read (SELECT) a data. No
other transactions can modify the data while shared locks exist. Shared
locks are released as soon as the data has been read.
Exclusive Locks: Exclusive locks are used for data modification
operations, such as UPDATE, DELETE and INSERT. It ensures that
multiple updates cannot be made to the same resource simultaneously. No
other transaction can read or modify data when locked by anexclusive lock.
Exclusive locks are held until transaction commits or rolls back since those
are used for write operations.
Database Management Systems Unit 11
Sikkim Manipal University Page No.: 202
There are three locking operations: read_lock(X), write_lock(X), and
unlock(X). A lock associated with an item X, LOCK(X), now has three
possible states: "read locked", "write-locked", or "unlocked". A read-locked
item is also called share-locked, because other transactions are allowed to
read the item, whereas a write-locked item is called exclusive-locked,
because a single transaction exclusive holds the lock on the item.
Each record on the lock table will have four fields: <data item name, LOCK,
no_of_reads, locking_transaction(s)>. The value (state) of LOCK is either
read-locked or write-locked.
read_lcok(X):
B, if LOCK(X)='unlocked'
Then begin LOCK(X)"read-locked"
No_of_reads(x)1
end
else if LOCK(X)="read-locked"
then no_of_reads(X)no_of_reads(X)+1
else begin wait(until)LOCK(X)="unlocked" and
the lock manager wakes up the transaction);
goto B
end;
write_lock(X):
B: if LOCK(X)="unlocked"
Then LOCK(X)"write-locked";
else begin
wait(until LOCK(X)="unlocked" and
the lock manager wkes up the transaction);
goto B
end;
Database Management Systems Unit 11
Sikkim Manipal University Page No.: 203
unlock(X):
if LOCK(X)="write-locked"
Then begin LOCK(X)"un-locked";
Wakeup one of the waiting transctions, if any
end
else if LOCK(X)=read-locked"
then begin
no_of_reads(X)no_of_reads(X)-1
if no_of_reads(X)=0
then begin LOCK(X)=unlocked";
wakeup one of the waiting transactions, if any
end
end;
Self Assessment Question(s) (SAQs) (For section 11.2)
1. Explain the shared locks.
2. Write down the rules to be followed in Binary locking scheme.
11.3 Summary
We have learnt about different types of locking in this unit.
11.4 Terminal Questions (TQs)
1. What do you understand by Shared lock?
2. Where do you use an exclusive lock? Write a note on this.
11.5 Multiple Choice Questions (MCQs)
1 is a restriction on access to data in a multi-user environment
a. A lock
b. A Transaction
c. A concurrency
d. None of the above
Database Management Systems Unit 11
Sikkim Manipal University Page No.: 204
2 . prevents multiple users from changing the same data
simultaneously.
(a) A lock
(b) A Transaction
(c) A concurrency
(d) None of the above
3 .. is also called share-locked, because other transactions are
allowed to read the item.
(a) Read -locked item
(b) Write-locked item
(c) Exclusive locked item
(d) None of the above
4 .item is called exclusive-locked, because a single transaction
exclusive holds the lock on the item.
a. Read -locked item
b. Write-locked item
c. Exclusive locked item
d. None of the above
11.6 Answers to SAQs, TQs, and MCQs
11.6.1 Answers to Self Assessment Questions (SAQs)
For Section 11.1
1. Some of the main techniques used to control concurrent execution of
transactions are based on the concept of locking data items. A lock is a
restriction on access to data in a multi-user environment. It prevents
multiple users from changing the same data simultaneously. If locking is
not used, data within the database may become logically incorrect and
may produce unexpected results. (Refer section 11.1)
Database Management Systems Unit 11
Sikkim Manipal University Page No.: 205
For Section 11.2
1. Several types of locks are used in concurrency control.
(Refer section11.2)
2. A binary lock can have two states or values: locked and unlocked (or 1
and 0, for simplicity).
11.6.2 Answers to Terminal Questions (TQs)
1. Shared Locks are used for read only operations, i.e., used for
operations that do not change or update the data..(Refer section 11.2)
2. Exclusive locks are used for data modification operations such as
UPDATE, DELETE, and INSERT (Refer section 11.2)
11.6.3 Answers to Multiple Choice Questions (MCQs)
1. A
2. A
3. A
4. B

You might also like