0% found this document useful (0 votes)
181 views19 pages

Recoverability in DBMS

Uploaded by

sandhyabandaru89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views19 pages

Recoverability in DBMS

Uploaded by

sandhyabandaru89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

4.

TRANSACTION MANAGEMENT AND CONCURRENCY CONTROL

1. What is transaction ?explain.

Ans: transaction is a set of logically related operation. it contains a group tasks.

 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.

2.Describe in detail about transaction states?

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.

3.What is concurrency control in dbms?


Ans: Concurrent execution refers to the simultaneous execution of more than one transaction. This is a
common scenario in multi-user database environments where many users or applications might be accessing or
modifying the database at the same time. Concurrent execution is crucial for achieving high throughput and
efficient resource utilization. However, it introduces the potential for conflicts and data inconsistencies.
Advantages of Concurrent Execution

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.

Problems with Concurrent Execution

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)

Result: T1's updates are lost.


2.Temporary Inconsistency or Dirty Read Problem (Write-Read conflict):One transaction might read an
inconsistent state of data that's being updated by another.

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

3.What is schedule? Explain?


Ans: A series of operation from one transaction to another transaction is known as schedule. it is used to
preserve the order of the operation in each of the individual transaction.

Schedule

Serial schedule Non_Serial schedule

Serializable Non-Serializable

Conflict View Recoverable Non- Recoverable

Serializability Serializability Serializability serializability


starting another transaction. in the
Serial schedule: It is type of schedule where one transaction is executed completely before
serial schedule ,when the first transaction completes its cycle, then the next transaction is executed.

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.

Conflict: conflict is occur in below cases:

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

4.define testing of serializability?


Ans:There will be a directed graph G=(N,E) constructed with following rules.
1.create a node for each transaction
2.create a directed edge Ti---Tj if Tj reads the values of an item witten by Ti.

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)

A:=f1(A) B=f2(B) R(C)


W(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)

4. Write about Implementation of Isolation in DBMS

 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

 The highest isolation level.


 Guarantees full serializability and ensures complete isolation of transaction operations.

2. Repeatable Read

 This is the most restrictive isolation level.


 The transaction holds read locks on all rows it references.
 It holds write locks on all rows it inserts, updates, or deletes.
 Since other transaction cannot read, update or delete these rows, it avoids non repeatable read.

3. Read Committed

 This isolation level allows only committed data to be read.


 Thus it does not allows dirty read (i.e. one transaction reading of data immediately after written by
another transaction).
 The transaction hold a read or write lock on the current row, and thus prevent other rows from reading,
updating or deleting it.

4. Read Uncommitted

 It is lowest isolation level.


 In this level, one transaction may read not yet committed changes made by other transaction.
 This level allows dirty reads.
The proper isolation level or concurrency control mechanism to use depends on the specific requirements of a
system and its workload. Some systems may prioritize high throughput and can tolerate lower isolation levels,
while others might require strict consistency and higher isolation.

5. Explain about Concurrency control and lock based Protocols ?


Ans: Concurrency control protocol ensures atomocity,isolation and serializability of concurrent transaction.
The concurrence control protocol can be divided in to 3 categories
1. Simplistic lock based protocol
2. Validation based protocol
3.Time stamp based protocal

1) lock based protocol:


In these type of protocol any transaction can’t read or write data until it acquired an appropriate log on it. There
are 2 types of log
a. Shared lock : it is also known as read only log. In shared log the data item can only read by the transaction
b. Exclusive lock : in this the data item can be both read as well as write by the transaction

Types of Lock based Protocols :


There are 4 types
i. Simplistic Lock Protocol : it’s the simplest way of Locking the data while transaction. It allow all
transactions to get the lock on the data before insert or delete or update on it. It will unlock the data item after
completing that transaction.
ii. pre-claiming protocol : in these evaluate the transaction to list all data items on which they need locks
 Before initiating an execution of transaction, it request DBMS for all the Log on all those data item.
 If all the logs are granted then these protocol allows the transaction begin. When transaction complete then
it religious all the Log.
 If all the logs are not granted then these protocol allows. The transactions to roles back and wait until the all
logs are granted.
iii. Two phase Locking(2PL) protocol: it divides the execution phase of transaction in to 3 parts
 In the first part, the execution of a transaction starts, it seeks permission for the lock it requires.
 In the second part the transaction acquires all the log. The 3 rd phase started as soon as transaction religious
it’s first lock.
 In third phase the transaction can’t demand any new logs. It only religious the acquired locks

lock is attained
Lock is released

T begin T end time

There are 2 phases 2PL


growing phase: in these a new lock on the data item may be acquired by the transaction, but none can be
released.
Shrinking phase: in these existing Lock held by the transaction may be released, but no new locks can be
acquired

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

Lock is attained Release at commit

T begin T end time


2. Validation based protocol: it is also called as optimistic concurrency control technique. In this protocol the
transaction evaluated in the following 3 phase.
a) Read page: in this page the transaction T is read and executes it is executes is used to read the value of
various data items and stores them in temporary local variable .it can perform all the white operations on
temporary variable without any update to the actual data base.
b) Validate phase: in this page the temporary variable value will be validated against the actual data to see if it
violates serializability
c) Write phase: if the validation of the transaction is validated then the temporary results are written to the data
base or system otherwise the transaction is rollback,.
Here each phase as the following different time stamps
Start(TA) : it contents the time when TA is started it’s execution.
Validation(TI): it contents the time when TI Finishes its read phase and starts its validation phase .

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)

Basic Time Stamp ordering Protocol works as follows


1. check the following condition whenever transaction Ti issues a read(X) operations
 If W-TS(X)>TS(TI) then the operation rejected
 If W-TS(x)<=TS(TI) then the operation is executed
 Timestamp of all the data items are updated
2. Check the following condition a transaction Ti issues Write(X) Operation
 If TS(Ti)<R-TS(X) then the operation is rejected
 If TS(Ti)<W-TS(X) then the operation is rejected and Ti is Rollback otherwise the operation is
executed.

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)

6. Write about multiple granularity?


 Allow the data items to be of various sizes and define a hierarchy of data granularities, where the small
granularities are nested within larger ones
 Granularity is nothing but size of the data allowed to lock.
 It can be defined as hierarchically breaking up the data base into blocks which can be locked.
 The multiple granularity protocol enhances concurrency and reduce the lock overhead
 It maintains the track of what to lock and how to lock.
 It makes easy to decide either to lock a data or to unlock data item. this type of hierarchy can be
graphically represented as a tree.

Example: consider a tree which has four levels of nodes

1the first level or higher level shows the entire db.


2. The second level represents a node of type area. The high db consists of exactly these areas.
3. The area consists of child nodes known as files .they can be present is more than one area.
4. Finally, each file contains child nodes known as records. The exactly those records that are its child nodes..
No records represents more than one file.
5. The levels of tree starting from the top level are.

i. DB ii. Area iii File iv. Record

DB

A1 A2

F2 F4
F1 F3

R1 Rn
R3 R4 ------- -- -- --- -- ---
R2

Compatibility Matrix with Lock Modes in multiple granularity

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 | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |

(NL = No Lock, S = Shared, X = Exclusive)

7. Explain in detail about Recovery and Atomicity?

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:

i. Check the states of all ‘T’ Which all being executed.


ii. A transaction may be in the middle of some operation, ensure atomicity.
iii. Whether the ‘T’ can be completed or rolled back.
iv. No ‘T’ leaves in inconsistent state.

8. What are the Recovery methods?


Recovery can be done in two ways:
1. Log based recovery
2. Concurrency transaction recovery

Log based recovery:


Log is stored each and every action of transaction, whether the starting of transaction ‘T’ or whether the
modification of transaction ‘T’ is successfully completed. Log is written before action.
Log file is kept on a stable storage.
Log format as follows below:

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

DB can be modified in 2 ways:

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 ‘.

Recovery with Concurrent transactions:

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

check point time

You might also like