of Chapter 3.2 - Transaction Management and Concurrency Control
of Chapter 3.2 - Transaction Management and Concurrency Control
ENGINEERING
• The main DBMS course, we learn about the structural formation of data, maintain data
integrity, multitasking with concurrent access and recovery without occurring crashes,
data structures, data models etc. and their working in which every organization is based.
• At the end of the course, the students may understand the concepts of data structures,
data models and design, construction of queries by using SQL, uses and applications of
database design etc
COURSE OUTCOMES
1. To have good understanding of database system concepts and design databases for
different applications.
2. To learn how to use a DBMS and RDBMS.
3. To implement and understand different types of DDL, DML and DCL statements.
4. To understand transaction concepts related to databases and recovery/backup
techniques required for the proper storage of data.
Topics covered
Atomicity
Consistency
• The rules (integrity constraint) that keep the database accurate and consistent are
followed before and after a transaction.
• When a transaction is completed, it leaves the database either as it was before or in
a new stable state.
• This property means every transaction works with a reliable and consistent version
of the database.
• The transaction is used to transform the database from one consistent state to
another consistent state. A transaction changes the database from one consistent
state to another consistent state.
Consistency
Isolation
• It shows that the data which is used at the time of execution of a transaction cannot be
used by the second transaction until the first one is completed.
• In isolation, if the transaction T1 is being executed and using the data item X, then that
data item can’t be accessed by any other transaction T2 until the transaction T1ends.
• The concurrency control subsystem of the DBMS enforced the isolation property
Isolation
Durability
• The durability property is used to indicate the performance of the database’s consistent
state. It states that the transaction made the permanent changes.
• They cannot be lost by the erroneous operation of a faulty transaction or by the system
failure. When a transaction is completed, then the database reaches a state known as the
consistent state. That consistent state cannot be lost, even in the event of a system’s
failure.
• The recovery subsystem of the DBMS has the responsibility of Durability property.
Durability
Failure Classification
To find that where the problem has occurred, we generalize a failure into the
following categories:
• Transaction failure
• System crash
• Disk failure
1.Transaction Failure
The transaction failure occurs when it fails to execute or
when it reaches a point from where it can’t go any further.
If a few transactions or process is hurt, then this is called
as transaction failure.
Reasons for a transaction failure could be –
1. Logical errors: If a transaction cannot complete due
to some code error or an internal error condition, then
the logical error occurs.
2. 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.
2. System Crash
System failure can occur due to power failure or other
hardware or software failure. Example: Operating
system error.
• Fail-stop assumption: In the system crash, non-
volatile storage is assumed not to be corrupted.
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.
Serializability
Serializability
It is an important aspect of Transactions. In simple meaning, you can say that
serializability is a way to check whether two transactions working on a database are
maintaining database consistency or not.
It is of two types:
1. Conflict Serializability
2. View Serializability
Conflict Serializable
Concurrency serializability, also known as conflict serializability, is a type of
concurrency control that guarantees that the outcome of concurrent transactions is
the same as if the transactions were executed consecutively.
• Conflict serializable schedules: A schedule is called conflict serializable if it
can be transformed into a serial schedule by swapping non-conflicting
operations.
• Non-conflicting operations: When two operations operate on separate data
items or the same data item but at least one of them is a read operation, they are
said to be non-conflicting.
Conflicting Operations
Two operations are said to be conflicting if all conditions are satisfied:
• They belong to different transactions
• They operate on the same data item
• At Least one of them is a write operation
Example:
• Conflicting operations pair (R1(A), W2(A)) because they belong to two different
transactions on the same data item A and one of them is a write operation.
• Similarly, (W1(A), W2(A)) and (W1(A), R2(A)) pairs are also conflicting.
• On the other hand, the (R1(A), W2(B)) pair is non-conflicting because they
operate on different data items.
• Similarly, ((W1(A), W2(B)) pair is non-conflicting.
Consider the following schedule:
If Oi and Oj are two operations in a transaction and Oi< Oj (Oi is executed before Oj),
same order will follow in the schedule as well. Using this property, we can get two
transactions of schedule S1:
T1: R1(A), W1(A), R1(B), W1(B)
T2: R2(A), W2(A), R2(B), W2(B)
Possible Serial Schedules are: T1->T2 or T2->T1
Possible Serial Schedules are: T1->T2 or T2->T1
Swapping non-conflicting operations R2(A) and R1(B) in S1, the schedule becomes,
-> Similarly, swapping non-conflicting operations W2(A) and W1(B) in S11, the schedule
becomes,
S12 is a serial schedule in which all operations of T1 are performed before starting any operation
of T2. Since S has been transformed into a serial schedule S12 by swapping non-conflicting
operations of S1, S1 is conflict serializable.
Conflict Equivalent
Two schedules are said to be conflict equivalent when one can be transformed to
another by swapping non-conflicting operations. In the example discussed above,
S11 is conflict equivalent to S1 (S1 can be converted to S11 by swapping non-
conflicting operations). Similarly, S11 is conflict equivalent to S12, and so on.
Note 1: Although S2 is not conflict serializable, still it is conflict equivalent to S21
and S22 because S2 can be converted to S21 and S22 by swapping non-conflicting
operations.
Note 2: The schedule which is conflict serializable is always conflict equivalent to
one of the serial schedule. S1 schedule discussed above (which is conflict
serializable) is equivalent to the serial schedule (T1->T2).
Advantages of Conflict Serializability
• Consistency: Conflict serializability guarantees that the transactions’ outcomes
correspond to the sequence in which they were carried out.
• Correctness: Regardless of the order in which transactions were submitted,
conflict serializability guarantees that transactions are executed correctly.
• Decreased Overhead: By doing away with pointless locking and other conflict
resolution techniques, conflict serializability lowers overhead.
Now, we see that the precedence graph of the second table does not contain any cycle/loop,
which means it is conflict serializable (equivalent to serial schedule, consistent) and the final
result is coming the same as the first table.
Note: In the above example we understood that if a schedule is Conflict-serializable so we can
easily predict that It would be –
Equivalent to a serial schedule,
Consistent,
And also, a View-Serializable.
Schedule
Schedule, as the name suggests is a process of lining the transactions and executing
them one by one. When there are multiple transactions that are running in a
concurrent manner and the order of operation is needed to be set so that the
operations do not overlap each other, Scheduling is brought into play and the
transactions are timed accordingly.
It is of two types:
1. Serial Schedule
2. Non-Serial Schedule
Types of Schedules in DBMS
Schedules in DBMS ensure that transactions are executed in a serializable order.
Understanding the types of schedules is crucial for ensuring database consistency.
Serial Schedules:
Schedules in which the transactions are executed non-interleaved, i.e., a serial
schedule is one in which no transaction starts until a running transaction has ended
are called serial schedules. Example: Consider the following schedule involving two
transactions T 1 and T 2 .
where R(A) denotes that a read operation is performed on some data
item ‘A’ This is a serial schedule since the transactions perform
serially in the order T 1 —> T 2
Non-Serial Schedule
This is a type of Scheduling where the operations of multiple transactions are
interleaved. This might lead to a rise in the concurrency problem. The transactions are
executed in a non-serial manner, keeping the end result correct and same as the serial
schedule. Unlike the serial schedule where one transaction must wait for another to
complete all its operation, in the non-serial schedule, the other transaction proceeds
without waiting for the previous transaction to complete. This sort of schedule does
not provide any benefit of the concurrent transaction. It can be of two types namely,
Serializable and Non-Serializable Schedule. The Non-Serial Schedule can be divided
further into Serializable and Non-Serializable.
Serializable
This is used to maintain the consistency of the database. It is mainly used in the Non-
Serial scheduling to verify whether the scheduling will lead to any inconsistency or
not. On the other hand, a serial schedule does not need the serializability because it
follows a transaction only when the previous transaction is complete. The non-serial
schedule is said to be in a serializable schedule only when it is equivalent to the serial
schedules, for an n number of transactions. Since concurrency is allowed in this case
thus, multiple transactions can execute concurrently. A serializable schedule helps in
improving both resource utilization and CPU throughput. These are of two types:
• Conflict Serializable
• View Serializable
Conflict Serializable
Concurrency serializability, also known as conflict serializability, is a type of
concurrency control that guarantees that the outcome of concurrent transactions
is the same as if the transactions were executed consecutively.
• Conflict serializable schedules: A schedule is called conflict serializable if
it can be transformed into a serial schedule by swapping non-conflicting
operations.
• Non-conflicting operations: When two operations operate on separate data
items or the same data item but at least one of them is a read operation, they
are said to be non-conflicting.
Conflicting Operations
Two operations are said to be conflicting if all conditions are satisfied:
• They belong to different transactions
• They operate on the same data item
• At Least one of them is a write operation
Example:
• Conflicting operations pair (R1(A), W2(A)) because they belong to two different
transactions on the same data item A and one of them is a write operation.
• Similarly, (W1(A), W2(A)) and (W1(A), R2(A)) pairs are also conflicting.
• On the other hand, the (R1(A), W2(B)) pair is non-conflicting because they operate
on different data items.
• Similarly, ((W1(A), W2(B)) pair is non-conflicting.
View Serializable Schedule
A View Serializable Schedule is a type of schedule in DBMS that ensures the final
outcome of the schedule is the same as that of a serial schedule, even if the operations
are interleaved.
It is broader than Conflict Serializable Schedules, meaning all conflict-serializable
schedules are view-serializable, but not all view-serializable schedules are conflict-
serializable.
Example of a View Serializable Schedule
• The initial read condition is satisfied as T2T2T2 reads AAA after
T1T1T1 writes it.
• The final write condition is satisfied as T3T3T3 performs the final write
on AAA.
• The read-write dependency condition is satisfied as T2T2T2 reads the
value of AAA written by T1T1T1.
Conditions for View Serializability A schedule is view-serializable if it
satisfies the following three conditions:
Initial Read Condition:
• If a transaction TiT_iTi reads a data item initially (i.e., no other transaction
writes it before TiT_iTi), then in the equivalent serial schedule, TiT_iTi
must also be the first to read that data item.
Final Write Condition:
• If a transaction TjT_jTj performs the final write on a data item in the
schedule, it must also perform the final write in the equivalent serial
schedule.
Read-Write Dependency Condition:
• If a transaction TkT_kTk reads a data item XXX written by TmT_mTm in
the schedule, then TkT_kTk must read XXX after TmT_mTm writes it in
the equivalent serial schedule.
Difference Between View Serializability and Conflict
Serializability
1. Recoverable Schedules
A recoverable schedule ensures that if a transaction TiT_iTi reads data modified by
another transaction TjT_jTj, TjT_jTj must commit before TiT_iTi commits. This
ensures that the database can be recovered to a consistent state if a failure occurs.
Key Features:
• Ensures no cascading aborts.
• Maintains consistency during failures.
Example of a Recoverable Schedule:
T2 reads the value of AAA written by T1T1T1.
T1T1T1 commits before T2T2T2, making the schedule recoverable.
Importance:
Recoverable schedules prevent data inconsistency during rollbacks.
2. Non-Recoverable Schedules
A non-recoverable schedule occurs when a transaction TiT_iTi reads data written by
TjT_jTj, but TjT_jTjis not committed before TiT_iTicommits. If TjT_jTjlater aborts,
it becomes impossible to maintain consistency because TiT_iTi has already committed
invalid data.
Benefits:
• Simplifies recovery.
• Reduces the number of transactions affected by rollbacks.
Strict Schedules
A strict schedule ensures that a transaction TiT_iTi can neither read nor write a data
item modified by another transaction TjT_jTjuntil TjT_jTjhas committed or aborted.
Example:
• T2 cannot access AAA until T1T1T1 has completed, making recovery
straightforward.
Benefits:
• Guarantees recoverability.
• Avoids cascading aborts.
Difference between Serial Schedule and
Serializable Schedule
Serial Schedule Serializable
Schedule
Concurrency Control
Concurrency control is a very important concept of DBMS which ensures the
simultaneous execution or manipulation of data by several processes or user without
resulting in data inconsistency. Concurrency Control deals with interleaved execution
of more than one transaction.