Unit 5 Transaction Concurrency Control
Unit 5 Transaction Concurrency Control
com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
DBMS
Unit - 5
i. Enter PIN.
Database Operations: -
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/dat… 1/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
It transfers data item X from the database to a local buffer belonging to the
transaction that executes the Read operation.
IT transfers data item X from the local buffer to the transaction that execute write
T1: - Read(A);
A: = A-50;
Write(A);
B: = B + 50;
Write(B);
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/dat… 2/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
1. Active: -
It is the initial state the transaction stays in this state while it is executing.
2. Partially Committed: -
The transaction stays in this state after the final statement has been executed.
3. Failed: -
The transaction enters into failed state after active state/ partially committed state.
This is the state after the discovery that normal execution can no longer proceed.
4. Aborted: -
After failed state, the transaction must be rolled back & the database must be
5. Committed: -
Above figure shows the state diagram of a transaction. A transaction starts in the
active state. When it finishes its final statement, it enters the partially committed state.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/dat… 3/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
When last statement of the actual output is written out in disk, the transaction enters
the committed state.
A transaction enters the failed state after the system determines that transaction can
no longer proceed with its normal execution. Such a transaction must be rolled back.
Then, it enters the aborted state.
i. Restart: -
It can restart the transaction if the transaction was aborted as a result of some
Hardware or software error that was created through internal logic of the transaction.
Ii. Kill: -
It can kill the program, if the transaction was aborted because of internal logical
Key takeaway:
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/dat… 4/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
● Atomicity
● Consistency
● Isolation
● Durability.
Atomicity: -
❏ It means either all operations are reflected in the database or none are.
❏ If a transaction fails to complete for some reason, recovery technique must undo
any effects of the transaction on the database.
Consistency: -
execution of transaction.
If account A having amount $100 & account B having amount $ 200 initially then after
execution of transaction, A must have $ 50 & B must have $ 250.
Isolation: -
Durability: -
Key takeaway;
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/dat… 6/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
The DBMS is the only organization in a 1-tier architecture where the user sits directly
on the DBMS and uses it. Any improvements made here will be carried out on the
DBMS itself directly. For end-users, it does not have handy tools. Designers and
programmers of databases typically tend to use a single-tier architecture.
3 -tier architecture
Based on the complexity of the users and how they use the data present in the
database, a 3-tier architecture divides the tiers from each other. It is the architecture
most commonly used to construct a DBMS.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/dat… 7/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
❏ Database (Data) Tier − The database resides at this level, along with its query
processing languages. At this stage, we also have the relationships that characterize
the data and their constraints.
❏ Application (Middle) Tier − The application server and the applications that
access the database reside at this level. For a user, this application tier provides an
abstract view of the database. End-users are unaware of any life outside the
application of the database. On the other hand, no other user above the application
tier is aware of the database tier. Thus, the application layer is in the middle and
serves as a mediator between the end-user and the database.
❏ User (Presentation) Tier − End-users work at this level and know little about the
life of the database above that layer. The framework may provide several views of the
database at this layer. Applications which reside in the application tier generate all
views.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/dat… 8/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
The architecture of multiple-tier databases is highly modifiable, since almost all its
components are independent and can be independently updated.
Key takeaway:
- Based on the complexity of the users and how they use the data present in the
database, a 3-tier architecture divides the tiers from each other
Transactions, subject to the constraint that, for each transaction Ti, appearing in S, th
Operations of Ti in they occur in original Ti. So, the execution of sequences which
Represents the chronological order in which instructions are executed in the system,
are called schedules.
E.g.
T1 T2
Read(A)
A:= A+100;
Write(A);
Read(A)
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/dat… 9/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
A := A-200;
Write(A).
* Schedule S *
If initial value of A = 500, then after successful execution of T1 & T2, A should
have value =400.
A = 500
T1 T2
Read(A)
Read(A)
(A=500) (A=500)
A: = A+100;
A: = A-200;
(A=600) (A=300)
Write(A); Write(A);
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 10/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
(A=600) (A=300)
*concurrent schedule S*
Here, instead of 400, schedule produces value of A=300. So, in this case database is in
inconsistent state.
Conflict Operations: -
Eg:
T1 T2
1. R(A)
2. W(A)
3. R(A)
4. W(A)
5. R(A)
6. R(B)
7.R(A)
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 11/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
8.W(B)
9. R(A)
Instructions 8 & 9 are non-conflict because these are working on different data item.
Key takeaway:
R here refers to the operation of reading and W to the operation of writing. In this
case, the execution of transaction T2 does not start until the completion of transaction
T1.
T1 T2
---- ----
R(A)
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 12/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
R(B)
W(A)
Commit
R(B)
R(A)
W(B)
Commit
Key takeaway:
5.2 Serializability
A schedule that can be serialized often leaves the database in a consistent state. A
serial schedule is often a serializable schedule since a transaction only begins after
the other transaction has completed execution in the serial schedule. However, for
serialization, a non-serial schedule needs to be tested.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 13/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
A serializable schedule helps to maximize both the usage of resources and CPU
throughput.
Types of serializability
Conflict serializability
Example
T1 T2
----- ------
R(A)
R(B)
R(A)
R(B)
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 14/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
W(B)
W(A)
We need to swap the R(A) operation of Transaction T2 with the W(A) operation of
Transaction T1 to turn this schedule into a serial schedule. However, since they are
competing operations, we cannot swap these two operations, so we can conclude that
this given schedule is not Serializable to Conflict.
View serializability
If the view is equal to a serial schedule, a schedule is called view serializable (no
overlapping transactions). A conflict schedule is a serializable view, but if blind
writing is included in the serializability, the serializable view is not serializable
conflict.
View equivalent
If they satisfy the following conditions, two timetables S1 and S2 are said to be
considered equivalent:
1. Initial Read
The initial reading of the two timetables must be the same. Suppose there are two S1
and S2 schedules. If a transaction T1 reads data item A in schedule S1, then in S2,
transaction T1 can read A as well.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 15/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
The two schedules above are considered as similar since T1 performs the initial read
operation in S1 and T1 also performs it in S2.
2. Updated Read
If Ti reads A that is updated by Tj in schedule S1, then in S2 as well, Ti can read A that
is updated by Tj.
The two schedules above are not considered equivalent since, in S1, T3 reads A
updated by T2 and in S2, T3 reads A updated by T1.
3. Final Read
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 16/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
For the two schedules, the final writing must be the same. In Schedule S1, if a
transaction T1 eventually updates A then in S2, T1 should also perform final writing
operations.
The view is identical to the above two schedules since T3 performs the final writing
operation in S1 and T3 performs the final writing operation in S2.
Key takeaway:
- If we are able to turn it into a serial schedule after swapping its non-conflicting
activities, a schedule is called dispute serializable.
● The schedules that theoretically meet this criterion are called recoverable
schedules & those do not are called non-recoverable schedules.
● Recoverable schedule is one where, for each pair of transactions Ti & Tj,
such that Tj reads a data item previously written by Ti, the commit operation of Ti
appears before the commit operation of Tj.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 17/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
E.g.
T1 T2
R(X)
W(X)
Commit;
R(X)
Commit
T2 reads the value of X, which has been written by T1. T1 commits & then T2. As per
definition, commit of T1 must appear before commit of T2. So, the schedule is called
as a recoverable schedule.
T1 T2 T3
R(X)
W(X)
R(X)
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 18/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
W(x)
R(X)
W(X)
*schedule S10*
● T2 has to be rolled back in case of T1’s failure because it read the X, written by
T1.
● Similarly, T3 has to be rolled back, because it read the value of X, written by T2.
Non-Recoverable Schedule:-
T1 T2
R(A)
W(A)
R(X)
Commit
R(B)
E.g.
T1 T2
r(x)
w(x)
r(X)
r(y)
w(x)
Commit;
Commit;
Key takeaway:
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 20/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
● Most of the techniques ensure Serializability of schedules, using protocols that guarantee
Serializability.
➢ Multiple granularity
➢ Multifermion schemes
i. A lock is a variable associated with a data item which describes the status of the item with
respect to possible operations that can be applied to it.
Ii. Generally, there is one lock for each data item in the database.
Iii. Locks are used as a means of synchronizing the access by concurrent transactions to the
database items.
Locking Models: -
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 21/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
a. Shared-Lock Mode: -
● If a transaction Ti has obtained a shared mode lock on item Q, then Ti can read Q but cannot
modify/write Q.
● Shared lock is also called as a Read-lock because other transactions are allowed to read the
item.
● It is denoted by s.
Eg. T1 T2
Locks(A);
Locks(B);
T1 has locked A in shared mode & T2 also has locked B in shared lock mode.
b. Exclusive-Lock Mode: -
● If a transaction Ti has obtained a exclusive-lock mode on item Q, then Ti can read & write Q.
● Exclusive –lock is also called a write-lock because a single transaction exclusively holds the
locks on the item
● It is denoted by X.
T1 T2
LockX(A)
LockX(B);
Lock-Compatibility Matrix: -
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 22/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
S X
S ✓ X
X X X
● If a transaction Ti has locked Q in shared mode, then another transaction Tj can lock Q in
shared mode only. This is called as composite mode.
● If a transaction Ti has locked Q in S mode, another transaction Tj can’t lock Q in X mode. This
is called incompatible mode.
● Similarly, if a transaction Ti has locked Q in X mode, then other transaction Tj can’t lock Q in
either S or X mode.
● If the data item is already locked by another transaction in an incompatible mode, the
concurrency control manager will not grant the lock until lock has been released.
● Thus, Ti is mode to wait until all incompatible locks have been released.
Without-locking modes: -
T1
R(A)
R(B)
Display(A+B)
With-locking modes: -
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 23/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
T1
Locks(A)
R(A) unlock(A)
Locks(B)
R(B) unlock(B)
Display(A+B)
T1 locks A & B in shared mode because T1 uses A & B only for reading purpose.
● Each transaction in the system should follow a set of rules, called locking protocol.
● A transaction is said to follow the two-phase locking protocol, if all locking operation
(shared, exclusive protocol) precede the first unlock operation.
● Such a transaction can be divided into two phases: Growing & shrinking phase.
● During Expanding / Growing phase, new locks on items can be acquired but no one can be
released.
● During a shrinking phase, existing locks can be released but no new locks can be acquired.
● If every transaction in a schedule follows the two-phase locking protocol, the schedule is
guaranteed to be serialization, obviating the need to test for Serializability.
● Consider, following schedules S11, S12. S11 does not follow two-phase locking &S12 follows
two-phase locking protocol.
T1
Lock_S(Y)
R(Y)
Unlock(Y)
Lock_X(Q)
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 24/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
R(Q)
Unlock(Q)
Q: = Q + Y;
W(Q);
Unlock(Q)
This schedule does not follow two phase locking because 3 rd instruction lock-X(Q) appears
after unlock(Y) instruction.
T1
Lock_S(Y)
R(Y)
Lock_X(Q)
R(Q)
Q: = Q + Y;
W(Q);
Unlock(Q);
Unlock(Y);
This schedule follows two-phase locking because all lock instructions appear before first
unlock instruction.
● These values are assigned, in the order in which the transactions are submitted to the
system, so timestamp can be thought of as the transaction start time.
● It is denoted as Ts(T).
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 25/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
● Note: - Concurrency control techniques based on timestamp ordering do not use locks, here
deadlock cannot occur.
Generation of timestamp: -
● Use a counter that is incremental each time its value is assigned to a transaction. Transaction
timestamps are numbered 1,2, 3, in this scheme. The system must periodically reset the counter
to zero when no transactions are executing for some short period of time.
1) Read-Ts(X): -
i. Read timestamp of X.
2) Write-Ts(X): -
i. Write timestamp of X.
These timestamps are updated whenever a new read(X) or write(X) instruction is executed.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 26/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
a. Whenever some transaction T issues a Read(X) or Write(X) operation, the algorithm compares
Ts(T) with Read-Ts(X) & Write-Ts(X) to ensure that the timestamp order of execution is not
violated.
b. If violate, transaction is aborted & resubmitted to system as a new transaction with new
timestamp.
c. If T is aborted & rolled back, any transaction T1 that may have used a value written by T
must also be rolled back.
d. Similarly, any transaction T2 that may have used a value written by T1 must also be rolled
back & so on.
Algorithm: -
OR
This is done because some younger transaction with a timestamp greater than Ts(T) has already
read/written the value of X before T had a chance to write(X), thus violating timestamp
ordering.
b) If the condition in (a) does not occur then execute write (X) operation of T & set write-
Ts(X) to Ts(T).
a. If write-Ts(X) > Ts(T), then abort & Rollback T & reject the operation.
This should be done because some younger transaction with timestamp greater than Ts(T) has
already written the value of X before T had a chance to read X.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 27/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
b. If Write-Ts(X) ≤ Ts(T), then execute the read(X) operation of T & set read-Ts(X) to the
larger of Ts(T) & current read-Ts(X).
Advantages: -
2. The protocol ensures freedom from deadlock, since no transaction ever waits.
Disadvantages: -
The DBMS validation-based protocol, also known as the Positive Concurrency Management
Technique, is a tool for preventing transaction rivalry. In this protocol, instead of the data itself,
the local copies of the transaction data are modified, resulting in less intrusion as the
transaction is executed.
1. Read phase
2. Validation phase
3. Write phase
Read phase
In the Read Process, a transaction may read the data values from the database, but only local
data copies, not the original database, are applied to write operations or updates.
Validation phase
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 28/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
The data is reviewed in the Validation Process to ensure that there is no breach of serializability
when adding transaction changes to the database.
Write phase
In the Write Process, if validation is successful, updates are added to the database; otherwise,
updates are not applied, and the transaction is rolled back.
Multifermion Concurrency Control (MVCC) is a way to control the consistency of data accessed
simultaneously by multiple users. The snapshot isolation guarantee is enforced by MVCC,
which guarantees that each transaction always sees a clear data snapshot.
When it begins, each transaction obtains a consistent data snapshot and can only access and
change data in this snapshot. When a transaction updates an entry, Ignite checks that other
transactions have not modified the entry and generates a new version of the entry. Only when
and if this transaction is successfully committed will the new version become available to other
transactions. If the entry has been modified, an exception to the current transaction fails.
Key takeaway:
- Locks are used as a means of synchronizing the access by concurrent transactions to the
database items.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 29/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
Recovery techniques are heavily dependent on the existence of a special file known as a
system log record and shadow page directory.
1. Shadow Paging.
Shadow Paging is a method of recovery that is used for database recovery. In this recovery
process, the database is considered to consist of fixed sizes of logical storage units referred to
as pages. With the support of the page table, pages are mapped into physical storage blocks
that allow for one entry for each logical database page. Two-page tables called the actual page
table and a shadow page table are used for this process.
The entries in the current page table are used to refer to the most recent pages of the database
on the disc. Another table, i.e., the Shadow Page Table, is used when the transaction that copies
the current page table begins.
After that, the shadow page table is saved on the disc, and for transactions, the actual page table
will be used. Entries present in the current page table can be updated during execution, but
they are never changed in the shadow page table. Both tables become similar after
transactions.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 30/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
Consider the figure above. Writing operations on page 3 and 5 are done in this 2. The new page
table points to the old page 3 before the start of the writing operation on page 3. The following
steps are carried out when the writing operation starts:
● After the free block is located, page 3 is copied to the free block represented by Page 3
(New).
● Now the present page table points to Page 3 (New) on the disc, but since it is not updated,
the shadow page table points to the old page 3.
● Changes are now propagated to Page 3 (New), where the existing page table points to.
Key takeaway:
- In this recovery process, the database is considered to consist of fixed sizes of logical
storage units referred to as pages.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 31/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
● Log is the most widely used structure for recording database modifications.
<Ti, X, V1, V2>: - Transaction Ti has performed write operation on X. Old value of x was V1 &
new value is V2.
● Whenever transaction performs write, a log record for that write is created.
● Once a log exists, we can output the modification to database if that is desirable.
● This ensures atomicity by recording all database modifications in the log, but deferring the
execution of all write operations in a transaction until transaction partially commits.
● When a transaction partially commits, the information in the log associated with the
transactions is used in executing deferred writes.
● If a system crashes before the transaction completes its execution, then the information on
the log is simply ignored.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 32/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
A = 100, B = 200, C = 50
T1: - R(A)
A: = A+100
W(A)
R(B)
B: = B-100
W(B)
T2: - R(C)
C: = C+50
W(C)
<T1, commit>
<T2, commit>
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 33/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
T1: = R(A)
A: = A+100
W(A)
R(B)
B: = B-100
W(B) → Case I
C = C+50;
Case I: - System comes back without taking any action because system fails before commit
operation. So, database has not been modified. Therefore, only log records are deleted.
<T1, commit>
In this case, when system failure occurs, T1 has been committed. So, the changes are
Recorded in the database. After this system fails, as database has been already modified, we
require new values of items. For this, redo(T1) is executed.
Case III: -
<T1, start>
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 34/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
<T1, commit>
<T2, start>
As T1 & T2 are committed log records are written to the database. So the database has been
modified & then system failure occurs. So, to retrieve modified values of database items,
redo(T1) & redo(T2) is executed.
● Database gets modifies immediately after write operation while the transaction is still in
active state.
I. Undo (Ti): - It restores the value of all data items updated by transaction, Ti to old values.
II. Redo (Ti): - IT sets the value of all data items updated by transaction, Ti to the new
Values.
Hints: -
T1 T2
R(A)
A: =A+100
W(A)
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 35/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
R(B)
B: = B-100 → Case I
W(B)
R(C) → Case II
C: = C+50
<T1, start>
Log record contains start but not commit. But as it is immediate database modification, database
has been modified before commit instruction. So, to maintain atomicity property, undo<T1> is
executed. So that original value of A will be achieved.
<T1, start>
<T1, commit>
<T2, start>
Log record for T1 contains both start & commit modifications are done on database &
T1has executed commit also. So, after failure, new values of A & B are required.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 36/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
For T2, start is recorded but not commit. It means modifications are reflected in the database
before commit. As per property of atomicity, to get original value of C, undo(T2) is issued.
Case III: - In this case, log record contains (start & commit) for both T1 & T2. So the
database has been modified & commit is executed for both T1 & T2. So, to get
modified values of A, B, & C Redo(T1) & Redo(T2) is issued.
Key takeaway :
- Database gets modifies immediately after write operation while the transaction is still in
active state.
- When a transaction partially commits, the information in the log associated with the
transactions is used in executing deferred writes.
- Log is the most widely used structure for recording database modifications.
There are some drawbacks of log-based recovery. In log-based recovery, log files are
maintained. But every time searching the entire log is time-consuming. So unnecessarily redo
transactions which have already output their updates to the database can take place.
So, the best solution is streamline recovery procedure by periodically performing check
pointing. Output all log records currently residing in main memory onto some stable storage.
The presence of <checkpoint> record in the log allows the system to streamline its recovery
procedure. Consider a transaction Ti has committed prior to the checkpoint. For such
transaction, < Ti commit> record appears in the log before the <checkpoint> record.
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 37/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
Any database modifications made by Ti must have been written to the database either prior to
the checkpoint or as part of the checkpoint itself. Thus, at recovery time, there is no need to
perform a redo operation on Ti.
1. Scan backwards from end of log to find the most recent <checkpoint> record
3. Need only consider the part of log following above start record. Earlier part of log can be
ignored during recovery, and can be erased whenever desired.
4. For all transactions (starting from Ti or later) with no <Ti, commit>, execute undo (Ti). (Done
only in case of immediate modification.)
5. Scanning forward in the log, for all transactions starting from T i or later with a <T i
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 38/39
3/1/23, 7:32 PM https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/seco…
● T2 and T3 redone.
● T4 undone
Key takeaway:
- Unnecessarily redo transactions which have already output their updates to the database
can take place.
- So, the best solution is streamline recovery procedure by periodically performing check
pointing.
References:
https://www.goseeko.com/reader/notes/savitribai-phule-pune-university-maharashtra/engineering/information-technology/second-year/sem-2/d… 39/39