Unit 4_1
Unit 4_1
UNIT -IV
UNIT - IV
Transaction
• Active
• Partially Committed
• Committed
• Failed
• Aborted
State diagram of a Transaction
Transaction States
• Atomicity
• Consistency
• Isolation
• Durability
ACID Properties
■ Atomicity
Either all operations of the transaction are reflected
properly in the database, or none are.
■ Consistency
Execution of a transaction in isolation(i.e. with no other
transaction executing concurrently) preserves the
consistency
of the database.
ACID Properties
■ Isolation
Even though multiple transactions may execute
concurrently, the system guarantees that, for every pair of
transactions Ti and Tj, it appears to Ti that either Tj finished
execution before Ti started or Tj started execution after Ti
finished.
■ Durability
After a transaction completes successfully, the changes it
has made to the database persist, even if there are system
failures.
Operations
• read(X)
• write(X)
Atomicity:
• Suppose that, just before the execution of transaction Ti, the
values of accounts A and B are $1000 and $2000,
respectively. Now suppose that, during the execution of
transaction Ti, a failure occurs that prevents Ti from
completing its execution successfully.
• Further, suppose that the failure happened after the write(A)
operation but before the write(B) operation.
Transaction model
Atomicity:
• In this case, the values of accounts A and B reflected in the
database are $950 and $2000.
• The system destroyed $50 as a result of this failure. In
particular, we note that the sum A + B is no longer
preserved.
Isolation:
Even if the consistency and atomicity properties are ensured for each
transaction, if several transactions are executed concurrently, their
operations may interleave in some undesirable way, resulting in an
inconsistent state.
A way to avoid the problem of concurrently executing transactions is
to execute transactions serially—that is, one after the other.
Transaction Recovery
• COMMIT
Committing a transaction means making
permanent changes
performed by the SQL statements within
the transaction.
• Write-ahead log rule
write-ahead logging (WAL) is a technique
for providing
atomicity and durability in database systems. The
Transaction Recovery
• SAVEPOINT
A savepoint is a way of implementing sub-
transactions (also known as nested transactions)
within a relational database management system by
indicating a point within a transaction that can be
"rolled back to" without affecting any work done in
the transaction before the savepoint was created.
• ROLLBACK
It is used to undo all the changes made on the
current transaction
Concurrency
Transaction1 Transaction 2
Concurrency Control
However, in the
interleaving of
operations ,it is X =
84
Concurrency Control
T1 Fails
Concurrency Control
2. The Temporary Update or Dirty Read Problem
• T1 updates item X and then fails before completion, so the system
must roll back X to its original value.
• Before it can do so, however, transaction T2 reads the temporary
value of X, which will not be recorded permanently in the database
because of the failure of T1.
• The value of item X that is read by T2 is called dirty data because it
has been created by a transaction that has not completed and
committed yet; hence, this problem is also known as the dirty read
problem.
Concurrency Control
3. The Incorrect Summary Problem
If one transaction is calculating an aggregate
summary function on a number of database items while
other transactions are updating some of these items, the
aggregate function may calculate some values before they
are updated and others after they are updated.
Concurrency Control
T1 T2
Read(x)
Read(x)
Write(x)
Read(x)
SCHEDULE
Serial Schedule
In this schedule,
• The write(A) instruction of T1 conflicts with the read(A)
instruction of T2.
• However, the write(A) instruction of T2 does not conflict
with the read(B) instruction of T1 because the two
instructions access different data items.
CONFLICT SERIALIZABILITY
• Since the write(A) instruction of T2 in schedule S does not
conflict with the read(B) instruction of T1, we can swap
these instructions to generate an equivalent schedule
CONFLICT SERIALIZABILITY
Final Schedule S’
CONFLICT SERIALIZABILITY
Edge : T1 → T2
Precedence graph :
Edge : T1 → T2
T2 → T1
Precedence graph :