1. A Research
On
“Lock base concurrency control”
For Partial Fulfillment of the Requirements for the Degree of
Master of Computer Information System Awarded by
Pokhara University
Date: 24 July 2019
2. Table of Contents
1. Introduction.............................................................................................................................. 1
2. Locking Based Algorithms ...................................................................................................... 2
3. Lock-Based Protocols Example............................................................................................... 4
4. Lock Based protocols .............................................................................................................. 5
5. 2PL for DDBMS...................................................................................................................... 6
5.1 Centralized 2PL..................................................................................................................... 6
5.2 Primary copy 2PL ................................................................................................................. 6
5.3 Distributed 2PL..................................................................................................................... 7
6. Communication structure of the distributed 2PL..................................................................... 8
7. Conclusion............................................................................................................................... 9
8. References.............................................................................................................................. 10
3. Abstract
The lock base concurrency control is a well-accepted method to handle database transaction at
execution time. When the multiple users try to access data at exactly the same time lock-based
concurrency control manipulation and lock the database execution and provide effective data to
the user. Without the concurrency control, there might be a problem with performance in a
database transaction. Multiple frameworks based database concurrency control is the most
important element for proper functioning
4. 1
1. Introduction
A lock is a variable related with an information thing that depicts a status of information thing as
for conceivable activity that can be connected to it. They synchronize the entrance by
simultaneous exchanges to the database things. It is required in this convention that every one of
the information things must be gotten to in a fundamentally unrelated way. Give me a chance to
acquaint you with two regular locks which are utilized and some wording followed in this
convention. A lock is a data variable which is associated with a data item. This lock signifies that
operations that can be performed on the data item. Locks help synchronize access to the database
items by concurrent transactions. All lock requests are made to the concurrency-control manager.
Transactions proceed only once the lock request is granted.
5. 2
2. Locking Based Algorithms
Locking-based concurrency algorithms ensure that data items shared by conflicting operations
are accessed in a mutually exclusive way. This is accomplished by associating a “lock” with each
such data item.
Terminology Use in this protocol
Shared Lock (S): also known as Read-only lock. As the name suggests it can be shared between
transactions because while holding this lock the transaction does not have the permission to
update data on the data item. S-lock is requested using lock-S instruction.
Exclusive Lock (X): Data item can be both read as well as written. This is Exclusive and cannot
be held simultaneously on the same data item. X-lock is requested using lock-X instruction.
Two types of locks (lock modes)
o Read lock (rl) – also called shared lock
o Write lock (wl) – also called exclusive lock
Compatibility matrix of locks
rl
i
(x) wl
i
(x) rl
j
(x) Compatible not compatible wl
j
(x) Not compatible not compatible
General locking algorithm
1. Before using a data item x, transaction requests lock for x from the lock manager
6. 3
2. If x is already locked and the existing lock is incompatible with the requested
lock, the Transaction is delayed
3. Otherwise, the lock is granted.
7. 4
3. Lock-Based Protocols Example
Transaction performing locking:
T2: lock-S (A);
Read (A);
Unlock (A);
Lock-S (B);
Read (B);
Unlock (B);
Display (A+B)
Locking as above is not sufficient to guarantee serializability — if A and B get updated
in-between the read of A and B, the displayed sum would be wrong.
A locking protocol is a set of rules followed by all transactions while requesting and
releasing locks. Locking protocols restrict the set of possible schedules
8. 5
4. Lock Based protocols
4.1 Two-phase locking protocol (2PL)
Each transaction is executed in two phases
Growing phase:
-Transaction may obtain locks
-Transaction may not release locks
Shrinking phase: the transaction releases locks
- Transaction may release locks
- Transaction may not obtain locks
4.1.1 Properties of the 2PL protocol
Generates conflict-serializable schedules – But schedules may cause cascading aborts
If a transaction aborts after it releases a lock, it may cause other transactions that have accessed
the unlocked data item to abort as well.
Strict 2PL locking protocol
Holds the locks till the end of the transaction – Cascading aborts are avoided
9. 6
5. 2PL for DDBMS
Various extensions of the 2PL to DDBMS
5.1 Centralized 2PL
A single site is responsible for the lock management, i.e., one lock manager for the whole
DDBMS – Lock requests are issued to the lock manager – Coordinating transaction manager
(TM at site where the transaction is initiated) can make all locking requests on behalf of local
transaction managers.
• Advantage:
Easy to implement
• Disadvantages:
Bottlenecks and lower reliability
Replica control protocol is additionally needed if data are replicated.
5.2 Primary copy 2PL
– Several lock managers are distributed to a number of sites
– Each lock manager is responsible for managing the locks for a set of data items
– For replicated data items, one copy is chosen as primary copy, others are slave copies
– Only the primary copy of a data item that is updated needs to be write-locked
– Once primary copy has been updated, the change is propagated to the slaves
• Advantages
– Lower communication costs and better performance than the centralized 2PL
• Disadvantages
– Deadlock handling is more complex
10. 7
5.3 Distributed 2PL
– Lock managers are distributed to all sites
– Each lock manager responsible for locks for data at that site
– If data is not replicated, it is equivalent to primary copy 2PL
– If data is replicated, the Read-One-Write-All (ROWA) replica control protocol is
Implemented ∗ Read(x): Any copy of a replicated item x can be read by obtaining a read lock on
The copy ∗ Write(x): All copies of x must be write-locked before x can be updated
• Disadvantages
– Deadlock handling more complex
– Communication costs higher than primary copy 2PL
11. 8
6. Communication structure of the distributed 2PL
The coordinating TM sends the lock request to the lock managers of all participating Sites.
– The LMs pass the operations to the data processors
– The end of the operation is signaled to the coordinating TM
Fig: Communication structure of the distributed 2PL
12. 9
7. Conclusion
Concurrency orders the operations of transactions such that two properties are achieved: the
database is always in a consistent state and the maximum concurrencies of operations are
achieved. Concurrency Control is a problem that arises when multiple processes are involved in
any part of the system. In most commercial systems, the most popular mechanism for
concurrency control is two-phase locking.