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. DBM pretend they are using a single-user system.
Purpose of Concurrency Control
o To enforce Isolation (through mutual exclusion)
among conflicting transactions. o To preserve database consistency through
consistency preserving execution of
transactions.
o To resolve read-write and write-write
conflicts.
Example: In concurrent
execution environment if T1 conflicts with T2 over a data item A, then the
existing concurrency control decides if T1 or T2 should get the A and if the
other transaction is rolled-back or waits.
Timestamp based concurrency control algorithm
Timestamp
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.
Basic Timestamp Ordering
1. Transaction T issues a write_item(X)
operation:
If read_TS(X) > TS(T) or if write_TS(X) >
TS(T), then an younger transaction has already read the data item so abort and
roll-back T and reject the operation.
If the condition in part (a) does not exist, then
execute write_item(X) of T and set write_TS(X) to TS(T).
2. 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).
Strict Timestamp Ordering
1. Transaction T issues a write_item(X)
operation:
If TS(T) > read_TS(X), then delay T 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 read X has terminated (committed or aborted).
Multiversion
concurrency control techniques
o
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.
o
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 satisfiedThis
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.
Multiversion technique based on
timestamp ordering
Assume X1, X2, …, Xn are the version of a
transactions. With each Xi a read_TS (read timestamp) and a write_TS (write
timestamp)
are associated.
read_TS(Xi):
The read timestamp of Xi is the largest of all the timestamps of transactions
that have successfully read version Xi.
write_TS(Xi): The write timestamp of Xi that wrote the
value of version Xi.
A
new version of Xi is created only by a write operation.
To ensure serializability, the following two rules
are used.
1. . If transaction T issues write_item (X) and
version i of X has the highest write_TS(Xi) of all versions of X that is also
less than or equal to TS(T), and read _TS(Xi) > TS(T), then abort and
roll-back T; otherwise create a new version Xi and read_TS(X) = write_TS(Xj) =
TS(T).
2. If transaction T issues read_item (X), find the
version i of X that has the highest write_TS(Xi) of all versions of X that is
also less than or equal to TS(T), then return the value of Xi to T, and set the
value of read _TS(Xi) to the largest of TS(T) and the current read_TS(Xi).
Rule
2 guarantees that a read will never be rejected.
Multiversion Two-Phase Locking Using
Certify Locks
Concept
o
Allow a transactionX whileT’ it
toiswritereadlockedby a data conflicting transaction T
o
This is accomplished by maintaining two versions
of each data item X where one version must always have been written by some committed
transaction. This
means a write operation
always creates a new version of X. Multiversion Two-Phase Locking Using Certify
Locks
n
Steps
1.
X is the committed version of a data item.
2.
T creates a second version X’ after obt
3.
Other transactions continue to read X.
4.
T is ready to commit so it obtains a certify lock on X’.
5.
The committed version X becomes X’.
6.
T releases its certify lock on X’, which
Compatibility tables for basic 2pl and 2pl
with certify locks:-
Note:
In multiversion 2PL read and write operations from conflicting
transactions can be processed concurrently.
This improves concurrency but it may delay transaction
commit because of obtaining certify locks on all its writes. It avoids cascading
abort but like strict two phase locking scheme conflicting transactions may get
deadlocked.
Validation (Optimistic) Concurrency Control
Schemes
In this technique only at the time of commit
serializability is checked and transactions are aborted in case of
non-serializable schedules.
Three
phases:
1.
Read phase
2.
Validation phase
3.
Write phase
1. 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).
2.Validation phase:
Serializability is checked before transactions write their updates to the
database.
o
This phase for Ti checks that, for each
transaction Tj that is either committed or is in its validation phase, one of
the following conditions holds:
§
Tj completes its write phase before
Ti starts its read phase.
§
Ti starts its write phase after Tj
completes its write phase, and the read_set of Ti has no items in common with
the write_set of Tj
§
Both the read_set and write_set of
Ti have no items in common with the write_set of Tj, and Tj completes its read
phase.
§
When validating Ti, the first
condition is checked first for each transaction Tj, since (1) is the simplest
condition to check. If (1) is false then (2) is checked and if (2) is false
then (3 ) is checked. If none of these conditions holds, the validation fails
and Ti is aborted.
3.Write phase:
On a successful validation transacti otherwise, transactions are
restarted.
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.