Module 6 - Transactions Management- Concurrency and Recovery - 1
Module 6 - Transactions Management- Concurrency and Recovery - 1
AND RECOVERY
29-Sep-24 COMPILED BY MRS. JISHA TINSU, TCET 1
WHAT IS A
TRANSACTION?
▪A transaction is a single logical unit of
work that accesses and possibly modifies
the contents of a database. Transactions
access data using read and write
operations.
▪Example: A bank transfer operation
involves debiting an amount from one
account and crediting it to another.
▪If the transaction fails after completion of T1 but before completion of T2(say, after
write(X) but before write(Y)), then the amount has been deducted from X but not
added to Y . This results in an inconsistent database state. Therefore, the transaction
must be executed in its entirety in order to ensure the correctness of the database
state.
29-Sep-24 COMPILED BY MRS. JISHA TINSU, TCET 9
ACID PROPERTIES: CONSISTENCY
▪ Guarantees that a transaction will bring the database from one valid state
to another. No transaction should violate any of the integrity constraints of
the database.
▪ This means that integrity constraints must be maintained so that the database
is consistent before and after the transaction. It refers to the correctness of a
database. Referring to the example above, After a transaction, the sum of
credits and debits in a banking system should be consistent (no loss or
creation of money).
The total amount before and after the transaction must be maintained.
Total before T occurs = 500 + 200 = 700 .
Total after T occurs = 400 + 300 = 700 .
▪ Therefore, the database is consistent . Inconsistency occurs in case T1
completes but T2 fails.
29-Sep-24 COMPILED BY MRS. JISHA TINSU, TCET 10
ACID PROPERTIES - ISOLATION
▪ The term 'isolation' means separation. In DBMS, Isolation is the property of a
database where no data should affect the other one and may occur
concurrently.
▪ In short, the operation on one database should begin when the operation on the
first database gets complete.
▪ It means if two operations are being performed on two different databases,
they may not affect the value of one another. In the case of transactions, when
two or more transactions occur simultaneously, the consistency should remain
maintained.
▪ Ensures that the intermediate state of a transaction is invisible to other
transactions. Transactions are isolated from one another to avoid interference.
▪ Example: Two transactions running concurrently should not affect each other's
operations.
A=5000
W(A); A=5500
The precedence
T1 T2 graph for schedule
S1 contains a cycle
that's why Schedule
S1 is non-
serializable.
T3
The precedence
T4 T5 graph for schedule
S2 contains no cycle
that's why
ScheduleS2 is
serializable.
T6
The cycle is present, so it is non conflict serializable. The cycle is not present, so it is conflict serializable.
Now,
•Since, the given schedule S is not conflict serializable, so, it may
or may not be view serializable.
•To check whether S is view serializable or not, let us use
another method.
29-Sep-24 •Let us BYcheck
COMPILED forTINSU,
MRS. JISHA blind
TCET writes. 51
▪Now,
•To check whether S is view serializable or not, let us use another method.
•Let us derive the dependencies and then draw a dependency graph.
▪Drawing a Dependency Graph-
•T1 firstly reads A and T3 firstly updates A.
•So, T1 must execute before T3.
•Thus, we get the dependency T1 → T3.
•Final updation on A is made by the transaction T1.
•So, T1 must execute after all other transactions.
•Thus, we get the dependency (T2, T3) → T1.
•There exists no write-read sequence.
▪Solution-
Alternatively,
•You could directly declare that the given schedule S is not view serializable.
•This is because there exists no blind write in the schedule.
•You
29-Sep-24need not check for conflict serializability.
COMPILED BY MRS. JISHA TINSU, TCET 60
SERIAL SCHEDULES VS SERIALIZABLE
SCHEDULES-
Table 1
The above Table 3 shows a schedule with two transactions. Transaction T1 reads
and write A and commits, and that value is read and written by T2. So, this is a
cascade less recoverable schedule. But if T1 fails before commit, no other
transaction has read its value, so there is no need to rollback other transaction.
29-Sep-24 COMPILED BY MRS. JISHA TINSU, TCET 68
STRICT SCHEDULE
▪A schedule is strict if it is both recoverable and
cascades.
▪In a strict schedule, a transaction that has read
uncommitted data from another transaction cannot
commit before that transaction commits, and a
transaction that has updated the database must
commit before any other transaction reads or writes
the same data.
▪If a transaction fails before committing, its updates
must be rolled back, and any transactions that have
read its uncommitted data must also be rolled back.
29-Sep-24 COMPILED BY MRS. JISHA TINSU, TCET 69
RECOVERY FROM TRANSACTION FAILURES
▪Database Systems like any other computer system, are subject to failures but
the data stored in them must be available as and when required.
▪When a database fails it must possess the facilities for fast recovery.
▪It must also have atomicity i.e. either transactions are completed successfully
and committed (the effect is recorded permanently in the database) or the
transaction should have no effect on the database.
▪Types of Recovery Techniques in DBMS:
▪Rollback/Undo Recovery Technique
▪Commit/Redo Recovery Technique
▪Checkpoint Recovery Technique
2. <Ti, Xj, V1, V2> .................... Transaction Ti has performed a write on data item Xj.
Xj has a value V1 before write & will have value V2 after write