UNIT-4: Transac Tions
UNIT-4: Transac Tions
TRANSAC
TIONS
Transaction Concept
Transaction State
Concurrent Executions
OUTLIN Serializability
E
Recoverability
Implementation of Isolation
CONCEP •
•
3.
4.
write(A)
read(B)
T •
•
5.
6.
B := B + 50
write(B)
REQUIRE 3.
4.
write(A)
read(B)
D 5.
6.
B := B + 50
write(B)
TRANSA
Failure could be due to software or hardware
The system should ensure that updates of a partially
executed transaction are not reflected in the database
CTION Durability requirement — once the user has been
notified that the transaction has completed (i.e., the transfer
of the $50 has taken place), the updates to the database by
the transaction must persist even if there are software or
hardware failures.
REQUIRED PROPERTIES
OF A TRANSACTION
(CONT.)
Consistency requirement in above example:
The sum of A and B is unchanged by the execution of the transaction
In general, consistency requirements include
Explicitly specified integrity constraints such as primary keys and
foreign keys
Implicit integrity constraints
e.g., sum of balances of all accounts, minus sum of loan amounts
must equal value of cash-in-hand
A transaction, when starting to execute, must see a consistent database.
During transaction execution the database may be temporarily
inconsistent.
When the transaction completes successfully the database must be
consistent
Erroneous transaction logic can lead to inconsistency
Isolation requirement — if between steps 3
and 6 (of the fund transfer transaction) , another
transaction T2 is allowed to access the partially
updated database, it will see an inconsistent
database (the sum A + B will be less than it
REQUIRE should be).
D T1 T2
1. read(A)
PROPERT 2.
3.
A := A – 50
write(A)
IES OF A 4.
read(A), read(B), print(A+B)
read(B)
TRANSA 5.
6.
B := B + 50
write(B
RRENT disk
• Reduced average response time for
Schedule 3 Schedule 6
Example of a schedule that is not conflict
serializable:
CONFLICT
SERIALIZA
BILITY
(CONT.)
We are unable to swap instructions in the above
schedule to obtain either the serial schedule
< T3, T4 >, or the serial schedule < T4, T3 >.
PRECEDEN
CE GRAPH
Consider some schedule of a
set of transactions T1, T2, ...,
Tn
Precedence graph — a
direct graph where the
vertices are the transactions
(names).
We draw an arc from Ti to Tj
if the two transaction
conflict, and Ti accessed the
data item on which the
conflict arose earlier.
We may label the arc by the
item that was accessed.
Example
TESTING FOR
CONFLICT
SERIALIZABIL
ITY
A schedule is conflict serializable if and
only if its precedence graph is acyclic.
CASCAD
ING
ROLLBA
CKS
If T10 fails, T11 and T12 must also be rolled back.
Can lead to the undoing of a significant amount of work
Cascadeless schedules — 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 read operation
of Tj.
Every cascadeless schedule is also recoverable
CASCAD It is desirable to restrict the schedules to those that
ELESS are cascadeless
LES
A database must provide a mechanism that will
ensure that all possible schedules are both:
• Conflict serializable.
• Recoverable and preferably cascadeless
A policy in which only one transaction can
execute at a time generates serial schedules, but
CONCUR provides a poor degree of concurrency
DEFINITI
Commit work commits current transaction and
begins a new one.
Rollback work causes current transaction to abort.
ON IN In almost all database systems, by default,
SQL every SQL statement also commits
implicitly if it executes successfully
Implicit commit can be turned off by a database
directive
E.g. in JDBC, connection.setAutoCommit(false);
OTHER
NOTIONS OF
SERIALIZABILIT
Y
Let S and S´ be two schedules with the same
set of transactions. S and S´ are view
equivalent if the following three conditions
are met, for each data item Q,
1. If in schedule S, transaction Ti reads
the initial value of Q, then in schedule
S’ also transaction Ti must read the
initial value of Q.
VIEW 2. If in schedule S transaction Ti executes
read(Q), and that value was produced
SERIALIZA by transaction Tj (if any), then in
schedule S’ also transaction Ti must
BILITY read the value of Q that was produced
by the same write(Q) operation of
transaction Tj .
3. The transaction (if any) that performs
the final write(Q) operation in
schedule S must also perform the final
write(Q) operation in schedule S’.
VIEW
SERIALIZA
BILITY
(CONT.)