KEMBAR78
Understanding Transactions in Databases.pptx
Understandin
g
Transactions
in Databases
ACID Properties, States, and
Deadlock Prevention
Transaction
A transaction is an action that
updates the contents of the
database.
ACID PROPERTIES
Atomicity
Atomicity ensures that in a
transaction, every step of the
transaction must succeed, or no
step executed at all. And if
transaction faces system
failure, the system must
contain the ability to roll back.
Consistenc
y
Consistency observes that
database constraints must be
maintained so that the
database is consistent before
and after the transaction. It
refers to the correctness of a
database.
Isolation
Isolation ensures that multiple
transactions can occur
concurrently without leading to
inconsistency of database state.
Durability
Durability ensures that: after a
transaction successfully
completes, the system reserve
the changes even in the event
of system failure.
Transaction states
Active State
If a transaction is in execution,
then it is said to be in active
state. It does not matter which
step is in execution, until unless
the transaction is executed, it
remains in active state.
Partially
Committed
State
After the last instruction of
transaction has been executed,
it enters a partially committed
state.
Committed
State
After all the changes made by
the transaction have been
permanently saved on the
database system.
Failed State
If a transaction is executing and
a failure occurs the transaction
goes into failed state from the
active state.
Aborted
State
After the transaction has failed
and entered a failed state, all
the changes are made by. It
must be rolled back completely,
and it enters an aborted state.
Implementati
on of
Atomicity and
Durability on
Database
When a transaction starts, the
system creates a complete copy of
the original database. Then all the
actions of the transaction will be
applied on the new copy. If
transaction face failure the new copy
will be deleted and the original will
remain untouched, and if it succeeds
the old one will be deleted and the
new copy became original copy of
database.
Transaction states diagram
Shadow-copy
technique for
atomicity and
durability
Concurrent
Execution
in
Transaction
Transaction-processing systems usually allow
multiple transactions to run concurrently
where any number of users can use the same
database at the same time. There are two
good reasons for allowing competition:
• Improved throughput and resource
utilization- Use all the resources to get all
the transaction done and produce output
within each transaction idle time.
• Reduced waiting time- no matter what type
of transaction is waiting it executes all
transaction at a time to reduce waiting time
and complete them into an average time.
Deadlock
A deadlock is a situation
wherein two or more
transactions are waiting for
each other to be finished but
none of the transactions is
willing to give up the resources
that other transactions need. In
this situation, no transactions
ever get finished and are in
waiting-state forever.
Deadlock
Handling
There are two ways for
deadlock handling, namely −
• Deadlock prevention.
• Deadlock detection and
removal.
Deadlock
Prevention
A deadlock can be prevented if
the resources are allocated in
such a way that deadlock never
occurs. The DBMS analyzes the
operations whether they can
create a deadlock situation or
not, if they do, that transaction
is never allowed to be executed.
Deadlock
Detection
and
Removal
We can detect deadlock through
a wait-for graph. The graph,
generated by the system itself,
represents each transaction
that is in execution with a node.
Deadlock detection algorithm
depends on the Frequency of
deadlock occurrence and
Number of transactions will be
affected by a deadlock.
Recovery
from
Deadlock
• Choice of Deadlock victim
• Rollback
• Problem of Starvation
Choice of
Deadlock
victim
To remove the deadlock
situation. One of the
transactions must be
terminated or rollbacked. The
selected one must be minimum
and the difference from
completion is maximum.
Rollback
Rollback ensure that the
changes made from the
transaction will not be available
anymore, and the database will
remain the same before the
following transaction occurs.
Problem of
Starvation
If a victim is chosen several
times, it cannot reach
completion. Then it will face
starvation.

Understanding Transactions in Databases.pptx

  • 1.
  • 2.
    Transaction A transaction isan action that updates the contents of the database.
  • 3.
  • 4.
    Atomicity Atomicity ensures thatin a transaction, every step of the transaction must succeed, or no step executed at all. And if transaction faces system failure, the system must contain the ability to roll back.
  • 5.
    Consistenc y Consistency observes that databaseconstraints must be maintained so that the database is consistent before and after the transaction. It refers to the correctness of a database.
  • 6.
    Isolation Isolation ensures thatmultiple transactions can occur concurrently without leading to inconsistency of database state.
  • 7.
    Durability Durability ensures that:after a transaction successfully completes, the system reserve the changes even in the event of system failure.
  • 8.
  • 9.
    Active State If atransaction is in execution, then it is said to be in active state. It does not matter which step is in execution, until unless the transaction is executed, it remains in active state.
  • 10.
    Partially Committed State After the lastinstruction of transaction has been executed, it enters a partially committed state.
  • 11.
    Committed State After all thechanges made by the transaction have been permanently saved on the database system.
  • 12.
    Failed State If atransaction is executing and a failure occurs the transaction goes into failed state from the active state.
  • 13.
    Aborted State After the transactionhas failed and entered a failed state, all the changes are made by. It must be rolled back completely, and it enters an aborted state.
  • 14.
    Implementati on of Atomicity and Durabilityon Database When a transaction starts, the system creates a complete copy of the original database. Then all the actions of the transaction will be applied on the new copy. If transaction face failure the new copy will be deleted and the original will remain untouched, and if it succeeds the old one will be deleted and the new copy became original copy of database.
  • 15.
  • 16.
  • 17.
    Concurrent Execution in Transaction Transaction-processing systems usuallyallow multiple transactions to run concurrently where any number of users can use the same database at the same time. There are two good reasons for allowing competition: • Improved throughput and resource utilization- Use all the resources to get all the transaction done and produce output within each transaction idle time. • Reduced waiting time- no matter what type of transaction is waiting it executes all transaction at a time to reduce waiting time and complete them into an average time.
  • 18.
    Deadlock A deadlock isa situation wherein two or more transactions are waiting for each other to be finished but none of the transactions is willing to give up the resources that other transactions need. In this situation, no transactions ever get finished and are in waiting-state forever.
  • 19.
    Deadlock Handling There are twoways for deadlock handling, namely − • Deadlock prevention. • Deadlock detection and removal.
  • 20.
    Deadlock Prevention A deadlock canbe prevented if the resources are allocated in such a way that deadlock never occurs. The DBMS analyzes the operations whether they can create a deadlock situation or not, if they do, that transaction is never allowed to be executed.
  • 21.
    Deadlock Detection and Removal We can detectdeadlock through a wait-for graph. The graph, generated by the system itself, represents each transaction that is in execution with a node. Deadlock detection algorithm depends on the Frequency of deadlock occurrence and Number of transactions will be affected by a deadlock.
  • 22.
    Recovery from Deadlock • Choice ofDeadlock victim • Rollback • Problem of Starvation
  • 23.
    Choice of Deadlock victim To removethe deadlock situation. One of the transactions must be terminated or rollbacked. The selected one must be minimum and the difference from completion is maximum.
  • 24.
    Rollback Rollback ensure thatthe changes made from the transaction will not be available anymore, and the database will remain the same before the following transaction occurs.
  • 25.
    Problem of Starvation If avictim is chosen several times, it cannot reach completion. Then it will face starvation.