09 Concurrency Control-TELU Translated
09 Concurrency Control-TELU Translated
Oleh:
Tim Dosen
Goals of the Meeting
01 02
Students understand Students understand
how the working of how to handling
protocol locking deadlock problem
OUTLINES
• Lock-Based Protocols
• Deadlock Handling
9 /1 0/ 2 02 4 Storage Management 3
LOCK-BASED
PROTOCOL
9 /1 0/ 2 02 4 4
INTRODUCTION
• The fundamental properties of a transaction is isolation.
• When several transactions execute concurrently in the database, however, the isolation property may
no longer be preserved.
• To ensure that it is, the system must control the interaction among the concurrent transactions; this
control is achieved through one of a variety of mechanisms called concurrency-control schemes.
• There are a variety of concurrency-control schemes. No one scheme is clearly the best; each one has
advantages.
• In practice, the most frequently used schemes are two-phase locking and snapshot isolation.
• A transaction may be granted a lock on an item if the requested lock is compatible with locks already held on the
item by other transactions
• But if any transaction holds an exclusive on the item no other transaction may hold any lock on the item.
L O C K - B A S E D P R O T O C O L S ( C O N T. )
• Example of a transaction performing locking:
T2: lock-S(A);
read (A);
unlock(A);
lock-S(B);
read (B);
unlock(B);
display(A+B)
Note:
• Neither T3 nor T4 can make progress — executing lock-S(B) causes T4 to wait for T3 to release its lock on B,
while executing lock-X(A) causes T3 to wait for T4 to release its lock on A.
• Such a situation is called a deadlock.
– To handle a deadlock one of T3 or T4 must be rolled back
and its locks released.
D E A D L O C K ( C O N T. )
• The potential for deadlock exists in most locking protocols.
• Deadlocks are a necessary evil associated with locking, if we want to avoid
inconsistent states.
• Deadlocks are definitely preferable to inconsistent states, since they can be
handled by rolling back transactions, whereas inconsistent states may lead to
real-world problems that cannot be handled by the database system.
STARVATI ON
• Starvation is also possible if concurrency control manager is badly designed.
• For example:
– A transaction may be waiting for an X-lock on an item, while a sequence of
other transactions request and are granted an S-lock on the same item.
– The same transaction is repeatedly rolled back due to deadlocks.
• Concurrency control manager can be designed to prevent starvation.
THE TWO-PHASE LOCKING PROTOCOL
• A protocol which ensures conflict-serializable schedules.
• Phase 1: Growing Phase
Locks
– Transaction may obtain locks
– Transaction may not release locks
• Phase 2: Shrinking Phase Time
Silberschatz, Korth, and Sudarshan. Database System Concepts – 7th Edition. McGraw-Hill. 2019.
Source: https://www.db-book.com/db7/slides-dir/index.html