ss zg518-l11.ppt
Post on 04-Jun-2018
235 Views
Preview:
TRANSCRIPT
-
8/14/2019 SS ZG518-L11.ppt
1/28
BITSPilaniHyderabad Campus
Dr.R.GururajCS&IS Dept.
Database Design & Applications
(SS ZG 518)
-
8/14/2019 SS ZG518-L11.ppt
2/28
BITS Pilani, Hyderabad Campus
Lecture Session-11
Transaction Processing(Ch.17)
1 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
Content
What is Transaction Model
Significance of Transaction Model
States of a transaction
ACID Properties
Concurrent Transactions
Transaction Schedule
Serial and Concurrent Schedules
Need for Concurrency ControlConflicting Operations
Conflict Equivalent Schedule & Test for Conflict
Serializability
View Equivalent Schedule & View Serializability
-
8/14/2019 SS ZG518-L11.ppt
3/28
BITS Pilani, Hyderabad Campus
Atransactionis an atomic unit of work that iseither completed in its entirety or not done atall.
For recovery purposes, the system needs to keep
track of when the transaction starts, terminates,and commits or aborts.
Transaction Model
2 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
4/28
BITS Pilani, Hyderabad Campus
A transactionis a program unit that access and update several dataitems.
Read ( ) and Write ( ) are the basic operations.
Data prior toexecution of
transaction
Exe. of
transaction. Datamay be in
inconsistent state
After Execution
of the transaction
Consistent
state
Difficulties whenfailure occur in
the process
Goes to next
consistent state
Hence, as a result of failure, state of the system will not reflect the state of
the real world that the database is supposed to capture.
We call that state as inconsistent state.
It is important to define transactions such that they preserve consistency.
3 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
5/28
BITS Pilani, Hyderabad Campus
-
8/14/2019 SS ZG518-L11.ppt
6/28
BITS Pilani, Hyderabad Campus
-
8/14/2019 SS ZG518-L11.ppt
7/28BITS Pilani, Hyderabad Campus
Transaction should possess the following properties called as ACID
properties.
A tomicity:A transaction is an atomic unit of processing. It is either
performed in its entirety or not performed at all.
Consistency Preservation:The successful execution of a transaction
takes the database from one consistent state to another.
Isolation:A transaction should be executed as if it is not interfered by
any other transaction.
Durability:The changes applied to the data by a transaction must be
permanent.
ACID Properties of a Transaction
4 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
8/28BITS Pilani, Hyderabad Campus
Active State:Initial state when a transaction starts.
Partially committed State:This state is reached when the last
statement is executed and the outcome is not written to the DB.
Failed State: After discovering that the normal execution cannot be
continued a transaction is aborted and reaches failed state.
Comitted State:Is reached after successful completion of the
transaction.
Terminated State:Is reached after failure or success of the transaction.
Transaction States
5 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
9/28BITS Pilani, Hyderabad Campus6 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
10/28BITS Pilani, Hyderabad Campus
The descriptions that specify the execution sequence of instructions in
a set of transactions are called as schedules.
Hence schedule can describe the execution sequence of more than
one transaction.
T1 T2
T1and T2are transaction
Read (A) Reads data item
A
Write (B) Writes the data
item B
Read (A)
A = A + 50
Read (B)
B = B + A
Write (B)
Read (B)
B = B + 75
Write (B)
Here, in the above schedule the
transactions T1& T2are executed in a
serial manner i.e., first all the
instructions of the transaction T1are
executed, and then the instructions of
T2are executed. Hence the above
schedule is known as serial schedule.
Transaction Schedule
7 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
11/28BITS Pilani, Hyderabad Campus
In a serial schedule, instructions belonging to one single transactionappear together.
A serial schedule does not exploit the concurrency. Hence, it is less
efficient.
If the transactions are executed concurrently then the resources can be
utilized more efficiently hence more throughput is achieved.
8 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
12/28BITS Pilani, Hyderabad Campus
A serial schedulealways results in correct database state that reflectthe real world situations.
When the instructions of different transactions of a schedule are
executed in an interleaved manner use call such schedules are called
concurrent schedules.
This kind of concurrent schedules may result in incorrect database
state.
9 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
13/28BITS Pilani, Hyderabad Campus10 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
T1 T2
Read (A)A = A + 50
Write (B)
Read (A)
A = A + 100
Write (A)
Time
-
8/14/2019 SS ZG518-L11.ppt
14/28BITS Pilani, Hyderabad Campus
Hence it is evident that if we swap non-conflicting operations of a
concurrent schedule, it will not affect the final result.
Look at the following example.
T1 T2 T1 T2 T1 T2
R(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
W(B)
(S1) (S2) (S3)
Concurrent schedule
with T1& T2
accessing A, B (data
item)
Swap W(A) in T2with
R(B) in T1(because
they are non
conflicting)
Swap R(A) of T2with
R(B) of T1and W(A)
in T2with W(B) in T1
(Since non
conflicting)
11 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
15/28BITS Pilani, Hyderabad Campus
T1 T2
Now, the final schedule is a serial scheduleR(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
W(B)
(S4)
Swap R(A) of T2
with
W(B) of T1
12 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
16/28BITS Pilani, Hyderabad Campus
If a schedule Scan be transformed into a schedule Sby
a series of swaps of non-conflicting instructions, we say
that Sand Sare conflict equivalent.
Further, we say that a schedule Sis conflict serializableif
it is conflict equivalent to a serial schedule.
In our example S4in the above example is a serial
schedule and is conflict equivalent to S1. Hence S1is aconflict serializable schedule.
Conflict Equivalent Schedules
13 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
17/28BITS Pilani, Hyderabad Campus
T1 T2 In this schedule we cannot perform any swap between instructions of T1and T2. Hence it
is not conflict serializableR()
W()
W()
14 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
18/28BITS Pilani, Hyderabad Campus
Test for Conflict Serializability
Let S be a schedule.
We construct a precedence graph.
Each transaction participating in the schedule will become a
vertex.
The set of edges consist of all edges TiTjfor which one of
the following three conditions hold-
Tiexecutes W(Q) before Tjexecutes R(Q)
Tiexecutes R(Q) before Tjexecutes W(Q)
Tiexecutes W(Q) before Tj executes W(Q)
15 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
19/28BITS Pilani, Hyderabad Campus
T0 T1
Infact their schedule is non conflict serializableR(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
T0 T1
T1writes(A) after T0writes(A) hence we draw on edge from T0T1
T1
reads(B) before T0
write (B) hence we can draw an edge from T1
T0
At any moment of time, while developing the graph in the above
manner, if we see a cycle then the schedule is not conflict
serializable. If no cycles at the end, then it is conflict serializable.
Hence the above schedule is not serializable.16 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
20/28BITS Pilani, Hyderabad Campus
Now let us consider the following transaction which is conflict serializableand discussed earlier.
Now, let us draw a precedence graph for the above
schedule
To write A before T1reads A. hence we have T0
T1.
T0 T1
We have only one edge in this graph, and no
cycles. Hence it is conflict serializable.
T1 T2
R(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
W(B)
17 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
21/28BITS Pilani, Hyderabad Campus
Serial schedule:
A schedule S is serial if, for every transaction T
participating in the schedule, all the operations of
T are executed consecutively in the schedule.
Otherwise, the schedule is called nonserial
schedule.
Serializable schedule: A schedule S is serializable if it is equivalent to
some serial schedule of the same n transactions.
18 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
22/28BITS Pilani, Hyderabad Campus
Being serializable is not the same as being
serial
Being serializable implies that the schedule is a
correct schedule.
It will leave the database in a consistent state.
The interleaving is appropriate and will result in a
state as if the transactions were serially executed,yet will achieve efficiency due to concurrent
execution.
19 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
23/28
BITS Pilani, Hyderabad Campus
Ex: Look at the following schedule for the concurrenttransactions 1 and 2. The data items are X and Y.
Schedule : r2(X); w2(X); r1(X); r2(Y); w1(X); w2(Y);
w1(X); r1(Y); w1(Y); w2(A); r1(A);
Here,r1(X) - means that the transaction-1 reads data item X
w2(Y) - means that the transaction-2 reads data item Y
For the above schedules draw the precedence graph and find
if it is conflict serializable.
20 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
24/28
BITS Pilani, Hyderabad Campus21 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
25/28
BITS Pilani, Hyderabad Campus
Ex: Look at the following schedules for the concurrenttransactions 1 and 2. The data items are A and B.
Schedu le 1 : r1(A); r1(B); r2(A); w1(B); w2(A); w1(B);
R2(B); r1(B); w2(A); r1(A);
Schedu le 2 : r1(B); r1(A); r2(A); w1(B); w2(A); R2(A);
w1(B); r2(B); R1(B); w2(A);
Here, r1(A); - means that the transaction-1 reads data
item Aw2(B); - means that the transaction-2 reads data
item B
For each of the above schedules draw the precedence
graph and find if they are conflict serializable.
22 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
26/28
BITS Pilani, Hyderabad Campus23 12/09/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
-
8/14/2019 SS ZG518-L11.ppt
27/28
BITS Pilani, Hyderabad Campus
-
8/14/2019 SS ZG518-L11.ppt
28/28
Summary
What is a transaction
Basic database operations performed by a transaction
Properties of a transaction
States of a transaction Transaction execution and the database consistency
What are concurrent Transactions
What are Serial and Concurrent Schedules
Why Concurrency Control needed in DBMS
Conflict Equivalent Schedule and its importance
Test for Conflict Serializability
top related