Concurrency Control Techniques
Concurrency Control Techniques
Techniques
Two-Phase Locking Technique
• Concept of two-phase locking
• Types of locks and system lock tables;
• Lock conversion;
• Guaranteeing serializability by two-phase locking;
• Basic, conservative, strict, and rigorous two-phase locking;
• Dealing with deadlock and starvation
What is concurrency?
• Concurrency in terms of databases means allowing multiple users to
access the data contained within a database at the same time.
• If concurrent access is not managed by the Database Management
System (DBMS) so that simultaneous operations don't interfere with
one another problems can occur when various transactions
interleave, resulting in an inconsistent database.
• Concurrency is achieved by the DBMS, which interleaves actions
(reads/writes of DB objects) of various transactions.
• Each transaction must leave the database in a consistent state if the
DB is consistent when the transaction begins.
• Concurrent execution of user programs is essential for good DBMS
performance.
• Because disk accesses are frequent, and relatively slow, it is important to
keep the CPU humming by working on several user programs concurrently.
• Interleaving actions of different user programs can lead to inconsistency:
e.g. check is cleared while account balance is being computed. DBMS ensures
such problems don‘t arise: users can pretend they are using a single-user
system.
Purpose of Concurrency Control
• To enforce Isolation (through mutual exclusion) among conflicting
transactions.
• To preserve database consistency through consistency preserving execution
of transactions.
• To resolve read-write and write-write conflicts.
Why concurrency control Needed?
• The lost of update problem: problem when two transactions that
access the same database items have their operations interleaved in
such way that value of the data item written by one transaction is
overlapped by another transaction and hence results to the incorrect
value of the database item.
• The dirty read(Temporary update) Problem: problem occur one
transaction updates a database item and then the transaction fails for
some reason.
• The updated item is accessed by another transaction before it’s
changed back to its original value which caused transaction T2 have
dirty value of the data item.
Cont…
Slide 21- 58
Multiversion Concurrency
Control Techniques (cont’d.)
• Multiversion technique based on timestamp ordering
• Two timestamps associated with each version are kept
• read_TS(Xi)
• write_TS(Xi)
Slide 21- 59
Multiversion Concurrency
Control Techniques (cont’d.)
• Multiversion two-phase locking using certify locks
• Three locking modes: read, write, and certify
Figure 21.6 Lock compatibility tables (a) Lock compatibility table for read/write locking
scheme (b) Lock compatibility table for read/write/certify locking scheme
Slide 21- 60
21.4 Validation (Optimistic) Techniques
and Snapshot Isolation Concurrency
Control
• Optimistic techniques
• Also called validation or certification techniques
• No checking is done while the transaction is executing
• Updates not applied directly to the database until finished transaction is
validated
• All updates applied to local copies of data items
• Validation phase checks whether any of transaction’s updates violate
serializability
• Transaction committed or aborted based on result
Slide 20- 61
Concurrency Control Based on
Snapshot Isolation
• Transaction sees data items based on committed values of the items
in the database snapshot
• Does not see updates that occur after transaction starts
• Read operations do not require read locks
• Write operations require write locks
• Temporary version store keeps track of older versions of updated
items
• Variation: serializable snapshot isolation (SSI)
Slide 20- 62
Validation (Optimistic) Techniques
and Snapshot Isolation Concurrency
Control
• Concept of validation (optimistic) techniques and
• snapshot isolation concurrency control