Database Management System - CS3492 - Notes - Unit 3 - Transactions
Database Management System - CS3492 - Notes - Unit 3 - Transactions
enter. Environmental
Professional English Sciences
Professional and Sustainability -
English - I - - II - HS3252 Discrete GE3451
HS3152
Mathematics
Statistics and Theory of Computation
- MA3354
Numerical - CS3452
Matrices and
Methods - MA3251
Calculus Digital Principles
and Computer Artificial
- MA3151
Semester
Engineering Intelligence and
Semester
Organization
Semester
- CS3351
Engineering - CS3491
Physics - PH3151 - GE3251
Foundation of Data
Physics for Science - CS3352 Database Management
4th
System - CS3492
2nd
1st
Engineering Information
3rd
Chemistry Science
Data Structure -
- CY3151 - PH3256 CS3301 Algorithms - CS3401
Basic Electrical and
Electronics Object Oriented Introduction to
Problem Solving Engineering Operating
Programming -
and Python - BE3251 Systems - CS3451
CS3391
Programming -
GE3151 Programming in C
- CS3251
Computer
Networks - Object Oriented
CS3591 Software
Engineering
- CCS356 Human Values and
Compiler Design - Ethics - GE3791
CS3501 Embedded
Semester
Semester
Project Work /
Semester
and Cyber
Security - Open Elective 3 Intership
CB3491 Open
Open Elective 4
5th
7th
Distributed Elective-1
8th
Computing
6th
Management
- CS3551 Elective-3
Elective
Elective 1 Elective-4
Elective 2 Elective-5
Elective-6
All Computer Engg [ B.E., M.E., ] (Click on Subjects to
Subjects - enter)
UNIT III
TRANSACTIONS
Need for Concurrency – Locking Protocols – Two Phase Locking – Deadlock – Transaction
Recovery – Save Points – Isolation Levels – SQL Facilities for Concurrency and Recovery.
https://play.google.com/store/apps/details? Page: 1 / 30
www.BrainKart.
com
UNIT - 3
TRANSACTIONS
TRANSACTION CONCEPTS
Transaction
• Collection of operations that form a single logical unit of work is called transaction.
• Transaction is executed as a single unit. If the database was in consistent state before a
transaction, then after execution of the transaction also, the database must be in a
consistent.
Process of Transaction
The transaction is executed as a series of reads and writes of database objects, which are
explained below:
ACID PROPERTIES
Transaction Properties
There are four important properties of transaction that a DBMS must ensure to maintain
data in the case of concurrent access and system failures. These are:
https://play.google.com/store/apps/details? Page: 2 / 30
www.BrainKart.
com
The effect of completed or committed transactions should persist even after a crash. It
means once a transaction commits, the system must guarantee that the result of its operations will
never be lost, in spite of subsequent failures.
The acronym ACID is sometimes used to refer above four properties of transaction that
we have presented here: Atomicity, Consistency, Isolation, and Durability.
Atomicity
Suppose that, just prior to execution of transaction Ti the values of account A and B are
Rs.I000 and Rs.2000.
Now, suppose that during the execution of Ti, a power failure has occurred that prevented
the Ti to complete successfully. The point of failure may be after the completion Write (A,a) and
before Write(B,b). It means that the changes in A are performed but not in B. Thus the values of
account A and Bare Rs.950 and Rs.2000 respectively. We have lost Rs.50 as a result 'of this
failure.
Now, our database is in inconsistent state. The reason for this inconsistent state is that our
transaction is completed partially and we save the changes of uncommitted transaction. So, in
order to get the consistent state, database must be restored to its original values i.e. A to Rs.I000
and B to Rs.2000, this leads to the concept of atomicity of transaction. It means that in order to
maintain the consistency of database, either all or none of transaction's operations are performed.
In order to maintain atomicity of transaction, the database system keeps track of the old
values of any write and if the transaction does not complete its execution, the old values are
restored to make it appear as the transaction never executed.
Consistency
The consistency requirement here is that the sum of A and B must be unchanged by the
execution of the transaction. Without the consistency requirement, money could be created or
destroyed by the transaction. It can. be verified easily that, if the database is consistent before an
execution of the transaction, the database remains consistent after the execution of the
transaction.
Ensuring consistency for an individual transaction is the responsibility of the application
programmer who codes the transaction.
Isolation
If several transactions are executed concurrently (or in parallel), then each transaction
must behave as if it was executed in isolation. It means that concurrent execution does not result
an inconsistent state.
Durability
Once the execution of the transaction completes successfully, and the user who initiated
the transaction has been notified that the transfer of funds has taken place, it must be the case that
no system failure will result in a loss of data corresponding to this transfer of funds.
https://play.google.com/store/apps/details? Page: 3 / 30
www.BrainKart.
com
The durability property guarantees that, once a transaction completes successfully all the
updates that it carried out on the database persist, even if there is a system failure after the
transaction completes execution. Ensuring durability is the responsibility of a component of the
database system called the recovery-management component.
States of Transaction
Active: the initial state, the transaction stays in this state while it is
executing.
Partially committed: after the final statement has been executed.
➢ Failed: when the normal execution can no longer proceed.
➢ Aborted: after the transaction has been rolled back and the database has been restored to
its state prior to the start of the transaction.
➢ Committed: after successful completion.
SCHEDULES
https://play.google.com/store/apps/details? Page: 4 / 30
www.BrainKart.
com
Conflict Schedule
Two operations in a schedule are said to conflict if they satisfy the following three
condition
• they belong to different transactions
• they access the same item X
• atleast one of the operations is a write – item (X)
Complete Schedule
Recoverability
If a transaction Ti fails, we need to undo the effect of this transaction to ensure the
atomicity property of the transaction. In a system that allows concurrent execution, it is necessary
to ensure that any transaction Tj that is dependent on Ti is also aborted.
To achieve this surety, we need to place restrictions on the type of schedules permitted in
the system.
Types of schedules that are acceptable from the view point of recovery from transaction
failure are:
1. Recoverable schedules
2. Cascadeless (non-cascading) schedules
3. Strict schedules.
1. Recoverable Schedules
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.
In T9 is a transaction that performs only one instruction read (A). Suppose that the system
allows T9 to commit immediately after executing the read (A) instruction. Thus, T9 commits
before T8 does.
https://play.google.com/store/apps/details? Page: 5 / 30
www.BrainKart.
com
T8 T9
read (A)
write (A)
read (A)
read (B)
Schedule-1
• Suppose that T8 fails before it commits. Since T9 has read the value of data item A written by
T8, we must abort T9 to ensure transaction atomicity. However T9 has already committed and
cannot be aborted. Thus it is impossible to recover correctly from the failure of T8.
• Schedule 11 is an example of non-recoverable schedule, which should not be allowed. Most
database system requires that all schedules be recoverable.
• 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.
3. Cascadeless Schedules
Even if a schedule is recoverable, to recover correctly from the failure of a transaction Ti,
we may have to roll back several transactions. Such situations occur if transactions have read
data written by Ti.
T10 T11 T11
read (A)
read (B)
write (A)
read (A)
write (A)
read (A)
Schedule-2
• Transaction T10 writes a value of A that is read by transaction T11. Transaction T11 writes a
value of A that is read by transaction T12. Suppose that, at this point, T10 fails. T10 must be
rolled back. Since T11 is dependent on T10, T11 must be rolled back.
• This phenomenon, in which a single transaction failure leads to a series of transaction roll
backs, is called cascading rollback.
• Cascading rollback is undesirable, since it leads to the undoing of a significant amount of
work.
• Therefore schedules with cascading rollbacks are undesirable. Schedules should not contain
cascading schedules are called cascadeless schedules.
• A cascadeless 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 read
operation of Tj.
https://play.google.com/store/apps/details? Page: 6 / 30
www.BrainKart.
com
Strict Schedules
This is a more restrictive schedule than the recoverable schedules and non cascading
schedules. In this schedule, transactions cannot read or write a data item ‘X’ until the last
transaction that wrote the data item ‘X’ has committed or aborted. Strict schedules simplify the
recovery process. In this, the process of undoing a write operation of an aborted transaction is
easy.
SERIALIZABILITY
Introduction
A schedule where the operations of each transaction are executed consecutively without
any other interference from other transactions is called serial schedule. Here the transactions are
performed in the serial order.
A non-serial schedule is a schedule where the operations from a group of concurrent
transactions are interleaved.
The objective of serializability is to find non-serial schedules that allow transactions to
executive concurrently without interfering with one another and thereby producing a database
state that could be produced by a serial execution.
A non-serial schedule is said to be serializable, if it produces the same results as some
serial execution of the transactions.
Types of Serializability
(1) Conflict serializability
(2) View serializability.
1. Conflict Serializability
Let us consider a schedule S in which there are two consecutive instructions Ii and Ij
of transactions Ti and Tj respectively (i j). If Ii and Ij refer to different data items, then we can
swap Ii and Ij without affecting the results of any instruction in the schedule. However, if Ii and Ij
refer to the same data item Q, then the order of the two steps may matter. Since we are dealing
with only read and write instructions, there are four cases that we need to consider.
1. Ii = read (Q), Ij = read (Q). The order Ii and Ij does not matter, since the same
value of Q is read by Ti and Tj regardless of the order.
2. Ii = read (Q), Ij = write (Q). If Ii comes before Ij, then Ti does not read the value
of Q that is written by Tj in instruction Ij. If Ij comes beore Ii, then Ti reads the
value of Q that is written by Tj. Thus the order of Ii and Ij matters.
3. Ii = write (Q), Ij = read (Q). The order of Ii and Ij matters, reason is same as
previous case.
4. Ii = write (Q), Ij = write (Q). Since both the instructions are write operations, the
order of these instructions does not affect either Ti or Tj. However the value
obtained by the next read (Q) instruction S is affected, since the result of only the
latter of the two write instructions is preserved in the database. If there is no other
https://play.google.com/store/apps/details? Page: 7 / 30
www.BrainKart.
com
write (Q) instruction after Ii and Ij in S then the order of Ii and Ij directly affects the
final or Q in the database state that results from schedule S.
Thus, only in the case where both Ii and Ij are read instructions does the order of
their execution does not matter.
We say that Ii and Ij conflict if they are operations by different transactions on the same
data item and at least one of these instructions is a write operation.
read (B)
write (A)
write (B)
read (B)
write (B)
The final result of these swaps - is shown below, which is serial schedule.
https://play.google.com/store/apps/details? Page: 8 / 30
www.BrainKart.
com
T1 T2
read (A)
write (A)
read (B)
write (B)
read (A)
write (A)
read (B)
write (B)
The concept of conflict equivalence loads to the concept of conflict serializability. We say
that a schedule S is conflict serializable, if it is conflict equivalent to a serial schedule. Thus
schedule 3 is conflict serializable, since it is conflict equivalent to the serial schedule 1.
Consider schedule 7 of Fig.5.9. It consists of two transactions T3 and T4. This schedule is
not conflict serializable, since it is not equivalent to either the serial schedule <T3, T4> or the
read
serial schedule <T4, T3>.
(Q)
T3 T4
write (Q)
write (Q)
Schedule 7
2. View Serializability
Consider two schedules S and S1, where the same set of transactions participates in both
the schedules. The schedule S and S1 are said to be view equivalent if three conditions are met:
1. For each data item Q, if transaction Ti reads the initial value of Q in schedule
S, then transaction Ti must in schedule S1, also read the initial value of Q.
2. For each data item Q, if transaction Ti executes read (Q) in schedule S, and
if that value was produced by a write (Q) operation executed by transaction Tj,
then the read (Q) operation of transaction Ti must, in schedule S1, also read the
value of Q that was produced by the same write (Q) operation of transaction Tj.
3. For each data item Q, the transaction (if any) that performs the final write (Q)
operation in schedule S must perform the final write (Q) operation in schedule S1.
The concept of view equivalence leads to the concept of view serializability. We say that
a schedule S is view serializable, if it is view equivalent to a serial schedule.
https://play.google.com/store/apps/details? Page: 9 / 30
www.BrainKart.
com
Consider the schedule 8 shown in Fig. It is view equivalent to the serial schedule. <T3, T4,
T6> since one read (Q) instruction reads the initial value of Q in both schedules, and T5 performs
the final write of Q in both schedules.
T3 T4 T6
read (Q)
write (Q)
write (Q)
write (Q)
Schedule 8-a view serializable schedule
Every conflict serializable schedule is also view serializable, but there are view serializable
schedules that are not conflict serializable.
Testing for serializability is done by using a directed graph, called precedence graph,
constructed from schedule. This graph consists of a pair G = (V , E), where V is a set of vertices
and E is a set of edges. The set of vertices consists of all transactions in schedule. The set of
edges consists of all edges Ti Tj for which one of three conditions holds:
https://play.google.com/store/apps/details? Page: 10 / 30
www.BrainKart.
com
T1 T2
read (A)
A: = A-50
read (A)
temp: = A*0.1
A: = A- temp
write (A)
write (B)
write (A)
read (B)
B: = B + 50
write (B)
B: = B + temp
write (B)
Schedule 9
The precedence graph for schedule 9 is shown below
T1 T2
https://play.google.com/store/apps/details? Page: 11 / 30
www.BrainKart.
com
Concurrent schedule
Solution:
T9 T10 T11
The precedence graph used for testing conflict serializability cannot be used for testing view
serializability. We need to extend the precedence graph to include labeled edges. This graph is
called as labeled precedence graph.
Let S be a schedule. Suppose that the transaction Tj reads the value of data item
Q written by Ti. If S is view serializable, then in any serial schedule S1 that is equivalent to S, Ti
must precede Tj. Suppose that, in schedule S, transaction Tk executed a write (Q).
Then, in schedules Tk must either precede Ti or follow Tj . It cannot appear in between Ti and Tj
because Tj would not read the value of Q written by Ti and thus S would not be view equivalent
to S1. These constraints cannot be expressed using simple precedence graph, therefore labeled
precedence graph is used.
https://play.google.com/store/apps/details? Page: 12 / 30
www.BrainKart.
com
T1 T2 T3
read (Q)
write (Q)
write (Q)
write (Q)
Concurrent schedule S2
Solution: The graph constructed in step 1 and 2 is shown in Fig. 5.16 (a) and final graph
is shown in the above figure.
CONCURRENCY CONTROL
The system must control the interaction among the concurrent transactions. This control
is achieve through one of concurrency control schemes. The concurrency control schemes are
based on the serializability property.
Different types of protocols/schemes used to control concurrent execution of transactions.
https://play.google.com/store/apps/details? Page: 13 / 30
www.BrainKart.
com
Types of Locks
Several types of locks can be used in concurrency control. Among them two types are
important.
1. Binary locks.
2. Shared and Exclusive locks.
https://play.google.com/store/apps/details? Page: 14 / 30
www.BrainKart.
com
SX true false
ffaallssee
Fig 3.6 Lock-compatibility matrix ‘comp’
To access a data item, transaction Ti must first lock that item. If the data item is
already locked by another transaction in an incompatible mode, the concurrency
control manager will not grant the lock until all incompatible locks held by other transactions
have released. Thus, Ti is made to wait until all incompatible locks held by other transactions
have been released.
LOCKING PROTOCOLS
Each transaction in the system should follow a set of rules, called locking protocol,
indicating when a transaction may lock and unlock each of the data items. Locking protocol
restricts the number of possible schedules.
Granting of Locks
When a transaction requests a lock on the data item in a particular mode and no other
transaction has a lock on the same data item in a conflicting mode, the lock can be granted.
However, care must be taken while granting the locks.
For example, consider a transaction T2 has a shared mode lock on data item Q, and
another transaction T1 requests an exclusive-mode lock on the same data item. In this case, T1 has
to wait for T2 to release the shared - mode lock. Mean while, another transaction T3 requests the
shared mode lock on Q. The lock request is compatible with the lock granted to T2, so T3 may be
granted the shared-mode lock.
At this point, T2 may releases the lock, but still T1 has to wait for T3 to release the lock.
Thus it is possible that sequence of transactions that each requests a shared-mode lock on Q, and
each transaction releases the lock a short while after it is granted, but T1 may never gets the
https://play.google.com/store/apps/details? Page: 15 / 30
www.BrainKart.
com
exclusive mode lock on the data item. The transaction T1 may never make progress 1 and is said
to be starved.
Starvation of transaction can be avoided by granting locks in the following manner. When
a transaction Ti requests a lock on a data item Q in a particular mode M, the concurrency control
manager grants the lock provided that
1. There is no other transaction holding a lock on Q in a mode that conflicts
with M.
2. There is no other transaction that is waiting for a lock on Q, and that made
its lock request before Ti.
Two-phase Locking Protocol
This protocol requires that each transaction issue lock and unlock requests in two phases.
3. Growing phase: A transaction may obtain locks, but may not release any lock.
4. Shrinking phase: A transaction may release locks, but may not obtain any new
locks.
Initially, a transaction is in the growing phase. The transaction aquires locks as needed.
Once a transaction releases a lock, it enters in the shrinking phase, and it cannot issue more lock
requests.
For example, transactions T3 is two phase. But transactions T1 and T2 are not two phase.
Note that the unlock instructions do not need appear at the end of the transaction.
T3: lock-X (B);
read (B);
B: = B-50;
write (B);
lock-X (A);
read (A); A: = A=50;
write (A); unlock (B); unlock (A);
Fig. 3.7 Transaction T3
Advantages
The two-phase locking protocol ensures conflict serializability.
Consider any transaction, the point in the schedule where the transaction has obtained its
final lock is called the lock-point of the transaction. Now, the transactions can be ordered
according to their lock points. This ordering is the serializability ordering for the transactions.
Disadvantages
1. It does not ensure freedom from deadlock.
2. Cascading rollbacks may occur under two-phase locking.
https://play.google.com/store/apps/details? Page: 16 / 30
www.BrainKart.
com
Types:
1. Strict two phase locking protocol
This protocol requires that locking should be two phase, and all exclusive-mode locks taken
by a transaction should be held until the transaction. This requirement prevents any transaction
from reading the data written by any uncommitted transaction under exclusive mode until the
transaction commits, preventing any other transaction from reading the data.
2. Rigorous two phase locking protocol
This protocol requires that all locks be held until the transaction commits. We can easily
verify that, with rigorous two-phase locking, transactions can be serialized in the order in which
they commit.Most database systems implement either strict or rigorous two-phase locking.
Two-phase locking protocol allows lock conversions. There is a mechanism for upgrading
a shared lock to an exclusive lock, downgrading an exclusive lock to a shared lock. We donote
the conversion from shared to exclusive modes by upgrade, and from exclusive to shared by
downgrade. Lock conversion cannot be allowed arbitrarily.
Strict two-phase locking and rigorous two-phase locking (with lock conversions) are used
extensively in commercial database systems.
A simple but widely used scheme automatically generates the appropriate lock and unlock
instructions for a transaction, on the basis of read and write requests from the transaction:
• When a transaction Ti issues a read (Q) operation, the system issues a lock-
S(Q) instruction followed by the read (Q) instruction.
• When Ti issues a write (Q) operation, the system checks to see whether Ti
already holds a shared lock on Q. If it does, then the system issues an upgrade
(Q) instruction, followed by the write (Q) instruction. Otherwise, the system issues a
lock - X(Q) instruction, followed by the write (Q) instruction.
• All locks obtained by a transaction are unlocked after that transaction commits or
aborts.
DEADLOCKS
A system is in a deadlock state if there exists a set of transactions such that every
transaction in the set is waiting for another transaction in the set.
In other words, there exists a set of waiting transactions such that T0 is waiting for a data
item that T1 holds and T1 is waiting for a data item that T2 holds and ..., and Tn-1 is waiting for a
data item that Tn holds, and Tn is waiting for a data item that T0 holds. In such a situation, none
of the transactions can make progress.
There are two principal methods for dealing with the deadlock problem.
(i) Deadlock prevention: This approach ensures that system will never enter in
deadlock state.
(ii) Deadlock detection and recovery: This approach tries to recover from
deadlock if system enters in deadlock state.
https://play.google.com/store/apps/details? Page: 17 / 30
www.BrainKart.
com
Deadlock Prevention
There are two approaches for deadlock prevention:
(a) One approach ensures that no cyclic waits can occur by ordering the requests
for locks, or requiring all locks to be acquired together. This approach
requires that each transaction locks all data items before it begins execution. It is
required that, either all data items should be locked in one step, or none should be
locked.
Disadvantages of this approach are
1. It is hard to predict before the transaction begins, what data items need to be
locked.
2. Data-item utilization may be very low, since many of the data items may be
locked but unused for long time.
(b) The second approach for deadlock prevention is to use pre-emption and
transaction rollbacks. In pre-emption when a transaction T2 requests a lock
that transaction T1 holds, the lock granted to T1 may be pre-empted by rolling
back of T1, and granting of the lock to T2.
To control pre-emption, a unique timestamp is assigned to each transaction. The system
uses timestamp to decide whether a transaction should wait or roll back.
Two different deadlock prevention schemes using timestamp are:
(i) Wait-die
The wait-die scheme is non-pre-emption technique. In this, when transaction Ti
requests a data item held by Tj, Ti is allowed to wait only if it has a timestamp
smaller than Tj. (That is Ti is older than Tj). Otherwise, Ti is rolled back (dies).
For example, suppose that transactions T22, T23, and T24 have timestamps 5, 10 and 15
respectively. If T22 requests a data item held by T23, then T22 will wait. If T24
requests a data item held by T23, then T24 will be rolled back.
(ii) Wound-wait
The wound-wait is pre-emptive technique. In this, when transaction Ti requests data
item-held by Tj, Ti is allowed to wait, only if it has timestamp greater than Tj (that
is Ti is younger than Tj). Otherwise Tj is rolled back.
Returning to same example, if T1 requests a data item hold by T2, then the data item
will be preempted by T2, and T2 will be rolled back. If T3 requests a data item held
by T2 then T3 will wait.
Differences between two schemes
• In the wait-die scheme, an older transaction must wait for a younger one to release its
data item. Thus, the older the transaction gets, the more it tends to wait. By contrast,
in the wound-wait scheme, an older transaction never waits for a younger
transaction.
https://play.google.com/store/apps/details? Page: 18 / 30
www.BrainKart.
com
• In the wait-die scheme, if a transaction Ti dies and is rolled back because it requested
a data item held by transaction Tj , then Ti may re-issue the same sequence of
requests when it is restarted. If the data item is still held by Tj, then Ti will die again.
Thus Ti may die several times before acquiring the needed data item. Contrast this series
of events with what happens in the wound-wait scheme Transaction Ti is wounded and rolled
back because Tj requested a data item that it holds. When Ti is restarted and requests the data item
now being held by Tj, Ti waits. Thus, there may be fewer rollbacks in the wound-wait scheme.
The major problem with both of these schemes is that unnecessary rollbacks may occur.
Timeout-Based Schemes
This approach for deadlock handling is based on lock timeouts. In this approach, a
transaction that has requested a lock waits for at most a specified amount of time. If the lock has
not been granted within that time, the transaction is said to be time out, and it rolls back itself and
restarts. Thus, if there was a deadlock one or more transactions involved in the deadlock will
time out and roll back, allowing the others to proceed.
Advantages
1. This scheme is easy to implement.
2. It works well if transactions are short, and if long, waits are likely to be due to
deadlocks.
Disadvantages
1. It is hard to decide how long a transaction should wait. Too long waits results in
unnecessary delays once a deadlock has occurred, and too short a wait results in
transaction rollbacks even when there is no deadlock.
2. Starvation is also possible with this scheme.
https://play.google.com/store/apps/details? Page: 19 / 30
www.BrainKart.
com
T26 T28
T25
T27
T26 T28
T25
T27
https://play.google.com/store/apps/details? Page: 20 / 30
www.BrainKart.
com
TRANACTION RECOVERY
❖ Protocols that obey this are referred to as non-blocking protocols. In the following two
sections, we consider two common commit protocols suitable for distributed DBMSs:
two-phase commit (2PC) and three-phase commit (3PC), a non-blocking protocol.
❖ Assume that every global transaction has one site that acts as coordinator (or
transaction manager) for that transaction, which is generally the site at which the
transaction was initiated. Sites at which the global transaction has agents are called
participants (or resource managers).
❖ Assume that the coordinator knows the identity of all participants and that each
participant knows the identity of the coordinator but not necessarily of the other participants.
https://play.google.com/store/apps/details? Page: 21 / 30
www.BrainKart.
com
Phase 1
(1) Write a begin_commit record to the log file and force-write it to stable storage.
✓ Send a PREPARE message to all participants.
✓ Wait for participants to respond within a timeout period.
Phase 2
https://play.google.com/store/apps/details? Page: 22 / 30
www.BrainKart.
com
(i) Coordinator
The coordinator can be in one of four states during the commit process:
❖ INITIAL
❖ WAITING
❖ DECIDED
❖ COMPLETED
as shown in the state transition diagram in Figure, but can time out only in the middle two states.
The actions to be taken are as follows:
Timeout in the WAITING state -The coordinator is waiting for all participants to
acknowledge whether they wish to commit or abort the transaction. In this case, the coordinator
cannot commit the transaction because it has not received all votes. However, it can decide to
globally abort the transaction.
Timeout in the DECIDED state -The coordinator is waiting for all participants to
acknowledge whether they have successfully aborted or committed the transaction. In this case,
https://play.google.com/store/apps/details? Page: 23 / 30
www.BrainKart.
com
The coordinator simply sends the global decision again to sites that have not acknowledged.
https://play.google.com/store/apps/details? Page: 24 / 30
www.BrainKart.
com
SAVE POINTS
A SAVEPOINT is a point in a transaction when you can roll the transaction back to a
certain point without rolling back the entire transaction.
The syntax for a SAVEPOINT command is as shown below.
SAVEPOINT SAVEPOINT_NAME;
This command serves only in the creation of a SAVEPOINT among all the transactional
statements. The ROLLBACK command is used to undo a group of transactions.
The syntax for rolling back to a SAVEPOINT is as shown below.
ROLLBACK TO SAVEPOINT_NAME;
Following is an example where you plan to delete the three different records from the
CUSTOMERS table. You want to create a SAVEPOINT before each delete, so that you can
ROLLBACK to any SAVEPOINT at any time to return the appropriate data to its original state.
Example
Consider the CUSTOMERS table having the following records.
ID NAME AGE ADDRESS SALARY
1 Suresh 23 Chennai 5400
2 Mano 22 Cochin 6500
3 Subhiksha 23 Newyork 4500
https://play.google.com/store/apps/details? Page: 25 / 30
www.BrainKart.
com
https://play.google.com/store/apps/details? Page: 26 / 30
www.BrainKart.
com
Isolation levels determine the type of phenomena that can occur during the execution of
concurrent transactions
Three phenomena define SQL Isolation levels for a transaction:
1. Dirty Reads returns different results within a single transaction when an SQL operation
an uncommitted or modified record created by another transaction. Dirty Reads increases
concurrency, but reduces consistency.
2. Non-Repeatable Reads returns different results within a single transaction when an SQL
operation reads the same row in a table twice. Non-Repeatable Reads can occur when another
transaction modifies and commits a change to the row between transaction reads. Non-repeatable
reads increases consistency, but reduces concurrency.
3. Phantoms returns different results within a single transaction when an SQL operation
retrieves a range of data values twice. Phantoms can occur if another transaction inserted a new
record and committed the insertion between executions of the range retrieval.
Each Isolation level differs in the phenomena it allows:
Read uncommitted X X X
Read committed -- X X
Repeatable read -- -- X
Serializable -- -- --
❖ Read Uncommitted – Read Uncommitted is the lowest isolation level. In this level, one
transaction may read not yet commited changes made by other transaction, thereby allowing
dirty reads. In this level, transactions are not isolated from each other.
❖ Read Committed – This isolation level guarantees that any data read is committed at the
moment it is read. Thus it does not allows dirty read. The transaction hold a read or write
lock on the current row, and thus prevent other rows from reading, updating or deleting it.
https://play.google.com/store/apps/details? Page: 27 / 30
www.BrainKart.
com
❖ Repeatable Read – This is the most restrictive isolation level. The transaction holds read
locks on all rows it references and write locks on all rows it inserts, updates, or deletes. Since
other transaction cannot read, update or delete these rows, consequently it avoids non
repeatable read.
Crash Recovery
DBMS is a highly complex system with hundreds of transactions being executed every
second. The durability and robustness of a DBMS depends on its complex architecture and its
underlying hardware and system software. If it fails or crashes amid transactions, it is expected
that the system would follow some sort of algorithm or techniques to recover lost data.
Failure Classification
To see where the problem has occurred, we generalize a failure into various categories,
as follows –
Transaction failure
A transaction has to abort when it fails to execute or when it reaches a point from where
it can’t go any further. This is called transaction failure where only a few transactions or
processes are hurt.
Reasons for a transaction failure could be −
• Logical errors − Where a transaction cannot complete because it has some code error or
any internal error condition.
• System errors − Where the database system itself terminates an active transaction
because the DBMS is not able to execute it, or it has to stop because of some system
condition. For example, in case of deadlock or resource unavailability, the system aborts
an active transaction.
System Crash
There are problems − external to the system − that may cause the system to stop abruptly
and cause the system to crash. For example, interruptions in power supply may cause the failure
of underlying hardware or software failure.
Examples may include operating system errors.
Disk Failure
In early days of technology evolution, it was a common problem where hard-disk drives
or storage drives used to fail frequently. Disk failures include formation of bad sectors,
unreachability to the disk, disk head crash or any other failure, which destroys all or a part of
disk storage.
https://play.google.com/store/apps/details? Page: 28 / 30
www.BrainKart.
com
Storage Structure
We have already described the storage system. In brief, the storage structure can be divided into
two categories −
• Volatile storage − As the name suggests, a volatile storage cannot survive system
crashes. Volatile storage devices are placed very close to the CPU; normally they are
embedded onto the chipset itself. For example, main memory and cache memory are
examples of volatile storage. They are fast but can store only a small amount of
information.
• Non-volatile storage − These memories are made to survive system crashes. They are
huge in data storage capacity, but slower in accessibility. Examples may include hard-
disks, magnetic tapes, flash memory, and non-volatile (battery backed up) RAM.
Recovery and Atomicity
When a system crashes, it may have several transactions being executed and various files
opened for them to modify the data items. Transactions are made of various operations, which
are atomic in nature. But according to ACID properties of DBMS, atomicity of transactions as a
whole must be maintained, that is, either all the operations are executed or none.
When a DBMS recovers from a crash, it should maintain the following −
• It should check the states of all the transactions, which were being executed.
• A transaction may be in the middle of some operation; the DBMS must ensure the
atomicity of the transaction in this case.
• It should check whether the transaction can be completed now or it needs to be rolled
back.
• No transactions would be allowed to leave the DBMS in an inconsistent state.
There are two types of techniques, which can help a DBMS in recovering as well as maintaining
the atomicity of a transaction −
• Maintaining the logs of each transaction, and writing them onto some stable storage
before actually modifying the database.
• Maintaining shadow paging, where the changes are done on a volatile memory, and later,
the actual database is updated.
Log-based Recovery
Log is a sequence of records, which maintains the records of actions performed by a
transaction. It is important that the logs are written prior to the actual modification and stored on
a stable storage media, which is failsafe.
https://play.google.com/store/apps/details? Page: 29 / 30
www.BrainKart.
com
https://play.google.com/store/apps/details? Page: 30 / 30
Click on Subject/Paper under Semester to
enter. Environmental
Professional English Sciences
Professional and Sustainability -
English - I - - II - HS3252 Discrete GE3451
HS3152
Mathematics
Statistics and Theory of Computation
- MA3354
Numerical - CS3452
Matrices and
Methods - MA3251
Calculus Digital Principles
and Computer Artificial
- MA3151
Semester
Engineering Intelligence and
Semester
Organization
Semester
- CS3351
Engineering - CS3491
Physics - PH3151 - GE3251
Foundation of Data
Physics for Science - CS3352 Database Management
4th
System - CS3492
2nd
1st
Engineering Information
3rd
Chemistry Science
Data Structure -
- CY3151 - PH3256 CS3301 Algorithms - CS3401
Basic Electrical and
Electronics Object Oriented Introduction to
Problem Solving Engineering Operating
Programming -
and Python - BE3251 Systems - CS3451
CS3391
Programming -
GE3151 Programming in C
- CS3251
Computer
Networks - Object Oriented
CS3591 Software
Engineering
- CCS356 Human Values and
Compiler Design - Ethics - GE3791
CS3501 Embedded
Semester
Semester
Project Work /
Semester
and Cyber
Security - Open Elective 3 Intership
CB3491 Open
Open Elective 4
5th
7th
Distributed Elective-1
8th
Computing
6th
Management
- CS3551 Elective-3
Elective
Elective 1 Elective-4
Elective 2 Elective-5
Elective-6
All Computer Engg [ B.E., M.E., ] (Click on Subjects to
Subjects - enter)