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

Transactions

Transactions group related tasks into logical units and must maintain ACID properties. Serializability ensures consistency when transactions run concurrently. Conflict serializability tests schedules by constructing a precedence graph - if acyclic, the schedule is conflict serializable. View serializability requires schedules be view equivalent to a serial schedule. Recoverable and cascadeless schedules support recovery by committing writers before readers.

Uploaded by

steffinamorin L
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)
26 views

Transactions

Transactions group related tasks into logical units and must maintain ACID properties. Serializability ensures consistency when transactions run concurrently. Conflict serializability tests schedules by constructing a precedence graph - if acyclic, the schedule is conflict serializable. View serializability requires schedules be view equivalent to a serial schedule. Recoverable and cascadeless schedules support recovery by committing writers before readers.

Uploaded by

steffinamorin L
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/ 30

UNIT III

TRANSACTIONS
Transaction
A transaction can be defined as a group of tasks that form a single
logical unit.

For example:
To withdraw Rs. 100 from an account.

In a database, each transaction should maintain ACID property to


meet the consistency and integrity of the database.
ACID Properties

Atomicity

Consistency

Isolation

Durability
Transaction States
Schedules
• Schedule is an order of multiple transactions executing in
concurrent environment.
Serial Schedule
Non Serial Schedule
Serializability
• When multiple transactions run concurrently, then it may lead to
inconsistency of data (i.e. change in the resultant value of data from
different transactions).
• Serializability is a concept that helps to identify which non serial
schedule and find the transaction equivalent to serial schedule.
Two types of Serializabilities

• Conflict serializability

• View serializability
Conflict Serializability
• Suppose T1 and T2 are two transactions and I1 and I2 are the
instructions in T1 and T2 respectively.
• Then these two transactions are said to be conflict
Serializable, if both the instruction access the data item d, and
at least one of the instruction is write operation.
Conflict - Three conditions
There should be different transactions
The operations must be performed on same data items
One of the operation must be the Write(W) operation

We can test a given schedule for conflict serializability by


constructing a precedence graph for the schedule, and by
searching for absence of cycles in the graph.
• Precedence graph is a directed graph, consisting of G=(V,E) where V is
set of vertices and E is set of edges.
• The set of vertices consists of all the transactions participating in the
schedule.
• The set of edges consists of all edges Ti →Tj for which one of three
conditions holds:

1. Ti executes write(Q) before Tj executes read(Q).


2. Ti executes read(Q) before Tj executes write(Q).
3. Ti executes write(Q) before Tj executes write(Q).
Precedence graph
• A serializability order of the transactions can be obtained by finding a
linear order consistent with the partial order of the precedence
graph. This process is called topological sorting.
Testing for serializability
• To test the conflict serializability we can draw a
graph G=(V,E)

where V = vertices which represent the number of transactions.


E = edges for conflicting pairs.
Step 1 :

Create a node for each transaction.

Step 2 :

Find the conflicting pairs(RW, WR, WW) on the same


variable(or data item) by different transactions.
Step 3:

Draw edge for the given schedule. Consider following cases

1. Ti executes write(Q) before Tj executes read(Q), then draw edge from Ti to Tj.

2. Ti executes read(Q) before Tj executes write(Q) , then draw edge from Ti to Tj

3. Ti executes write(Q) before Tj executes write(Q), , then draw edge from Ti to Tj

Step 4 :

Now, if precedence graph is cyclic then it is a non conflict serializable schedule and if
the precedence graph is acyclic then it is conflict serializable schedule.
View Serializability
• If a given schedule is found to be view equivalent to some serial
schedule, then it is called as a view serializable schedule.

• View Equivalent Schedule : Consider two schedules S1 and S2


consisting of transactions T1 and T2 respectively, then schedules S1
and S2 are said to be view equivalent schedule if it satisfies following
three conditions :

1. If transaction T1 reads a data item A from the database initially in
schedule S1, then in schedule S2 also, T1 must perform the initial
read of the data item X from the database. This is same for all the
data items.

2. If data item A has been updated at last by transaction Ti in schedule


S1, then in schedule S2 also, the data item A must be updated at last by
transaction Ti.

3. If transaction Ti reads a data item that has been updated by the


transaction Tj in schedule S1, then in schedule S2 also, transaction Ti
must read the same data item that has been updated by transaction Tj. In
other words the Write-Read sequence must be same.
• Transactions perform write operation without having performed a
read operation. This is called blind writes.

• Blind writes appear in any view-serializable schedule that is not


conflict serializable.
Schedule - Techniques

• Recoverable Schedule

• Cascadeless Schedule
Recoverable Schedule

• A recoverable schedule is one where, for each pair of transactions


Ti and Tj such that Tj reads a data item previously written by Ti,
the commit operation of Ti appears before the commit operation of
Tj.
Eg:
• The dirty read is a situation in which one transaction reads the data
immediately after the write operation of previous transaction.
To make the schedule recoverable we will apply the rule that
 commit the independent transaction before any dependable transaction.
Cascadeless Schedule

• If in a schedule, a transaction is not allowed to read a data item


until the last transaction that has written that data item is
committed or aborted, then such a schedule is known as a
cascadeless schedule.

• The cascadeless schedule allows only committed Read


operation.
In above schedule at any point if the failure occurs due to commit operation before every Read operation of
each transaction, the schedule becomes recoverable and atomicity can be maintained.

You might also like