Unit-6 DBMS by Prof. C.A. Tripathi
Unit-6 DBMS by Prof. C.A. Tripathi
UNIT NO.-06
By
Prof. C.A.TRIPATHI
By Prof. C.A.TRIPATHI 1
Unit 6 Syllabus
By Prof. C.A.TRIPATHI 2
Concurrent Execution of Transaction
By Prof. C.A.TRIPATHI 3
Concurrent Execution of Transaction Example
By Prof. C.A.TRIPATHI 4
Concurrent Execution Problem
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.
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.
By Prof. C.A.TRIPATHI 12
Guarantying serializability by 2 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
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.
By Prof. C.A.TRIPATHI 16
Nested 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 :
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.
By Prof. C.A.TRIPATHI 19
Commit Phase
If coordinator receives a ready to commit reply from all participants in phase I then
Else
It send abort message to all participants.
By Prof. C.A.TRIPATHI 20
Deadlock
By Prof. C.A.TRIPATHI 21
Deadlock Detection :
By Prof. C.A.TRIPATHI 22
Deadlock Prevention
1. No cyclic wait
Transaction lock data item only in sequence consistent with the ordering.
By Prof. C.A.TRIPATHI 23
Deadlock Prevention
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
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)
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.
30
By Prof. C.A.TRIPATHI
Crash Recovery
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
32
By Prof. C.A.TRIPATHI
Recovery Techniques
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.
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
The database is partitioned into number of fixed length blocks, are referred
a s pages
35
By Prof. C.A.TRIPATHI
Shadow Paging
-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
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.
•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.
44
By Prof. C.A.TRIPATHI
Roll of O S in Buffer Management
•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.
•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