Recoverability in DBMS
Recoverability in DBMS
A transaction is an action or series of action. it is performed by a single user to perform operations for
accessing the contents of the data base.
Eg: suppose an employee of bank and transfers Rs. 800/ from x’ a/c to y’ a/c. this small transaction
contains several low level tasks.
X’s A/c
1.open account (x)
2.old balance =x.bal
3.new bal=old bal-800
4.x.bal=new bal
5.close account (x)
Y’s a/c
1.open account (y)
2.old balance=y.bal
3.new bal=old bal+800
4.y.bal=new bal
5.close account (y)
Transaction property: ACID properties: the transaction has the 4 properties.
These are used to maintain consistency in a database, before and after the transaction.
1Atomicity
2.consistency
3.Isolation
4.Durablity
1Atomicity:It state that all operations of the transactions take place at ones if not, the transaction is
aborted.
There is no mid way eg: the transaction can not occur partially. each transaction is treated as 1
unit and either run to completion or is not executed at all.
Atomicity involves the following two operations
Abort: if a transaction aborts then all the changes made or not visible.
Commit: if a transaction commit then all the changes made or visible.
Eg: let assume that the following transaction T consisting of T1 and T2.
A consists of RS. 600/ and B consists of Rs. 300/ -.transfer Rs. 100 from a/c A to A/c B.
T1 T2
Read(A) Read(B)
A=A-100 Y=Y+100
Write(A) Write(b)
After completion of the transaction a consists of Rs.500/ an d consists of Rs 400/
The transaction T fails after the completion of transaction T1,but before completion of
transaction of T2.then the amount will be deducted from A but not added to B .this shows the in
consists database state. In order to ensure correctness of database table. the transaction must be
executed entirely.
2.Consistency:the integrity constraints are maintained so that database is consistent before and
after the transaction
The execution of transaction will leave a database in either its trior stable state or new
stable state.
The consistent of property of database state that every transaction sees a consistent
database instants.
The transaction is used to transform database from one consistent stable to another
consistent state.
Eg: the total amount must be maintained before or after the transaction
1.total before T occurs =600+300=900
2.Total after T occurs=400+500=900
There fore the database is consistent in the case when T1 is completed but T2 fails.then
inconsistent will occur.
3.Isolation:it shows that the data which is used at the time of execution of a transaction can’t
be used by the 2 transaction until the 1 one completed.
In isolation with transaction T1 is being executed and using the data item X. then that
data item can’t be access by any other transaction T2 until the transaction T1 ends.
The concurrency control subsystem of the dbms. enforce the isolation property
4.Durability:it is used to indicate the performance of the databases consistent state. its state
that the transaction made the performance.
Ans: The transaction is set logically related operations it contains group of operations. follow the transaction
state diagram .
These are different types of Transaction States :
1. 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”.
2. 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”.
3. 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.
4.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.
5. 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”.
6.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.
1. Increased System Throughput: Multiple transactions can be in progress at the same time, but at
different stages
2. Maximized Processor Utilization: If one transaction is waiting for I/O operations, another transaction
can utilize the processor.
3. Decreased Wait Time: Transactions no longer have to wait for other long transactions to complete.
4. Improved Transaction Response Time: Transactions get processed faster because they can be
executed in parallel.
1. Lost Update Problem (Write-Write conflict):One transaction's updates could be overwritten by another.
Examples:
T1 T2
read(A)
A=A+50
Read(A)
A=A+100
write(A)
Write(A)
Examples:
T1 T2
Read(A)
A=A+50
Write(A)
Read(A)
A=A+100
Write(A)
Read (A)rollback
commit
Result: T2 has a "dirty" value, that was never committed in T1 and doesn't actually exist in the database.
3. Unrepeatable Read Problem (Read-Write conflict):when a single transaction reads the same row multiple
times and observes different values each time. This occurs because another concurrent transaction has modified
the row between the two reads.
Examples:
T1 T2
Read(A)
Read(A)
A=A+100
Write(A)
Read(A)
Result: Within the same transaction, T1 has read two different values for the same data item. This
inconsistency is the unrepeatable read.
To manage concurrent execution and ensure the consistency and reliability of the database, DBMSs use
concurrency control techniques. These typically include locking mechanisms, timestamps, optimistic
concurrency control, and serializability checks
Schedule
Serializable Non-Serializable
T1 T2
R(A);
A:=A+100:
W(A);
R(A);
A:=A+100;
W(A):
Non_serial schedule: If interleaving of operations is allowed, then there will be non serial schedule.
T1 T2
R(A):
A:=A-100;
R(A);
A:=A+100;
W(A);
R(B);
W(A);
B:=B+100;
W(B);
Serializable schedule: the serializability of schedule is used to find non_serial schedule that allows the
transaction to execute concurrently without interfering with one another.(i.e. A schedule with no overlapping
transaction)
In this transaction said to serializble which result inconsistency or conflict result in the data.
R(A)---------W(A)
W(A)---------W(A)
W(A)---------R(A)
Non_conflict:
R(A)----------R(B)
W(A)---------R(B)
R(B)----------W(A)
W(B)----------R(A)
Conflict seriazability:if it can be transformed into a serial schedule (i.e a schedule with no overlapping
transaction) by swapping non –conflict operations.
T1 T2
R(A)
W(A)
R(B)
Before swap W(B) After Swap
T1 T2
R(A)
W(A) R(A)
W(A)
R(B)
T1 T2
R(A) W(B)
W(A)
R(B)
W(B)
R(B)
W(B)
View serializability: A schedule is called view serializable ,if it is view
equal to a serial schedule (no over lapping transaction).A conflict schedule is view serializable ,but if the
serializability contains blind writes, then the view serializable doesn’t conflict serializable.
T1 T2
T1 T2
R(A) R(A)(100) T1 T2
W(A) R(A)
W(A)140(100 W(A)
W(A) +40)
W(A) W(A)
90(140-50)
Non-serial Schedule: the schedule in which operations present with in the transaction are inter mixed. this may
lead to conflict in the result or in consistency in the result data.
Recoverable schedule: A schedule is recoverable if each transaction commits only after all the transactions
from which it has read have committed. In other words ,if some transaction T2 read a value that has been
updated/written by some other transaction T1,then the commit of T2 must occur after the commit of T1.
T1 T2
R(A)
W(A)
R(A)
W(A)
Abort
commit
The schedule shown above is recoverable since T1 commit before T2 ,which makes the values read by T2
correct.
Non- Recoverable schedule: if a transaction reads the value of an operation from an un committed transaction
and commits before the transaction from where it has read the value ,then such a schedule is called non-
recoverable schedule. A non- recoverable schedule means when there is a system failure, we may not be able to
recover to a consistent database state, if the commit operation of ti doesn’t occur before the commit operation of
tj, it is non-recoverable.
T1 T2
R(A)
W(A)
R(A)
W(A)
commit
3. create a directed edge Ti---Tj if Tj writes a values of an item after Ti read it.
4. create a directed edge Ti---Tj if Tj writes the values of an item after Ti wrote it.
The precedence directed graph is a cyclic then only the schedule is serializable.
Ti W(X) Ti R(X) or W(X)
Tj R(X) Tj W(X)
T1 T2 T3
R(A)
R(B)
C=f3(C)
W(C)
T1 T2
W(A)
R(A) R(B)
A=f4(A)
T3
R(C)
W(A)
C=f5(C)
W(C)
B=f6(B)
W(B)
T4 T5 T6
R(a)
A:=f1(a)
R(C)
W(A) T4 T5
A:=f2(C)
R(B) T6
W(C)
R(A)
R(C)
B:=f3(B)
W(B)
C:=f4(C)
R(B)
W(C)
A:=f5(A)
W(A)
B:=f6(B)
W(B)
Ans: Isolation is one of the core ACID properties of a database transaction, ensuring that the operations
of one transaction remain hidden from other transactions until completion. It means that no two
transactions should interfere with each other and affect the other's intermediate state.
Isolation Levels:Isolation levels defines the degree to which a transaction must be isolated from the
data modifications made by any other transaction in the database system. There are four levels of
transaction isolation defined by SQL -
1. Serializable
2. Repeatable Read
3. Read Committed
4. Read Uncommitted
lock is attained
Lock is released
iV.Strict Two phase locking(Strict 2PL): the first phase of strict 2PL is similar to 2PL. in the first phase
after acquiring all the locks the transaction continue to execute normally
The only difference between 2PL and Strict 2PL is that Strict 2PL doesn’t release a Lock After Using it.
Strict 2PL waits until the whole transaction to commit,and then it religious all the locks at a time.
Strict 2PL protocol doesn’t have shrinking phase of lock released.
It doesn’t have cascading abort as 2PL does
3. Time stamp based protocol: it maintains the order of transaction based on their time stamp
A time stamp is unique identifier that is been created by DBMS then a transaction enters in to system. This
time stamp can be based on the system clock of a logical counter maintain in the system.
Time stamp helps identifying the older transaction and gives them higher priority compared to the newer
transactions. This make sure that none of the transactions are pending for a period of time.
TS(T1) the time stamp of the transactions
R-TS(x) the read time stamp Ti of the data item X
W-TS(x) the write operation of data item X
TS(Ti) T1=10(old)
T2=20(younger)
T3=30(younger/bigger)
T1 T2
R(A)
W(A)
10 20
T1 T2
R(A)
W(A)
10 20
T1 T2
R(A)
Executed
W(A)
10 20
T1 T2
W(A)
R(A)
10 20
T1 T2
W(A)
W(A)
DB
A1 A2
F2 F4
F1 F3
R1 Rn
R3 R4 ------- -- -- --- -- ---
R2
A compatibility matrix defines which types of locks can be held simultaneously on a database object.
Here's a simplified matrix
| | NL | IS | IX | S | SIX | X |
|:-----:|:-----:|:------:|:-----:|:------:|:-----:|:------:|
| NL | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| IS | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ |
| IX | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ |
| S | ✓ | ✓ | ✗ | ✓ | ✗ | ✗ |
| SIX | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ |
| X | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
Answer:
A schedule is recoverable, if each transaction commits only after all the transactions from which it has read
have committed. In other words, if some transaction T2 read a value that has been updated/written by some
other transaction T1, Then commit of T2 must occur after the commit of T1.
Atomicity states that all operations of the transaction take place at once if not, the transaction is
aborted. There is no mid way, i.e the transaction cannot occur partially. Each transaction is treated as one unit
and either run to completion or is not executed at all.
Classifications of Failure:
1.Transaction Failure
a. Logical errors
b. System errors
2. System crash
3. Disk failure
4. Storage structure failure
a. Volatile storage
b. Non-volatile storage
When a DBMS recovers from a crash:
When T starts:<Tn,start>//Tn-‘T’-ID
-- ‘T’ modifies X(eg: ‘x’ is marks/attendance)
<Tn,X,V1,V2>//(V1=25(old value,v2=45(new value))
-’T’ finishes: <Tn,commit>// log using id,commit
1. Deferred DB modification:
The data can be stored in the Database after all the operations transaction are successfully committed.
This process is also called as ‘Redoing’
2. Immediate DB modification
In this method, the data can be stored in database for each and every modification of transaction.
It is also called as’ Undoing ‘.
While doing multiple transactions at a time, if any modifications occurs in the flow of transaction then it is
necessary to recover it. Checkpoint plays an dynamic role in this recovery method.
T1 commit
T2 commit
T3 commit