0% found this document useful (0 votes)
5 views

Lecture_3 database

The document discusses concurrency control in multiuser database systems, highlighting the importance of maintaining data integrity and isolation during simultaneous transactions. It outlines various concurrency problems such as lost updates, uncommitted data, and inconsistent retrievals, and explains the concept of serializability in transaction scheduling. Additionally, it describes the role of schedulers in managing transaction execution to ensure serializability through techniques like locking and time stamping.

Uploaded by

goliemate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lecture_3 database

The document discusses concurrency control in multiuser database systems, highlighting the importance of maintaining data integrity and isolation during simultaneous transactions. It outlines various concurrency problems such as lost updates, uncommitted data, and inconsistent retrievals, and explains the concept of serializability in transaction scheduling. Additionally, it describes the role of schedulers in managing transaction execution to ensure serializability through techniques like locking and time stamping.

Uploaded by

goliemate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Concurrency Control and

Serializabilty

Ali El-Bastawissy 1
Introduction to Multiuser DB
System
 Single-User System:
At most one user at a time can use the system.
 Multiuser System:
Many users can access the system concurrently.
 Concurrency
Interleaved processing:
○ Concurrent execution of processes is interleaved in
a single CPU
Parallel processing:
○ Processes are concurrently executed in multiple
CPUs.
MULTIPROGRAMMIN
G/
TIME-SHARING PROCESS OUT

SYSTEMS
RUN

WAI I/O
SERVICES
T
IN
PROCESS

Ali El-Bastawissy 3
Concurrency
 Control
Problem
in multi-user environment; simultaneous
access to database can result in interference
and data loss
Solution: CONCURRENCY CONTROL
The process of managing simultaneous
operations against a database so that data
isolation is maintained

Ali El-Bastawissy 4
Concurrency problems
 The objective of concurrency control is to
ensure the serializability of transactions in a
multi-user database environment.
 Simultaneous execution of transactions over a
shared database can create several data
integrity and consistency problems:
 Lost Updates.
 Uncommitted Data.
 Inconsistent retrievals.

Ali El-Bastawissy 5
Lost Updates

Zaki his wife


Lost Updates
 Using Product Table: Product’s quantity on Hand
(PROD_QOH)
 Two concurrent transactions update
PROD_QOH:

 See Table 1 for the serial execution under normal


circumstances.
 See Table 2 for the lost update problems
resulting from the execution of the second
transaction before the first transaction is
committed.
Ali El-Bastawissy 7
Lost Updates

Ali El-Bastawissy 8
Uncommitted Data
 Data are not committed when two transactions
T1 and T2 are executed concurrently and the first
transaction is rolled back after the second
transaction has already accessed the
uncommitted data - thus violating the isolation
property of the transaction.

Ali El-Bastawissy 9
Uncommitted
Data
Correct
Execution Of
Two
Transactions

An
Uncommitted
Data Problem

Ali El-Bastawissy 10
Inconsistent Retrieval
 Inconsistent retrievals occur when a transaction
calculates some summary (aggregate) functions
over a set of data while other transactions are
updating the data.
 Example:
 T1 calculates the total quantity on hand of the
products stored in the PRODUCT table.
 At the same time, T2 updates the quantity on hand
(PROD_QOH) for two of the PRODUCT table’s
products.

Ali El-Bastawissy 11
Inconsistent Retrieval

Ali El-Bastawissy 12
Inconsistent Retrieval

Ali El-Bastawissy 13
Inconsistent Retrieval

Ali El-Bastawissy 14
Why Concurrency Control is needed?
 The Lost Update Problem
 This occurs when two transactions that access the same
database items have their operations interleaved in a way
that makes the value of some database item incorrect.
 The Temporary Update (or Dirty Read) Problem
 This occurs when one transaction updates a database
item and then the transaction fails for some reason (see
Section 21.1.4).
 The updated item is accessed by another transaction before
it is changed back to its original value.
 The Incorrect Summary Problem
 If one transaction is calculating an aggregate summary
function on a number of records while other transactions
are updating some of these records, the aggregate function
may calculate some values before they are updated and
others after they are updated.
Conflict

Operations
Two operations conflict if they belong to different
transactions, they access the same data item and
at least one of them is a write operation.

Ali El-Bastawissy 16
SCHEDULES
 Schedule S consists of a sequence of the operations from a
set of concurrently executed transactions.
 Example:
S = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
 Serial Schedule is a schedule where the operations of each
transaction are executed without any interleaved
operations from other transactions
Example:
S = r1(A)w1(A)r1(B)w1(B)r2(A)w2(A)r2(B)w2(B)
 Nonserial Schedule is a schedule where the operations
from a set of concurrent transactions are interleaved
Example:
S = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)

Ali El-Bastawissy 17
Scheduling Example

E=
r2(Z),r2(Y),w2(Y),r3(Y),r3(Z),r1(X),w1(x),W3(Y),W3(Z),r2(X)r1(Y),w1(Y),w2(X)

Ali El-Bastawissy 18
Scheduling Note
 A schedule (or history) S of n transactions T1, T2,
…, Tn:
 It is an ordering of the operations of the transactions
subject to the constraint that, for each transaction Ti that
participates in S, the operations of T1 in S must appear
in the same order in which they occur in T1.
 Note, however, that operations from other transactions
Tj can be interleaved with the operations of Ti in S.

Ali El-Bastawissy 19
Serializability
 Is to find nonserial schedules that allow
transactions to execute concurrently
without interfering with one another.

 Serializable Schedule: a nonserial


schedule is serializable when a set of
transactions executes concurrently and
produces the same results as some serial
execution.

Ali El-Bastawissy 20
Schedules

Characteristics
A schedule is serializable if it is
equivalent
to some serial schedule.
 Two schedules are Result equivalent if the
database would reach the same state after
each schedule executes.
 Two schedules are Conflict equivalent
if the ordering of any two conflicting
operations appear in the same order in
both schedules.

Ali El-Bastawissy 21
serialization graph
 To construct the serialization graph for a schedule:
1.Create a node for each transaction in the schedule.
2.Draw a directed arc from Ti to Tj if Tj reads the results of a
write operation in Ti
3. Draw a directed arc from Ti to Tj if Tj writes a data item
after
it was read by Ti
4.Draw a directed arc from Ti to Tj if Tj writes a data item after
Ti writes to the same item.
5.If we can find a directed cycle among the directed arcs, then
a conflict exists and we can not safely execute the
transactions concurrently.
6.To serialize the schedule, reorder the transactions (possibly
by aborting one) to break the cycles.

Ali El-Bastawissy 22
Serialization Graph

Example
T1 executes: Ra Wa Rb Wb C
 T2 executes: Ra Wa Rc Wc C

 Conflicts: T1Ra with T2Wa


T1Wa with T2Ra
T1Wa with
T2Wa
 Serial Schedule:

T1Ra T1Wa T1Rb T1Wb T1C


T2Ra T2Wa T2Rc T2Wc T2C
 Conflict Serializable
Schedule: Ali El-Bastawissy 23
cont’d
 Serialization Graph
1) Draw nodes for T1 and T2
2) Draw an arc from T1 to T2 since T2 reads a after T1 writes
a
3) Draw an arc from T1 to T2 since T2 writes a after T1 reads
a
4) Draw an arc from T1 to T2 since T2 writes a after T1 writes
a

No Directed Cycle

Ali El-Bastawissy 24
Serialization graph
Example
T1: Ra Wa Rb Wb2
Rc Wc Rd Wd Re We C
T2: Re We Ra Wa Rb Wb Rh Wh C
T3: Rf Wf Rb Wb C
Given Schedule S:
T3Rf T2Re T2We T2Ra T2Wa T3Wf T1Ra T2Rb
T2Wb T1Wa T1Rb T1Wb T3Rb T1Rc T1Wc
T2Rh T1Rd T3Wb T1Wd T1Re T2Wh T1We T3C
T2C T1C
Is the given schedule S conflict serializable?

Ali El-Bastawissy 25
cont’d
Step 1, write down the Step 2, construct the Serialization Graph
conflicting operations in for schedule S
schedule S: Showing all conflicts:
T2Re before T1We
T2We before T1We
T2We before T1Re
T2Ra before T1Wa
T2Wa before T1Wa
T2Wa before T1Ra
T2Rb before T3Wb
T2Wb before T3Wb
T2Wb before T3Rb
T1Rb before T3Wb
T1Wb before T3Wb
T1Wb before T3Rb
T2Wb before T1Rb
T2Wb before T1Wb
T2Rb before T1Wb Ali El-Bastawissy 26
cont’d

Showing just conflicting


items (same thing):

 Conclusion:
There are no directed cycles in this graph.
Therefore the given schedule S is conflict
serializable
Ali El-Bastawissy 27
Example
2b
 Suppose instead the given Schedule X is
the following:
X: T3Rf T2Re T2We T2Ra T2Wa T3Wf T1Ra
T2Rb T2Wb T1Wa T1Rb T3Rb T1Wb T1Rc
T1Wc T2Rh T1Rd T3Wb T3C T1Wd T1Re
2Wh T2C T1We T1C

Ali El-Bastawissy 28
Step 1, write down the cont’d
conflicting operations
in Schedule X: Step 2, construct the Serialization Graph
T2Re before T1We for Schedule X:
T2We before T1We
T2We before T1Re
T2Ra before T1Wa
T2Wa before T1Wa
T2Wa before T1Ra
T2Rb before T3Wb
T2Wb before T3Wb
T2Wb before T3Rb
T1Rb before T3Wb
T1Wb before T3Wb
T3Rb before T1Wb Conclusion:
T2Wb before T1Rb There is a directed cycle between T1 and T3.
T2Wb before T1Wb Therefore, the given schedule X is NOT
conflict serializable.
T2Rb before T1Wb

Ali El-Bastawissy 29
Test the Conflict Serializability
of E

Ali El-Bastawissy 30
Test the Conflict Serialisability
of F

Ali El-Bastawissy 31
The SCHEDULER
 The scheduler establishes the order in which
the operations within concurrent transactions
are executed.
 The scheduler interleaves the execution of
database operations to ensure
serializability.
 To determine the appropriate order, the
scheduler uses concurrency control techniques,
such as locking or time stamping methods.
 The scheduler also makes sure that the
computer’s CPU is used efficiently.

Ali El-Bastawissy 32
Assignment

Please write everything datawarehouse.

33

You might also like