You are on page 1of 13

A

SEMINAR PRESENTATION

ON

CONCURRENCY CONTROL AND MANAGEMENT IN DISTRIBUTED


DATABASE

PRESENTED BY

JIMMY, OTUEKONG OKON


REG NO: 19165025

SUBMITTED TO

THE DEPARTMENT OF COMPUTER SCIENCE


HERITAGE POLYTECHNIC, IKOT UDOTA, EKET,
AKWA-IBOM STATE.

JULY, 2021

1
TABLE OF CONTENTS

Introduction - - - - - - - - - -3
Concurrency Control in a Distributed Database Management System - -3
Database Concurrency - - - - - - - -3
Why is Concurrency Control Needed - - - - - -4
Types and the Issue of Concurrency Control - - - - - -5
Improvement of Issue in Concurrency Control - - - - -8
Conclusion -- - - - - - - - - -12
References

2
INTRODUCTION
Concurrency control is the activity of coordinating concurrent accesses to a database in a
multiuser database management system (DBMS). Concurrency control permits users to access a
database in a multi-programmed fashion while preserving the illusion that each user is executing
alone on a dedicated system. The main technical difficulty in attaining this goal is to prevent
database updates performed by one user from interfering with database retrievals and updates
performed by another (Shapour, 2007).

CONCURRENCY CONTROL IN A DISTRIBUTED DATABASE MANAGEMENT


SYSTEM
Concurrency Control in Distributed Database Management System is a procedure
of managing simultaneous operations without conflicting with each other. It ensures that
Database transactions are performed concurrently and accurately to produce correct results
without violating data integrity of the respective Database.

DATABASE CONCURRENCY
Database concurrency is the ability of a database to allow multiple users to affect multiple
transactions. This is one of the main properties that separates a database from other forms of data
storage, like spreadsheets. Other users can read the file, but may not edit data.
The goal of concurrency control is to prevent interference among users accessing a database. Let
us illustrate the problem by presenting two "canonical" examples of interuser interference
(Abdou, 2004).
Examples of an on-line electronic funds transfer system accessed via remote automated teller
machines
(ATMs). In response to customer requests, ATMs retrieve data from a database, perform
computations, and store results back into the database.
Anomaly 1: Lost Updates. Suppose two customers simultaneously try to deposit money into the
same account. In the absence of concurrency control, these two activities could interfere (see
Figure 1). The two ATMs handling the two customers could read the account balance at
approximately the same time, compute new balances in parallel, and then store the new balances
back into the database. The net effect is incorrect: although two customers deposited money, the
database only reflects one activity; the other deposit is lost by the system.

3
Anomaly 2: Inconsistent Retrievals. Suppose two customers simultaneously execute the
following transactions.
Customer 1: Move $1,000,000 from Acme Corporation's savings account to its checking
account.
Customer 2: Print Acme Corporation's total balance in savings and checking

WHY IS CONCURRENCY CONTROL NEEDED


If transactions are executed serially, i.e., sequentially with no overlap in time, no transaction
concurrency exists. However, if concurrent transactions with interleaving operations are allowed
in an uncontrolled manner, some unexpected, undesirable results may occur, such as:

1. The lost update problem: A second transaction writes a second value of a data-item
(datum) on top of a first value written by a first concurrent transaction, and the first value
is lost to other transactions running concurrently which need, by their precedence, to read
the first value. The transactions that have read the wrong value end with incorrect results.
2. The dirty read problem: Transactions read a value written by a transaction that has been
later aborted. This value disappears from the database upon abort, and should not have
been read by any transaction ("dirty read"). The reading transactions end with incorrect
results.
3. The incorrect summary problem: While one transaction takes a summary over the
values of all the instances of a repeated data-item, a second transaction updates some
instances of that data-item. The resulting summary does not reflect a correct result for

4
any (usually needed for correctness) precedence order between the two transactions (if
one is executed before the other), but rather some random result, depending on the
timing of the updates, and whether certain update results have been included in the
summary or not.
Most high-performance transactional systems need to run transactions concurrently to meet their
performance requirements. Thus, without concurrency control such systems can neither provide
correct results nor maintain their databases consistently.

TYPES AND THE ISSUE OF CONCURRENCY CONTROL


 Two -phase locking
Two -phase locking is a widely used concurrency control technique to synchronize
accesses to shared item. Each data item has a lock associated with it. The scheduler will
first examine the associated lock before a transaction (T1) may access a data item. If
there is no transaction holds the lock then the scheduler will obtains the lock on behalf of
T1. When another transaction T2 hold the lock, the T1 has to wait until T2 to gives up the
lock. The scheduler will give the T1 the lock after the T2 release the lock. Scheduler must
ensure that there is only one transaction can hold the lock at a time and only one
transaction can access data item at a time. They are two types of locks associate with data
item that is read locks and write locks. Figure 1 below show that the transaction T1 and
T2 follow the two-phase locking protocol.
Figure 1: Transaction T1 and T2 with 2-phase locking protocol
However, there is an important and unfortunate property of two-phase locking schedulers
is that they are subject to deadlocks. For instances, the classic deadlock situation in which
neither of two processes can proceed that is one must release a resource and the other one
needs to proceed. Besides that, deadlock also arises when the transaction try to strengthen
read locks to write locks. To ensure that there is no transaction is blocked forever, the
scheduler needs a strategy for detecting the deadlock (Philip, 2018).
In addition, two-phase locking is suffer from sensible delays due to a node needs to send
message to all nodes and must receive acknowledgement from all nodes to discover a
deadlock. The messages will exchange between nodes to get decision of transaction’s

5
commit. The whole system will stop since not discover the deadlock immediately and a
natural of distributed system make deadlock treatment very difficult. Moreover, the
message that due to commit and deadlock treatment make high traffic on network which
is makes need of special kind of networking.
Figure 2: A spatial schedules of T1 and T2 in state of deadlock
T1 wait for T2 to release read lock on y2
T3 wait for T1 to release read lock on x1
T2 wait for T3 to release read lock on z3
Figure 3: A wait-for graph for the spatial schedule of Figure 2
There are two type of graph that show as above which is a spatial schedule of T1 and T2
in the state of deadlock. Another graph show that the wait for graph for the spatial
schedule of the figure 2 above. Each node of the graph represent the transaction, the
edges represent the “waiting for” relationship.
Furthermore, concurrency control also deals with starvation. The starvation occurs when
a particular transaction consistently waits or restarted and never gets a chance to proceed
further. In a deadlock resolution it is possible the same transaction may consistently be
selected as victim and rolled-back. This type of limitation is inherent in all priority based
scheduling mechanism. The wound-wait scheme a younger transaction may always be
aborted by a long running older transaction which may create starvation.
Besides that, the two phases in locking method also may cause to dirty read and
cascading abort. The problem of dirty read is arises when assume T1 and T2 are executed
interleave. For this condition, the T1 will get the exclusive locks for record. Supposedly,
T1 release locks immediately after doing updates while T2 acquires that locks and does
its update. If the T1 fail before it commits due to certain of reason, then it will return
value to original value. T2 will continue to its execution with uncommitted data and this
will cause an error on the system result. On the other hand, the problem of cascading
abort arises when if a transaction aborts. There may have some other transaction already
used data from an object that the aborted transaction modified it and unlocked it. If this
happen, any such transaction will also have to be aborts.

6
 Timestamp ordering technique
Timestamp is a monotonically increasing variable indicating the age of an operation or a
transaction. The larger of the timestamp values indicate that more recent event or
operation. Timestamp ordering technique concurrency mechanism were considered
suitable for distributed database systems since transaction to be rolled back can be
determined locally at each site. It involves a unique transaction timestamps in place of
conventional locks. This technique is based on the idea that an operation is allowed to
proceed only if all the conflicting operations of older transaction have already been
processed. For instance, when a transaction accesses an item the system will check
whether the transaction is older than the last one which is accesses the item. If this is the
case that transaction proceeds, otherwise ordering is violated and the transaction is
aborted. Besides that, the serializability of the transaction is preserved and requires
knowledge about which transaction are younger than the others.
In the implementation of a distributed timing system, each site in the distributed system
contains a local clock or a counter. This clock assumed to tick at least once between any
two events. This event within the site is totally ordered. If the total ordering of event at
different sites, it need to assigned a unique number to each site and the number is
concatenated as least significant bits to the current value of local block. Moreover, each
message contains the information about the local time of their site of origin at which the
message is sent. There are many concurrency control method on timestamp ordering
technique. One of the method is basic timestamp ordering (BTO) which is for each data
item x, the largest timestamp of any write operation on data item x and the largest
timestamp of any read operation on data item x which are denoted by R_TS (x) and
W_TS (x) respectively.
The basic timestamp ordering technique is easy to distribute and the transaction to be aborted
will immediately be recognized when the operation are being scheduled. This type of method
will not deal with deadlock problem because the locks are not used and operations are blocked.
Hence, an atomic commitment mechanism is necessary to provide the reliability.

7
IMPROVEMENT OF ISSUE IN CONCURRENCY CONTROL
1. Deadlock resolution
The preceding implementation of two-phase locking makes the transaction to wait for
unavailable locks. When the waiting is uncontrolled will cause a deadlock. The situation
of deadlock can be characterized by wait-for graph, that graph indicates which
transaction is waiting for which other transaction. There are three type of general
technique are available for deadlock resolution that are deadlock detection, deadlock
prevention and timeout strategies.
 Deadlock Detection
Deadlock detection is a transaction wait for each other in an uncontrolled manner and
is only aborted if a deadlock occurs. It can be detected by explicitly constructing a
wait-for graph and searching it for cycles. Victim which is one transaction on the
cycle will abort when cycle is found and thereby breaking the deadlock. There are a
few victim selection criteria will be consider. First is the Current Blocker, this
current blocker will pick the transaction that blocked the most recently. Secondly,
Random Blocker which is a process of picks a transaction at random from the
participants in the deadlock cycle. Third is the Min Locks that is to pick a transaction
that is holding the fewest locks. Fourth is the Youngest which is picked the
transaction with the most recent initial startup time. Lastly is the Min Work and
responsible to pick the transaction that has consumed the least amount of physical
resources (CPU + I/O time) since it first began running (Wu, 2009).

In order to minimize the cost of restarting the victim, usually the victim is based on
the amount of resource that use by each of transaction on the cycle. Each of the two-
phase locking’s scheduler can be easily construct the waits-for graph based on the
waits-for relationships local to that scheduler. But this is not efficient to characterize
all deadlocks in the distributed system. To increase the efficiency, more “global”
wait-for graphs have to combine with local waits-for graph. For the centralized two-
phase locking will not have this type of problem since there only consist of one
scheduler.
In order to construct global waits-for graph, there consist of two techniques which
are hierarchical and centralized deadlock detection. For the hierarchical deadlock

8
detection, the database sites are organized into hierarchy with deadlock detector to
each node of the hierarchy. Deadlock divided into many sites. Deadlock involve a
single site are detected at that. Whereas deadlock involve more than two sites of the
same region detected by the regional deadlock detector.
On the other hand, one site is designated the deadlock detector in the centralized
deadlock detection. Every few minutes, each scheduler has to send its local wait-for
graph to the deadlock detector. Then the deadlock detector combines the local graph
into a system wide waits-for graph by constructing the union of the local graph.
Although both of the technique mention above differ in detail but it involve periodic
transmission of local waits-for information to one or more deadlock detector sites.
 Deadlock Prevention
Deadlock prevention is a “cautious” scheme in which transaction is restarted when
the system is afraid that deadlock to be occurring. In the process of deadlock
prevention, the scheduler will test the requesting transaction which is name (T1) and
the transaction that currently owns by the lock (T2) when a lock request is denied.
When T1 and T2 pass the test, T1 is permitted to wait for T2 as usual. Otherwise, one
of the two is aborted. There are a few prevention algorithms that are Wound-Wait,
Wait-Die, Immediate-Restart and Running Priority. In the Wait-Die prevention
algorithm, if a lock request from transaction T1 leads to a conflict with another
transaction T2, then T1 started time earlier than T2 and block the T1 otherwise will
restarted T1. The deadlock prevention will know as no preemptive if T1 is restarted.
By this technique deadlock are impossible since there is only one transaction can be
blocked by a younger transaction.
In the Wound-Wait algorithm, if T1 started running before T2 then restarted T2
otherwise blocked T1. This type of algorithm is known as preemptive which is older
transaction run though the system by killing any one that they conflict with and
continues waiting onlt for older conflicting transaction. The scheduler must ensure
that T1 wait for T2 so that deadlock cannot occur. There is a better approach can be
assign priorities to transaction and to test priorities to decide whether T1 can wait for
T2. If T1 has the lower priority than T2 then T1 will wait for T2. When they have
same priorities, T1 cannot wait for T2 or vice versa. This test will prevents the

9
deadlock to occur since every edge in the waits-for graph T1 has a lower priority
than T2. In addition, the Immediate-Restart algorithm also will overcome the
deadlock by simply restart T1 since there is no transaction is ever blocked.
Besides that, preordering of resources is a type of deadlock avoidance technique that
used to avoid restarts altogether. It requires predeclaration of locks which mean that
each transaction obtains all its locks before execution. The priority of transaction is
the number of the highest number lock on it and the data item are numbered and each
transaction request locks one at a time in numeric order. Although this techniques
can avoid the deadlock occur but it forces locks to be obtained sequentially which is
tends to increase response time.
 Timeout strategic
In the timeout strategic, a transaction whose lock request cannot be granted is simply
placed in the blocked queue. When the wait time exceeds some threshold value then
the transaction will restarted. Timeout will restart transaction that involves in
deadlocks in the detection strategies whereas in prevention strategic it may also
restarted some transaction that are not involved in any cycle.
2. Strict 2 Phase Locking (S2 PL)
In order to prevent cascading problem and dirty read, Strict 2 Phase Locking mechanism
is apply. The executed transaction holds all its lock to the every end until it is committed
or aborts. For the dirty read, the executed transaction does not release any of exclusive
locks until it commits or aborts. S2PL has important role in the two phase locking
problems. In first time transaction it need a lock on a data item, acquires it and all locks
of a transaction released together when the transaction terminates and has a few resource
wasting. Figure 4 below show the S2PL mechanism.
Figure 4: S2PL mechanism
3. Ordering by Serialization Number (OSN) Method
There exists a new method for concurrency control in distributed system which increases
the level of concurrent execution of transaction and known as ordering by serialization
number (OSN). The deadlock is prevented by this method since it works in the certifier
mode and uses time interval technique in conjunction. In order to provide serializability,
it combines with time interval technique with short term locks. Scheduler is distributed

10
and the standard transaction execution policy is assumed. The read and write operations
are issued continuously during transaction execution. The write operations are performed
on the private copies of the data that issue by the transaction. The transaction is certified
and its operation will applied to database when a validation test is passed by the
transaction at the end of transaction. Otherwise, the transaction will restart if the test
validation is not passed.
To find the serialization number for a transaction, the largest serialization number of
certified transaction will read item x. The largest serialization number of certified
transaction which have written item x will record along the data item x which is known as
RSN(x) and WSN(x). There consist of four types of short term locks in this OSN method
that are R-lock, W-lock, Certified Read lock, Certified Write lock. The R-lock and W-
lock normally used when read or write the data item. It responsible to protect the data
item forms two conflicting operations of concurrent transaction. Whereas Certified Read
lock (CR-lock) and Certified Write lock (CW-lock) are used during the validation test
while a transaction is searching for a valid time interval. These lock are held until either
the transaction’s operation are applied to the database or the transaction is aborted
(Rakesh, 2016).
The deadlock of short term locks is prevented by a few steps. Firstly, R-lock or W-lock is
obtained at any order. Since transaction do not require any other lock before releasing a
particular R-lock or W-lock deadlock does not appear. Secondly, employing the
preordering for deadlock avoidance can prevent the deadlock of the CR-lock and CW-
lock respectively. Although this method requires the access set of transaction to known in
advance but this disadvantage eliminated in the OSN method (Sang, 2014).

11
CONCLUSION
In this study, the performance of concurrency control protocol on top of a comprehensively
modeled high-speed network is evaluated. It found that there exist of some issue within the
concurrency protocol such as deadlock and starvation in the two-phase locking. The weaknesses
that occur in another concurrency protocol that is timestamp ordering.
By the way, there are also discussing about the effective way to make improvement of the
concurrency control by using three types of deadlock resolution to solving the deadlock problem.
The deadlock resolution included deadlock detection, deadlock prevention and timeout strategic.
Furthermore, a precise definition of deadlock in term of existence interval of an edge is given
and these help provide a better understanding of deadlock detection is distributed system.
Besides, this paper also discuss the complete specification of a secure version of two phase
locking protocol. The interaction between the protocol and the standard failure recovery
procedures were discuss and modification to the commit and restart procedures were proposed.

12
REFERENCES
Abdou R.; Hany M. and Harb, N (2004): “Two Phase Locking Concurrency Control in
Distributed Database with N-Tier architecture”, .
Philip A. (2018): BERNSTEIN AND NATHAN GOODMAN, “Concurrency Control in
Distributed Database Systems”,
Rakesh, A. Michael, J. Member, I. and Lawrence, W. (2016):” The Performance of Alternative
Strategies for Dealing with Deadlocks in Database Management Systems”,
Sang, H. and Rasikan, D. (2014): “Design and Analysis of A Secure Two-Phase Locking
Protocol”.
Shapour, J. Fariborz, M. and Mehdi, A., (2007): “Improving Strict 2 Phase Locking (S2PL) in
Transactions Concurrency Control”.
Ugur, H. and Asuman, D. (2010): “Concurrency Control in Distributed Databases Through Time
Intervals and Short-Term Locks”.
Wu, S. and Pan, D. (2009): “FUTURE TREND ON CONCURRENCY CONTROL IN
DISTRIBUTED DATABASES SYSTEM DESIGN“.

13

You might also like