Transaction Processing Class PDF
Transaction Processing Class PDF
• So, there is a need to manage these two operations in the concurrent execution of
the transactions as if these operations are not performed in an interleaved manner,
and the data may become inconsistent.
• So, the following problems occur with the Concurrent Execution of the operations:
• As the name suggests, when some dirty data is read from the database it is
known as the Dirty Read.
• More formally, when a transaction (say X) is reading a row that has been
modified by another transaction (say Y) but not committed yet leads to the
condition of Dirty Read.
Syntax error: It occurs where the DBMS itself terminates an active transaction
because the database system is not able to execute it. For example, The system
aborts an active transaction, in case of deadlock or resource unavailability.
3. Disk Failure
It occurs where hard-disk drives or storage drives used to fail
frequently. It was a common problem in the early days of technology
evolution.
Disk failure occurs due to the formation of bad sectors, disk head
crash, and unreachability to the disk or any other failure, which destroy
all or part of disk storage.
Department of Computer Science, GFGC, Malur Prepared by Dr Hamela K 16
Transaction States in DBMS
States through which a transaction goes during its lifetime. These are the states which
tell about the current state of the Transaction and also tell how we will further do the
processing in the transactions. These states govern the rules which decide the fate of
the transaction whether it will commit or abort.
Active State –
When the instructions of the transaction are running then the transaction is in
active state. If all the ‘read and write’ operations are performed without any error
then it goes to the “partially committed state”; if any instruction fails, it goes to the
“failed state”.
Partially Committed –
After completion of all the read and write operation the changes are made in main
memory or local buffer. If the changes are made permanent on the DataBase then
the state will change to “committed state” and in case of failure it will go to the
“failed state”.
Failed State –
When any instruction of the transaction fails, it goes to the “failed state” or if failure
occurs in making a permanent change of data on Data Base.
Department of Computer Science, GFGC, Malur Prepared by Dr Hamela K 18
Aborted State –
After having any type of failure the transaction goes from “failed state” to
“aborted state” and since in previous states, the changes are only made to local
buffer or main memory and hence these changes are deleted or rolled-back.
Committed State –
It is the state when the changes are made permanent on the Data Base and the
transaction is complete and therefore terminated in the “terminated state”.
Terminated State –
If there isn’t any roll-back or the transaction comes from the “committed state”,
then the system is consistent and ready for new transaction and the old
transaction is terminated.
Property of Transaction
• Atomicity
• Consistency
• Isolation
• Durability
Abort: If a transaction aborts then all the changes made are not
visible.
In DBMS Lock based Protocols, there are two modes for locking and unlocking data items Shared Lock
(lock-S) and Exclusive Lock (lock-X). Let's go through the two types of locks in detail:
Shared Lock
• Shared Locks, which are often denoted as lock-S(), is defined
as locks that provide Read-Only access to the information
associated with them.
• Whenever a shared lock is used on a database, it can be read
by several users, but these users who are reading the
information or the data items will not have permission to edit it
or make any changes to the data items.
• A shared lock, also known as a read lock, is solely used to read
data objects. Read integrity is supported via shared locks.
• Shared locks can also be used to prevent records from being
updated.
• S-lock is requested via the Lock-S instruction.
*Source: Scaler Topics
Department of Computer Science, GFGC, Malur Prepared by Dr Hamela K 28
Exclusive Lock
•Exclusive Lock allows the data item to be read as
well as written. This is a one-time use mode that
can't be utilized on the exact data item twice. To
obtain X-lock, the user needs to make use of
the lock-x instruction. After finishing the 'write'
step, transactions can unlock the data item.
•By imposing an X lock on a transaction that
needs to update a person's account balance, for
example, you can allow it to proceed. As a result
of the exclusive lock, the second transaction is
unable to read or write.
•The other name for an exclusive lock is write
lock.
•At any given time, the exclusive locks can only be
owned by one transaction.
Growing Phase: In this phase, we can acquire new locks on data items, but
none of these locks can be released.
Shrinking Phase: In this phase, the existing locks can be released, but no
new locks can be obtained.
Efficient: The technique is efficient and scalable, as it does not require locking and can handle a large number
of transactions.
No Deadlocks: Since there are no locks involved, there is no possibility of deadlocks occurring.
Improved Performance: By allowing transactions to execute concurrently, the overall performance of the
database system can be improved.
Disadvantages:
Limited Granularity: The granularity of timestamp-based concurrency control is limited to the precision of the
timestamp. This can lead to situations where transactions are unnecessarily blocked, even if they do not
conflict with each other.
Timestamp Ordering: In order to ensure that transactions are executed in the correct order, the timestamps
need to be carefully managed. If not managed properly, it can lead to inconsistencies in the database.
Timestamp Synchronization: Timestamp-based concurrency control requires that all transactions have
synchronized clocks. If the clocks are not synchronized, it can lead to incorrect ordering of transactions.
Timestamp Allocation:
Department of ComputerAllocating
Science, GFGC, unique
Malur timestamps for
Prepared by Dr each
Hamela K transaction can be challenging, especially in 37
distributed systems where transactions may be initiated at different locations.
Deadlock in DBMS
A deadlock is a condition where two or more transactions are waiting
indefinitely for one another to give up locks. Deadlock is said to be one of the
most feared complications in DBMS as no task ever gets finished and is in
waiting state forever.
Deadlock in DBMS
• Every process need some resource for its execution and these resources are granted in
sequential order
• First the process request some resource.
• OS grants the resource to the process if it is available or else it places the request in the wait
queue.
• The process uses it and releases on the completion so that it can be granted to another
process
• Deadlock is a situation where two or more transactions are waiting indefinitely for each other
to give up their locks.
No pre-emption
The process which once scheduled will be executed till the completion. No other
process can be scheduled by the scheduler meanwhile.
Circular Wait
All the processes must be waiting for the resources in a cyclic manner so that the
last process is waiting for the resource which is being held by the first process.
· Resource leak.
Suppose there are 3 transactions namely T1, T2, and T3 in a database that are trying to acquire a lock on
data item ‘ I ‘.
The scheduler grants the lock to T1(maybe due to some priority), and the other two transactions are
waiting for the lock.
Another transaction T4 also come over and request to lock on data item I. Now, this time the scheduler
grants lock to T4, and T2, T3 has to wait again.
In this way, if new transactions keep on requesting the lock, T2 and T3 may have to wait for an indefinite
period of time, which leads to Starvation.
1. Increasing Priority –
Starvation occurs when a transaction has to wait for an indefinite time, In In this situation, we can increase the
priority of that particular transaction/s. But the drawback with this solution is that it may happen that the
other transaction may have to wait longer until the highest priority transaction comes and proceeds.