0% found this document useful (0 votes)
12 views46 pages

Unit-6 DBMS by Prof. C.A. Tripathi

The document discusses concurrency control mechanisms in database management systems including lock-based protocols, timestamp-based protocols, and validation-based protocols. It also covers topics like deadlock handling, recovery systems, log-based recovery, and checkpoints.

Uploaded by

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

Unit-6 DBMS by Prof. C.A. Tripathi

The document discusses concurrency control mechanisms in database management systems including lock-based protocols, timestamp-based protocols, and validation-based protocols. It also covers topics like deadlock handling, recovery systems, log-based recovery, and checkpoints.

Uploaded by

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

Presentation on

Database Management System

UNIT NO.-06

By
Prof. C.A.TRIPATHI

Department of COMPUTER SCIENCE & ENGINEERING


YESHWANTRAO CHAVAN COLLEGE OF ENGINEERING

By Prof. C.A.TRIPATHI 1
Unit 6 Syllabus

Concurrency Controls: Lock Based Protocol, Time-stamp Based


Protocols, and Validation Based Protocols Deadlock Handling.

Recovery System: Failure Classification, recovery and


atomicity,Log Based Recovery, checkpoints, buffer
management, Advanced Recovery Techniques.

By Prof. C.A.TRIPATHI 2
Concurrent Execution of Transaction

Its a mechanism of running multiple transactions at a time, which perform


various database updates simultaneously.

Its similar to the concept of multi programming in OS.

Two reasons for allowing concurrent execution of transactions

Improved throughout and resource utilization:


Transaction may involve set of activities such as I/O and CPU activity.

Reduced Waiting Time :


short transaction may require to wait for long time for preceding long transaction to
complete.

By Prof. C.A.TRIPATHI 3
Concurrent Execution of Transaction Example

By Prof. C.A.TRIPATHI 4
Concurrent Execution Problem

When concurrent transactions are executed in an uncontrolled manner,


several problems can occur.

Lost Updates

Dirty Read

Unrepeatable
Read

By Prof. C.A.TRIPATHI 5
Lost Update problem

A lost update problem occurs when two transactions access the same database items and
update made by one transaction is overwritten by another transaction causing
inconsistency in database.

By Prof. C.A.TRIPATHI 6
Dirty Read Problem

A dirty read problem occurs when one transaction update database item and then
transaction fails for some reason but another transaction access updated database item
before it is changed back to original value.

By Prof. C.A.TRIPATHI 7
Unrepeatable Read Problem

Unrepeatable read problem occurs when one transaction performs some aggregate
function over a set of data while other transaction carry out
some changes over same set of data.

so first transaction may read some data before they are changed and some data
after they are changed, which results in inconsistent result to be produced by first
transaction.

By Prof. C.A.TRIPATHI 8
Unrepeatable Read Problem

By Prof. C.A.TRIPATHI 9
C o ncurrency C o ntrol
concurrency control mechanism can control an access to database by number
of transaction simultaneously.

Concurrency control helps to maintain data integrity of respective database and


it
can be use in system such as
- Joint account
- Reservation of ticket

It can be implemented by using one of the following protocol.


1) Lock based protocol
2) Timestamp based protocol
3) Graph based protocol
4) Validation based protocol
By Prof. C.A.TRIPATHI 10
Lock based protocol

To ensure serializability we require data item to be accessed in mutually


exclusive manner.

Concept of looking is use to solve concurrency problem.

-A lock can be applied on data item in two modes

a) Shared Mode: any number of other transactions can be allowed to read


data item Q along with Ti , but its not able to write data item Q.

b)Exclusive Mode: Ti can read & write data item Q, but no other transaction allow
to either read or write same data item.

By Prof. C.A.TRIPATHI 11
Two Phase Locking Protocol

Growing Phase :
In this phase transaction can only acquire locks but can not release any lock.
A transaction reaches a point where all locks that it needs has been acquired then this
point is called lock point.

Shrinking Phase :
Once transaction reaches to lock point, it enters into shrinking phase where it can only
release locks one by one but can not acquire new lock.

There are 2 versions of two phase locking protocol


Strict two phase locking protocol : transaction may release all shared lock after
lock point has been reached but it can not release exclusive lock until transaction
commits.

Rigorous two phase locking protocol


Here transaction is not allowed to release any lock either shared or exclusive until it
commits.

By Prof. C.A.TRIPATHI 12
Guarantying serializability by 2 phase locking protocol

The serializability of transaction schedule can be guaranteed by using


two phase locking protocol.

By Prof. C.A.TRIPATHI 13
Time Stamp Based
Algorithm
Time stamp is a unique identifier or tag attached to any transaction or any data item
which denote specific time on which transaction or data item is activated.
Time stamps can be generated in 2 ways

using current data time val of system clock.


Use logical counter

By Prof. C.A.TRIPATHI 14
Basic Time Stamp Ordering Algorithm

By Prof. C.A.TRIPATHI 15
Validation Based Protocol

It works in 3 phases

Read Phase: During this phase Ti reads values of various data items & store
them in its local variable, without updating it to actual database.

Validation Phase: During this phase Ti determines that whether updating of


actual database cause violation of serializability or not.

Write phase: If validation is successful then system apply actual updates


to database.

By Prof. C.A.TRIPATHI 16
Nested Transactions

Its a hierarchical relationship of master and sub-transactions.

Master transactions can start one or more sub transactions & each of the sub
transactions can, in turn instantiate one or more sub-sub-level transactions.

By Prof. C.A.TRIPATHI 17
Two Phase Commit Protocol :

It is used to synchronize updates on two or more databases that run on physically


different computers.

It involves two agents coordinator and participant.

Two phase commit protocol works in two phase as


Prepare Phase
Commit phase

By Prof. C.A.TRIPATHI 18
Prepare Phase (Voting Phase):

The coordinator sends a query to commit message to all Participants and waits
until it has received a reply from all Participants.

Each Participants replies either yes or no.

By Prof. C.A.TRIPATHI 19
Commit Phase

If coordinator receives a ready to commit reply from all participants in phase I then

It send commit message to all participants

Else
It send abort message to all participants.

By Prof. C.A.TRIPATHI 20
Deadlock

A deadlock is a situation where two or more transactions are waiting for


each other to release lock and none of them can continue as each
transaction in the set is on a waiting queue.

By Prof. C.A.TRIPATHI 21
Deadlock Detection :

A deadlock can be detected for any system by constructing a wait for


graph for this system.

By Prof. C.A.TRIPATHI 22
Deadlock Prevention

1. No cyclic wait

In this approach system avoid formation of cycle by using below 2 ways.

a)Lock all data item initially

Lock all data items initially before it begins it’s execution.

b) Put ordering on data item

Transaction lock data item only in sequence consistent with the ordering.

2.Use of preemption and Rollback

By Prof. C.A.TRIPATHI 23
Deadlock Prevention

3 Using time stamp

a)Wait Die Scheme (Non preemptive)

B Wound wait scheme (Preemptive)

By Prof. C.A.TRIPATHI 24
Recovery from Deadlock

1) Selection of a victim
Many factors may determine cost of rollback including
a. How long transaction has completed & how much longer transaction will
compute before it completes it’s task.
b. How many data item used by transaction.
c. How many more data items transaction needs to complete.
d. How many transactions will be involved in rollback.

2 Roll back

3 Starvation:
Transaction can be picked as victim for finite number of times.

By Prof. C.A.TRIPATHI 25
Recovery System

It brings database from inconsistent state to a previously consistent state.

It helps to recover from following Types of failure.

Transaction Failure
Logical error :For example bad input, data not found.
System error : for example deadlock
System Crash :

Disk Failure:

26
By Prof. C.A.TRIPATHI
Storage Types

Volatile Storage :

Non-volatile Storage:

Stable Storage :

27
By Prof. C.A.TRIPATHI
Types of Database Recovery

- Forward Recovery

- Backward Recovery

- Media Recovery

- Crash Recovery

28
By Prof. C.A.TRIPATHI
Forward Recovery (or REDO)

It is used in case of physical damage for eq. Crash of disk.

It guarantees durability property of transaction.

29
By Prof. C.A.TRIPATHI
Backward Recovery (or UNDO)

It is used in case an error occurs in the mid of normal operation on the database.

It guarantees the atomicity property of transaction.

30
By Prof. C.A.TRIPATHI
Crash Recovery

It’s a recovery which can be done after system crashes due to


hardware malfunction or bug in database s/w or operating system.
It uses Write ahead logging rule.

Ti enters commit state after <Ti, commit> log records has been output to stable
storage.

Before block of data in main memory can be output to database all log records of
data in that block have been output to stable storage.

Before <Ti, commit> log record can be output to stable storage all log records
related to transaction Ti have been output to stable storage.

31
By Prof. C.A.TRIPATHI
Media Recovery

The recovery which is performed after disk head crash is


called as media recovery.

Generally media recovery can be performed in following 2


steps

(1) Restore or Reload database from it’s Backup or dump.

(2) System log is then used to redo all changes.

32
By Prof. C.A.TRIPATHI
Recovery Techniques

(1) Log based recovery


(2) Shadow paging

Log Based Recovery Technique


The database maintain below information about transaction.

Transaction identifier
Data Item Identifier :
Old Value
New Value :
<Ti, start> :
<Ti, commit>
<Ti, abort> :
<Ti, XJ, V1, V2>

33
By Prof. C.A.TRIPATHI
Log Based Recovery Technique
D e f e rre d d a t a b a s e Modification or D e f e rre d
Update
Updates are not written to disk until transaction has reached it’s
commit point.

Updates to database is postponed until transaction completes it’s


execution successfully and reaches it’s commit point.

I m m e d i a t e d a t a b a s e modification or I m m e d i a t e
Update

All updates to database are applied immediately a s they occur


without waiting to reach the commit point.

Record of all changes kept in transaction log.


34
By Prof. C.A.TRIPATHI
Shadow Paging

The database is partitioned into number of fixed length blocks, are referred
a s pages

35
By Prof. C.A.TRIPATHI
Shadow Paging

. Advantages of shadow paging


- Less disk access
- Log record overhead is not there
-No Undo/Redo operation is required, so recovery becomes faster.

-Disadvantages :

Commit overhead :
To commit one transaction shadow paging needs to copy current page table
to non volatile storage.:

36
By Prof. C.A.TRIPATHI
Advanced Recovery Techniques

Transaction Rollback
The system scan the log backward and uses log records belonging to transaction to
restore old values of data items.

Checkpoint
Its like a snapshot of the DBMS state. By taking checkpoints, the DBMS can reduce
amount of work done during restart in the event of subsequent crash.

A better way is to find a point that is sufficient to go back to ensure that any item written
before that point has been done correctly and stored safely, this method is called
checkpointing.

37
By Prof. C.A.TRIPATHI
Checkpoint
Advantages :
- Checkpoint technique is used to limit
- Volume of log information
-Amount of searching
- It reduces the time required for recovery after crash.
-It helps to clear log records from stable storage as it gets full.

38
By Prof. C.A.TRIPATHI
Advanced Recovery Techniques

Restart Recovery
Phase I :
-In the redo phase system replays updates of all transactions by scanning the log
forward from last checkpoint.

Phase II :
- In the undo phase system roll back all transactions in the undo list.

39
By Prof. C.A.TRIPATHI
Advanced Recovery Techniques ARIES Algorithm

ARIESuses a number of techniques to reduce the time taken for


recovery and to reduce overhead of checkpointing.

Each log record inARIES has a log


se quence num b er (LS N ) that uniquely identifies
record.

ARIES recovery algorithm works in following 3 phases

1) Analysis Phase :
This phase determines which transaction to undo and L S N from
which
redo pas s should start.

2) Redo Phase :
The Redo phase scan the log record forward from Redo L S N to
bring database to state it was in before crash.
40
By Prof. C.A.TRIPATHI
Advanced Recovery Techniques

Undo Phase :
It will rollback all transaction that were incomplete at the time of
crash. actually it performs backward scan of log record.

41
By Prof. C.A.TRIPATHI
Buffer Management
•A buffer is the part of main memory which is use to hold data temporarily.
•Buffer manager is responsible for handling buffer.
•Buffer manager controls movement of data between main memory and disk.

42
By Prof. C.A.TRIPATHI
Buffer Management
Buffering is of two types as
Log Record Buffering & Database Buffering
Log Record Buffering
• Its necessary to output the every log Record to stable storage at time when
it is created, but this impose high overhead on system.

• It is desirable to output multiple log record at once.

•Multiple log records can be gathered in buffer and output it to stable storage in single output
operation.
Set of Rules ensure recovery if system crashes

•Transaction Ti enters commit state after <Ti, commit> log record has been output to stable storage.

•Before <Ti, commit> log record can be output to stable storage, all log records related to
transaction Ti have been output to stable storage.

•Before block of data in main memory can be output to database all log records of data in that
block have been output to stable storage.

43
By Prof. C.A.TRIPATHI
Buffer Management
Database Buffering

•The system stores database in disk & brings block of data into main memory when
needed.
•When we need to bring block B2 into main memory to perform certain operation on it,
but if enough space is not available in main memory then we need to replace some block
to disk to bring B2.
•So we will keep B2 into buffer until B1 brought to disk.

Sequence of action taken by system before replacing B1 to disk as follows

•Output all log records related to B1 to stable storage.

•Output block B1 to disk.

•Input the block B2 to main memory.

44
By Prof. C.A.TRIPATHI
Roll of O S in Buffer Management

Using part of main memory :

•The operating system allows database system to reserve part of main memory to serve as a buffer.

•The operating system make sure that buffer is kept as small enough so that other
applications have sufficient main memory available for their need.

Using Virtual Memory :

•The database system implements it’s buffer within virtual memory provided by operating
system.

•If database buffer is in virtual memory, transfer between database files and buffer in virtual memory
must be managed by database system.

45
By Prof. C.A.TRIPATHI
Thank
s
By
Prof. C.A.TRIPATHI
(YCCE)

By Prof. C.A.TRIPATHI 46

You might also like