0% found this document useful (0 votes)
27 views28 pages

Chapter 8 - Concurrency Control Techniques

The document discusses concurrency control techniques in database management systems, focusing on the importance of isolation and consistency among transactions. It covers various methods such as locking, timestamping, and optimistic approaches, detailing their mechanisms, advantages, and potential issues like deadlock and starvation. Additionally, it introduces concepts like multiversion concurrency control and multiple granularity locking, emphasizing their impact on performance.
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)
27 views28 pages

Chapter 8 - Concurrency Control Techniques

The document discusses concurrency control techniques in database management systems, focusing on the importance of isolation and consistency among transactions. It covers various methods such as locking, timestamping, and optimistic approaches, detailing their mechanisms, advantages, and potential issues like deadlock and starvation. Additionally, it introduces concepts like multiversion concurrency control and multiple granularity locking, emphasizing their impact on performance.
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/ 28

Exit Exam Tutorial

Part 2: Fundamental Database Management Systems


Episode 8: Concurrency Control Techniques
2.8 Concurrency Control
Techniques
2.8.1 Concurrency Control Protocol
 Transaction Processor is divided into:
- A concurrency-control manager, or scheduler, responsible
for assuring isolation of transactions
- A logging and recovery manager, responsible for the
durability of transactions.
- The scheduler (concurrency-control manager) must assure
that the individual actions of multiple transactions are
executed in such an order that the net effect is the same as
if the transactions had in fact executed one-at-a-time.
2.8 Concurrency Control
Techniques
1. 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.
2.8 Concurrency Control
Techniques
2.8.2 Concurrency Control Techniques and their Concepts
- Basic concurrency control techniques: Locking,
Timestamping and Optimistic methods.
- The First two are conservative approaches: delay
transactions in case they conflict with other transactions.
- Optimistic methods assume conflict is rare and only check
for conflicts at commit.
2.8 Concurrency Control
Techniques
2.8.2.1 Locking
- Lock is a variable associated with a data item that describes
the status of the data item with respect to the possible
operations that can be applied to it.
- Generally, a transaction must claim a shared (read) or
exclusive (write) lock on a data item before read or write.
- Lock prevents another transaction from modifying item or
even reading it, in the case of a write lock.
- Locking is an operation which secures permission to Read
and permission to Write a data item for a transaction.
- Unlocking is an operation which removes these permissions
from the data item.
2.8 Concurrency Control
Techniques
 Two locks modes:
- Shared mode: shared lock (X): More than one transaction
can apply share lock on X for reading its value but no write
lock can be applied on X by any other transaction.
- Exclusive mode: Write lock (X): Only one write lock on X
can exist at any time and no shared lock can be applied by
any other transaction on X.
2.8 Concurrency Control
Techniques
 Locking-Basic Rules:
- A transaction request access to an item X by first issuing a
lock_item(x) opreation.
- If lock (x)=1, the transaction is forced to wait.
- If lock (X)= 0; it is set to 1 and the transaction is allowed to
access x
- When a transaction finished operation on X it issues an
unlock _item operation which set lock(x) to 0 so that X may
be accessed by another transaction.
- If transaction has shared lock on item, can read but not update
item.
- If transaction has exclusive lock on item, can both read and
update item.
- Reads cannot conflict, so more than one transaction can hold
shared locks simultaneously on same item.
- Exclusive lock gives transaction exclusive access to that item.
2.8 Concurrency Control
Techniques
2.8.2.2 Two-Phase Locking Techniques
- Transaction follows 2PL protocol if all locking operations
precede first unlock operation in the transaction.
- Every transaction can be divided into Two Phases: Locking
(Growing) & Unlocking (Shrinking)
- Locking (Growing) Phase: A transaction applies locks (read
or write) on desired data items one at a time.
 Acquires all locks but cannot release any locks.
- Unlocking (Shrinking) Phase: A transaction unlocks its
locked data items one at a time.
 Releases locks but cannot acquire any new locks.
2.8 Concurrency Control
Techniques
- Deadlock: It is a state that may result when two or more
transaction are each waiting for locks held by the other to
be released.
- So the DBMS must either prevent or detect and resolve
such deadlock situations.
- There are possible solutions: Deadlock prevention,
deadlock detection and avoidance, and lock timeouts.
2.8 Concurrency Control
Techniques
DEADLOCK PREVENTION PROTOCOL: TWO POSSIBILITIES
1. Conservative Two-Phase Locking: A transaction locks all
data items it refers to before it begins execution.
 This way of locking prevents deadlock since a transaction
never waits for a data item.
 Limitation : It restrictions concurrency.
2. Transaction Timestamp (TS(T)): We can prevent deadlocks
by giving each transaction a priority and ensuring that lower
priority transactions are not allowed to wait for higher
priority transactions (or vice versa ).
- One way to assign priorities is to give each transaction a
timestamp when it starts up.
2.8 Concurrency Control
Techniques
- It is a unique identifier given to each transaction based on
time in which it is started. That means, if T1 starts before T2
, TS(T1)<TS(T2)
- The lower the timestamp, the higher the transaction's
priority, that is, the oldest transaction has the highest
priority.
- If a transaction Ti requests a lock and transaction Tj holds a
conflicting lock, the lock manager can use one of the
following two policies: Wait-die & Wound-wait.
2.8 Concurrency Control
Techniques
i. WAIT-DIE: If Ti has higher priority, it is allowed to wait;
otherwise it is aborted.
- An older transaction is allowed to wait on a younger
transaction.
- A younger transaction requesting an item held by an older
transaction is aborted.
- If TS(Ti) < TS(Tj), then (Ti older than Tj)Ti is allowed to wait.
- Otherwise (Ti younger than Tj)Abort Ti (Ti dies) and restart
it later with the same timestamp.
2.8 Concurrency Control
Techniques
ii. WOUND-WAIT: The opposite of wait-die
- If Ti has higher priority, abort Tj; otherwise Ti waits.
- A younger transaction is allowed to wait on an older one.
- An older transaction requesting an item held by a younger
transaction preempts the younger transaction by aborting
it.
- If TS(Ti) < TS(Tj), then (Ti older than Tj),Abort Tj (Ti wounds
Tj) and restart Tj later with the same timestamp.
- Otherwise (Ti younger than Tj)Ti is allowed to wait.
2.8 Concurrency Control
Techniques
DEADLOCK DETECTION AND RESOLUTION
- In this approach, deadlocks are allowed to happen.
 The scheduler maintains a wait-for-graph for detecting
cycle.
 When a chain like: Ti waits for Tj waits for Tk waits for Ti or
Tj occurs, then this creates a cycle.
 When the system is in the state of deadlock , some of the
transaction should be aborted by selected (victim) and
rolled-back
 This can be done by aborting those transaction: that have
made the least work, the one with the lowest locks, and that
have the least of abortion and so on.
2.8 Concurrency Control
Techniques
TIMEOUTS: It uses the period of time that several transaction
have been waiting to lock items
- It has lower overhead cost and it is simple.
- If the transaction wait for a longer time than the predefined
timeout period, the system assume that may be deadlocked
and aborted it.
STARVATION: Starvation occurs when a particular
transaction consistently waits or restarted and never gets a
chance to proceed further while other transaction continue
normally.
This may occur , if the waiting method for item locking:
- Gave priority for some transaction over others
- Problem in Victim selection algorithm- it is possible that the
same transaction may consistently be selected as victim
and rolled-back example In Wound-Wait.
2.8 Concurrency Control
Techniques
- FIFO (First-in-First-out) or Queue.
- Allow for transaction that wait for a longer time.
- Give higher priority for transaction that have been aborted
for many time.
2.8 Concurrency Control
Techniques
2.8.3 Concurrency Control Based on Timestamp Algorithm
- Timestamp: In lock based concurrency control , conflicting
actions of different transactions are ordered by the order in
which locks are obtained.
- But here, Timestamp values are assigned based on time in
which the transaction are submitted to the system using the
current date & time of the system.
- A monotonically increasing variable (integer) indicating the
age of an operation or a transaction.
- A larger timestamp value indicates a more recent event or
operation.
- Timestamp based algorithm uses timestamp to serialize the
execution of concurrent transactions.
2.8 Concurrency Control
Techniques
- It doesn’t use lock, thus deadlock cannot be occurred
- In the timestamp ordering, conflicting operation in the
schedule shouldn’t violate serializable ordering
- This can be achieved by associating timestamp value (TS) to
each database item which is denoted as follow:
a) Read_TS(X): the read timestamp of X – this is the largest
time among all the time stamps of transaction that have
successfully read item X.
b) Write_TS(X): the largest of all the timestamps of
transaction that have successfully written item X.
2.8 Concurrency Control
Techniques
- The concurrency control algorithm check whether conflict
operation violate the timestamp ordering in the following
manner: three options.
i. Basic Timestamp Ordering
- Transaction T issues a write_item(X) operation:
- If read_TS(X) > TS(T) or if write_TS(X) >
TS(T), then a younger transaction has already read/write
the values of the data item x before T had a chance to write
X.
- So abort and roll-back T and restarted with a new, larger
timestamp.
- Why is with new timestamp?, is there a difference between
this timestamp protocol and the 2PL for dead lock
prevention?
2.8 Concurrency Control
Techniques
- If the condition in part (a) does not exist, then execute
write_item(X) of T and set write_TS(X) to TS(T).
- Transaction T issues a read_item(X) operation:
- If write_TS(X) > TS(T), then an younger transaction
has already written to the data item, so abort and roll-back
T and reject the operation.
- If write_TS(X) ≤ TS(T), then execute read_item(X)
of T and set read_TS(X) to the larger of TS(T) and the
current read_TS(X).
- Limitation: cyclic restart/starvation may occur when a
transaction is continuously aborted and restarted.
2.8 Concurrency Control
Techniques
ii. Strict Timestamp Ordering
1. Transaction T issues a write_item(X) operation:
- If TS(T) > read_TS(X), then delay T until the transaction T’
that wrote or read X has terminated (committed or aborted).
2. Transaction T issues a read_item(X) operation:
- If TS(T) > write_TS(X), then delay T until the transaction T’
that wrote X has terminated (committed or aborted).
iii. Thomas’s Write Rule: Modification of Basic Timestamp
ordering Algorithm.
 A transaction T issue a write_item(X) Operation:
- If read_TS(X) > TS(T) then abort and roll-back T and reject
the operation.
- If write_TS(X) > TS(T), then just ignore the write
operation and continue execution. This is because the most
recent writes counts in case of two consecutive writes.
2.8 Concurrency Control
Techniques
2.8.4 Multiversion Concurrency Control Techniques
- This approach maintains a number of versions of a data item
and allocates the right version to a read operation of a
transaction.
- Thus unlike other mechanisms a read operation in this
mechanism is never rejected.
- This algorithm uses the concept of view serializability than
conflict serialiazability.
 Side effect:
- Significantly more storage (RAM and disk) is required to
maintain multiple versions.
- To check unlimited growth of versions, a garbage collection
is run when some criteria is satisfied.
2.8 Concurrency Control
Techniques
2.8.5 Validation (Optimistic) Concurrency Control
Techniques
- This technique allow transaction to proceed
asynchronously and only at the time of commit,
serializability is checked & transactions are aborted in case
of non-serializable schedules.
- Good if there is little interference among transaction.
- It has three phases: Read, Validation , and Write phase.
2.8 Concurrency Control
Techniques
i. Read phase: A transaction can read values of committed
data items. However, updates are applied only to local
copies (versions) of the data items (in database cache).
ii. Validation phase: If the transaction Ti decides that it
wants to commit, the DBMS checks whether the
transaction could possibly have conflicted with any
other concurrently executing transaction.
- While one transaction ,Ti, is being validated , no other
transaction can be allowed to commit.
- This phase for Ti checks that, for each transaction Tj that is
either committed or is in its validation phase.
iii. Write phase: On a successful validation, transactions’
updates are applied to the database; otherwise,
transactions are restarted.
2.8 Concurrency Control
Techniques
2.8.6 Multiple Granularity Locking Concepts
- A lockable unit of data defines its granularity
- Granularity can be coarse (entire database) or it can be fine
(an attribute of a relation).
- Example of data item granularity:
 A field of a database record
 A database record
 A disk block/ page
 An entire file
 The entire database
- Data item granularity significantly affects concurrency
control performance.
- Thus, the degree of concurrency is low for coarse
granularity and high for fine granularity.
2.8 Concurrency Control
Techniques
Special Thanks to the publisher and author with:
2.8 Concurrency Control
Techniques
TOPICS AND THE CONCEPTS:
Concurrency Control Techniques
Two-Phase Locking Techniques
Deadlock and Starvation
Timestamps
Multiversion Concurrency Control Concepts
Validation (Optimistic) Techniques
Granularity Locking Techniques

REFERENCES:
Fundamental Database Management Systems (6th Edition) by Ramez Elmasri, Shamkant B. Navaathe
Database Systems: A Practical Approach to Design, Implementation, and Management (6th Edition) by
Thomas Connolly, Carolyn Begg

PRESENTED BY:
Mohammed Nebil

HISTORY OF THE PROGRAMMING:


Boyce Codd

SPECIAL THANKS:
Digital Library of Educations
Federal Democratic Republic of Ethiopia, Ministry of Educations
Ethiopian Education Short Note

You might also like