0% found this document useful (0 votes)
7 views

Unit 4 Concurrency Control

Concurrency control
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Unit 4 Concurrency Control

Concurrency control
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 111

DATABASE MANAGEMENT UNIT -4

TRANSACTION
SYSTEMS MANAGEMENT

© Kalasalingam academy of research and education


Course Outline:

Course description:
CO 1 Apply the database management
system concepts. This course is designed to introduce under
graduate students to the foundations of
CO 2 Design relational and ER model for
database design. database systems, focusing on basics such as
the relational algebra and data model, schema
CO 3. Examine issues in data storage and query normalization, query optimization, and
processing and frame appropriate solutions.
transactions.
CO 4. Analyze the role and issues like efficiency, privacy,
security, ethical responsibility and strategic advantage in
data management

CO 5. Build applications to schedule concurrent


executions with recovery mechanisms.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Syllabus
Transaction Concepts – Transaction Recovery –
ACID Properties –Need for Concurrency
Control – Schedule and Recoverability-
Serializability and Schedules – Concurrency
Unit 4
Control – Types of Locks- Two Phases locking-
Deadlock- Time Stamp based Concurrency
Outcomes
Control – Recovery Techniques – Concepts -
Immediate Update - Deferred Update - Shadow CO4:
Paging.
Analyze the role and issues like efficiency, privacy,
security, ethical responsibility and strategic
advantage in data management

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Unit 4 TRANSACTION MANAGEMENT

Analyze the role and issues like efficiency,


Lesson 1.
privacy, security, ethical responsibility and
strategic advantage in data management
Lesson 2. Serializability and schedules

Lesson 3. Two phase locking

Lesson 4. Deadlock and Timestamp based


Concurrency Control

Lesson 5. Database Recovery Techniques

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Reference:

Abraham Silberschatz, Henry F. Korth and Sudarshan S., Database System Concepts, McGraw-Hill , 6th
Edition, 2011.
Ramez Elmasri and Shamkant B. Navathe. Fundamental Database Systems, Addison-Wesley, 5th
Edition, 2005.
Raghu Ramakrishnan, Database Management System, Tata McGraw-Hill, 3rd Edition, 2006.
Hector Garcia-Molina, Jeff Ulman and Jennifer Widom, Database Systems: The Complete Book,
Prentice Hall, 2003.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Lesson 1:Definition of Transaction

Various data items are accessed and updated by a unit of program execution is called transaction.
Eg. An amount of 50 dollar is transferred from Account X to Account Y.
There are many issues to deal with transaction.
There might be hardware and software crashes and failures.
Multiple transactions are executed parallely.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Transaction

© Kalasalingam academy of research and education COURSE NAME


Transaction

© Kalasalingam academy of research and education COURSE NAME


Initial state - Active State

The initial state of transaction is the active state.


Transaction is performed with read or write operations.
These operations lead to two different states.
When transaction is successful, it leads to partially committed state.
When transaction fails, it goes to failed state.

© Kalasalingam academy of research and education COURSE NAME


Second state - Partially Committed

The changes in the transaction happen due to read/write operations.


These changes will be saved in memory.
When commit is done, transaction is permanently saved.
After this, old transaction is terminated.
New transaction is ready to execute.

© Kalasalingam academy of research and education COURSE NAME


Failed State

When transaction is failed, it goes to two states.


A transaction is aborted once it is failed.
Aborted transaction can be rolled back from the point of failure.
It is made to execute and once the transaction is committed, it is terminated.

© Kalasalingam academy of research and education COURSE NAME


Transaction Concepts

© Kalasalingam academy of research and education COURSE NAME


ACID Properties

A transaction which is happening must satisfy ACID property.


A for Atomicity which is full transaction has to happen or no transaction has to be executed
C for Consistency which is after every transaction execution the database must be consistent that is
database must be updated.
I for Isolation which is one transaction must not cross with other transaction.
Each and every transaction is separate
D for Durability which is transaction has to happen within specified amount of time.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


ACID Properties

© Kalasalingam academy of research and education COURSE NAME


ACID Properties

© Kalasalingam academy of research and education COURSE NAME


Transaction State

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


State Diagram for Transaction

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Implementation of Atomicity and Durability

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Atomicity and Durability

© Kalasalingam academy of research and education COURSE NAME


Concurrent Executions

In a multi-user system, multiple users can access and use the same database at one
time, which is known as the concurrent execution of the database.
It means that the same database is executed simultaneously on a multi-user system by
different users.
While working on the database transactions, there occurs the requirement of using the
database by multiple users for performing different operations, and in that case,
concurrent execution of the database is performed.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Concurrent Executions

The thing is that the simultaneous execution that is performed should be done in an
interleaved manner, and no operation should affect the other executing operations.
Thus maintaining the consistency of the database.
Thus, on making the concurrent execution of the transaction operations, there occur
several challenging problems that need to be solved.

© Kalasalingam academy of research and education COURSE NAME


Problems with Concurrent Execution

Problem 1: Lost Update Problems (W - W


Conflict)
The problem occurs when two different database
transactions perform the read/write operations on the
same database items in an interleaved manner (i.e.,
concurrent execution) that makes the values of the
items incorrect hence making the database
inconsistent.

© Kalasalingam academy of research and education COURSE NAME


Dirty Read Problems (W-R Conflict)

The dirty read problem occurs when one transaction updates an item of the database, and somehow the transaction fails, and
before the data gets rollback, the updated database item is accessed by another transaction. There comes the Read-Write Conflict
between both transactions.
For example:
Consider two transactions TX and TY in the below diagram performing read/write operations on account A where the available
balance in account A is $300:
At time t1, transaction TX reads the value of account A, i.e., $300.
At time t2, transaction TX adds $50 to account A that becomes $350.
At time t3, transaction TX writes the updated value in account A, i.e., $350.
Then at time t4, transaction TY reads account A that will be read as $350.
Then at time t5, transaction TX rollbacks due to server problem, and the value changes back to $300 (as initially).
But the value for account A remains $350 for transaction TY as committed, which is the dirty read and therefore known as the
Dirty Read Problem.

© Kalasalingam academy of research and education COURSE NAME


Unrepeatable Read Problem (W-R Conflict)

Also known as Inconsistent Retrievals Problem that occurs when in a transaction, two different values are read for the same
database item.

Consider two transactions, TX and TY, performing the read/write operations on account A, having an available
balance = $300.

At time t1, transaction TX reads the value from account A, i.e., $300.

At time t2, transaction TY reads the value from account A, i.e., $300.

At time t3, transaction TY updates the value of account A by adding $100 to the available balance, and then it becomes
$400.

At time t4, transaction TY writes the updated value, i.e., $400.

After that, at time t5, transaction TX reads the available value of account A, and that will be read as $400.

It means that within the same transaction TX, it reads two different values of account A, i.e., $ 300 initially, and after
updation made by transaction TY, it reads $400. It is an unrepeatable read and is therefore known as the Unrepeatable read
problem.

© Kalasalingam academy of research and education COURSE NAME


Concurrent Executions

© Kalasalingam academy of research and education COURSE NAME


Concurrent Executions

© Kalasalingam academy of research and education COURSE NAME


Schedules

In the fields of databases and transaction processing (transaction management), a schedule (or history) of a system is
an abstract model to describe execution of transactions running in the system.
Often it is a list of operations (actions) ordered by time, performed by a set of transactions that are executed together
in the system.
 If the order in time between certain operations is not determined by the system, then a partial order is used.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Schedules

Examples of such operations are requesting a read operation, reading, writing, aborting, committing,
requesting a lock, locking, etc.
Not all transaction operation types should be included in a schedule, and typically only selected
operation types (e.g., data access operations) are included, as needed to reason about and describe certain
phenomena.
Schedules and schedule properties are fundamental concepts in database concurrency control theory.

© Kalasalingam academy of research and education COURSE NAME


Schedules

© Kalasalingam academy of research and education COURSE NAME


Schedule - 1

Start of
T2

End of
T1

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Schedule - 2

Serial
Schedule

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Schedule - 3

Not a Serial
Schedule

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


First Lesson Summary:
ACID properties
Implementation of Atomicity and
Topic 1
Transaction concept Durability
Topic 2 Concurrent Executions
Transaction state

Topic 3
Schedules

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Lesson – 2
Serializability

It is discussed before that a non-serial schedule may lead to inconsistency sometimes.
Here, in the conflict schedule, we will discuss how, with a non-serial Schedule, we can ensure consistency in the
system.
To ensure a consistent system, we first need to confirm whether a non-serial schedule will produce a compatible
system or not.
As we have already discussed that the serial schedules are consistent, we can compare the output of the serial
Schedule to the non-serial Schedule.
 If both the outputs are just equivalent, we can ensure that the non-serial Schedule will produce a consistent system.
If we try to convert a non-serial transaction to a serial transaction, we need to swap instructions between the non-
serial Schedule.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Serializability

© Kalasalingam academy of research and education COURSE NAME


Schedules

© Kalasalingam academy of research and education COURSE NAME


Conflict Serializability

The instructions of the same transaction can not be swapped. So there is no conflict between the instructions of the
same transaction.
The instructions can conflict only when they belong to different transactions.
They must operate on the same data value to have conflicting instructions.

© Kalasalingam academy of research and education COURSE NAME


Conflict Serializability

There may be a conflict if any of the swapping instructions is a write operation.


So after swapping non-conflicting instructions, if we can convert a non-serial schedule into a serial one,
that Schedule is called conflict serializable. The non-serial Schedule is proved to be a consistent one.
To check that the Schedule is Conflict Serializable or not, We should know What are Conflict Operations
and Non-Conflict Operation.

© Kalasalingam academy of research and education COURSE NAME


Conflict Serializability

© Kalasalingam academy of research and education COURSE NAME


Conflict Serializability

© Kalasalingam academy of research and education COURSE NAME


Example of Non-Conflict Serializable schedule

© Kalasalingam academy of research and education COURSE NAME


View Serializability

As it is known to all of us that if we use serial schedule then the database will never be trapped in an inconsistent
state as there are no concurrent transactions are running in this schedule.
But with the use of a non-serial schedule, there are high chances that the database may go inconsistent state as
concurrent transactions are allowed in this schedule.
So to just make sure the consistency of the database we need to check the view serializability of a given non-serial
schedule.

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Example of View Serializability

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
View Serializability

© Kalasalingam academy of research and education COURSE NAME


Example for precedence graph

© Kalasalingam academy of research and education COURSE NAME


Precedence Graph

T1 T2

T4
T3

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Precedence Graph

© Kalasalingam academy of research and education COURSE NAME


Test for Conflict Serializability

A schedule is conflict serializable if and only if its precedence graph is acyclic.


Cycle-detection algorithms exist which take order n2 time, where n is the number of vertices in the graph.
(Better algorithms take order n + e where e is the number of edges.)

If precedence graph is acyclic, the serializability order can be obtained by a topological sorting of the graph.
 This is a linear order consistent with the partial order of the graph.
For example, a serializability order for Schedule A would be
T5  T1  T3  T2  T4

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Test for Conflict Serializability

© Kalasalingam academy of research and education COURSE NAME


Test for View Serializability

The precedence graph test for conflict serializability cannot be used directly to test for view serializability.
Extension to test for view serializability has cost exponential in the size of the precedence graph.

The problem of checking if a schedule is view serializable falls in the class of NP-complete problems.
 Thus existence of an efficient algorithm is extremely unlikely.

However practical algorithms that just check some sufficient conditions for view serializability can still be
used.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Test for View Serializability

© Kalasalingam academy of research and education COURSE NAME


Recoverable - Schedules

 For concurrently running transactions, the effect of transaction failures have to be addressed.
The schedules which can be recovered are said to be recoverable schedules
Below is the example of recoverable schedule.
T8 and T9 transactions are executed which is recoverable schedule.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Recoverable Schedules

© Kalasalingam academy of research and education COURSE NAME


Cascadeless - Schedules

Rollbacks cannot occur in cascade manner.


These are called as cascadeless schedules for each pair of transactions Ti and Tj
Every recoverable schedule is a cascadeless schedule.

Cascadeless schedules have to be restricted.


These schedules cannot run in next to next manner.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Cascadeless Schedules

© Kalasalingam academy of research and education COURSE NAME


Cascadeless Schedules

© Kalasalingam academy of research and education COURSE NAME


Concurrency Control

A database must provide a mechanism that will ensure that all possible schedules are
Either conflict or view serializable, and
Are recoverable and preferably cascadeless

A policy in which only one transaction can execute at a time generates serial schedules, but provides a poor degree
of concurrency
Are serial schedules recoverable/cascadeless?

Testing a schedule for serializability after it has executed is a little too late!
Goal – to develop concurrency control protocols that will assure serializability.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Concurrency Control

© Kalasalingam academy of research and education COURSE NAME


Concurrency Control vs. Serializability Tests

Concurrency-control protocols allow concurrent schedules, but ensure that the schedules are conflict/view
serializable, and are recoverable and cascadeless .
Concurrency control protocols generally do not examine the precedence graph as it is being created
Instead a protocol imposes a discipline that avoids nonseralizable schedules.

Different concurrency control protocols provide different tradeoffs between the amount of concurrency they allow
and the amount of overhead that they incur.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Weak Levels of Consistency

Some applications are willing to live with weak levels of consistency, allowing schedules that are not serializable
E.g. A read-only transaction that wants to get an approximate total balance of all accounts
E.g. Database statistics computed for query optimization can be approximate
Such transactions need not be serializable with respect to other transactions

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Second Lesson Summary:
Topic 1
Conflicting Instructions
Serializability Non-conflict Serializable schedule
Topic 2
Predecessor graph
Conflict Serializability
Recoverable schedules
Topic 3

View Serializability
Cascadeless schedules
Topic 4 Weak levels of consistency
Testing for Serializability

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Lesson 3: Definition of Lock Based Protocols

Concurrent access to a data item can be controlled by a mechanism called lock.


There are two modes to lock a data item:
Read and write operations can be done in exclusive lock.
Only read operation can be done in shared lock.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Lock Based Protocols

© Kalasalingam academy of research and education COURSE NAME


Types of lock protocols

Simplistic lock protocol


It is the simplest way of locking the data while transaction.
Simplistic lock-based protocols allow all the transactions to get the lock on the data before
insert or delete or update on it. It will unlock the data item after completing the transaction.

© Kalasalingam academy of research and education COURSE NAME


Types of lock protocols

Pre-claiming Lock Protocol

Pre-claiming Lock Protocols evaluate the transaction to list all the data items on which they need locks.

Before initiating an execution of the transaction, it requests DBMS for all the lock on all those data
items.

If all the locks are granted then this protocol allows the transaction to begin. When the transaction is
completed then it releases all the lock.

If all the locks are not granted then this protocol allows the transaction to rolls back and waits until all
the locks are granted.

© Kalasalingam academy of research and education COURSE NAME


How Lock Compatibility Matrix is created?

A lock is granted for the transaction when there is no lock on the data item which is requested by the transaction.
Shared lock can be granted to any transaction which requests data item which holds shared lock.
A transaction cannot be granted lock when there is exclusive lock held by data item.
A transaction can wait until data item is given access and upto the locks are released.

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Lock Compatibility Matrix

© Kalasalingam academy of research and education COURSE NAME


Example of Lock Based Protocol

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Disadvantages of Lock-Based Protocols

Contention: some threads/processes have to wait until a lock (or a whole set of locks) is released.
If one of the threads holding a lock dies, stalls, blocks, or enters an infinite loop, other threads waiting for the lock
may wait forever.
Overhead: the use of locks adds overhead for each access to a resource, even when the chances for collision are
very rare. (However, any chance for such collisions is a race condition.)

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Disadvantages of Lock-Based Protocols

Debugging: bugs associated with locks are time dependent and can be very subtle and extremely hard to
replicate, such as deadlocks.
Instability: the optimal balance between lock overhead and lock contention can be unique to the
problem domain (application) and sensitive to design, implementation, and even low-level system
architectural changes. These balances may change over the life cycle of an application and may entail
tremendous changes to update (re-balance).

© Kalasalingam academy of research and education COURSE NAME


Pitfalls of Lock-Based Protocols

© Kalasalingam academy of research and education COURSE NAME


Two phase Locking Protocol

© Kalasalingam academy of research and education COURSE NAME


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
continues to execute normally.
The only difference between 2PL and strict 2PL is that Strict-2PL does not release a lock after using it.
Strict-2PL waits until the whole transaction to commit, and then it releases all the locks at a time.
Strict-2PL protocol does not have shrinking phase of lock release.
It does not have cascading abort as 2PL does.

© Kalasalingam academy of research and education COURSE NAME


Strict Two-phase locking (Strict-2PL)

© Kalasalingam academy of research and education COURSE NAME


Conversions of lock

Lock conversions can be made in two phase


In the first phase shared lock has to be acquired on a data item and then shared lock can be acquired
Shared lock can be converted to exclusive lock by upgrade process
 In the second Phase shared lock and exclusive lock can be released in order
Exclusive lock can be converted to shared lock by downgrade process.
Serializability is assured by this conversion of lock.

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Lock Conversions

© Kalasalingam academy of research and education COURSE NAME


Lock - Table

Granted locks are in the black rectangles and the waiting requests are stored in white rectangles.
The type of lock granted or requested is recorded in the lock table.
At the end of the queue, new requests are added.
Once the request is unlocked, it is deleted.
Locks are implemented efficiently by the lock manager.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Lock Table

© Kalasalingam academy of research and education COURSE NAME


Lock Table

© Kalasalingam academy of research and education COURSE NAME


Topic 1
Lock Based Protocol

Topic 2 Third Lesson Summary:


Lock Compatibility matrix

Topic 3
Two Phase Locking Protocol
Example of Lock Based Protocol Lock conversion
Topic 4 Automatic Acquisition of locks
Pitfalls of Lock Based Protocol Implementation of Locking
Lock table

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Lesson 4: Deadlock Handling

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Deadlock Handling

© Kalasalingam academy of research and education COURSE NAME


Deadlock Prevention Strategies

Non-preemptive is wait-die scheme:


Younger transactions are rolled back and never wait for older ones.
Before acquiring needed data item, a transaction dies several times.

Preemptive is wound-wait scheme:


Younger transactions are wounded by older transactions .
Compared to wait-die scheme, roll backs are fewer.

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Deadlock Prevention

© Kalasalingam academy of research and education COURSE NAME


Deadlock - prevention

A rolled back transactions is restarted with its original timestamp in both in wait-die
and in wound-wait schemes,.
Deadlocks are not possible in time-out based scheme.
It is simple to implement;
Starvation is possible.

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Deadlock prevention

© Kalasalingam academy of research and education COURSE NAME


Deadlock Detection

Deadlocks can be described as a wait-for graph, which consists of a pair G = (V,E),


V is a set of vertices (all the transactions in the system)
E is a set of edges; each element is an ordered pair Ti Tj.

If Ti  Tj is in E, then there is a directed edge from Ti to Tj, implying that Ti is waiting for Tj to release a data item.

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Deadlock Detection

When Ti requests a data item currently being held by Tj, then the edge Ti Tj is inserted in the wait-for
graph. This edge is removed only when Tj is no longer holding a data item needed by Ti.
The system is in a deadlock state if and only if the wait-for graph has a cycle. Must invoke a deadlock-
detection algorithm periodically to look for cycles.

© Kalasalingam academy of research and education COURSE NAME


Deadlock Detection

Wait-for graph without a cycle


Wait-for graph with a cycle

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Deadlock Detection

© Kalasalingam academy of research and education COURSE NAME


Timestamp-Based Protocols
Each transaction is issued a timestamp when it enters the system. If an old transaction Ti has time-stamp TS(Ti), a new
transaction Tj is assigned time-stamp TS(Tj) such that TS(Ti) <TS(Tj).

The protocol manages concurrent execution such that the time-stamps determine the serializability order.

In order to assure such behavior, the protocol maintains for each data Q two timestamp values:
W-timestamp(Q) is the largest time-stamp of any transaction that executed write(Q) successfully.
R-timestamp(Q) is the largest time-stamp of any transaction that executed read(Q) successfully.

The timestamp ordering protocol ensures that any conflicting read and write operations are executed in timestamp order.

Suppose a transaction Ti issues a read(Q)


 If TS(Ti)  W-timestamp(Q), then Ti needs to read a value of Q that was already overwritten.
 Hence, the read operation is rejected, and Ti is rolled back.
 If TS(Ti) W-timestamp(Q), then the read operation is executed, and R-timestamp(Q) is set to max(R-
timestamp(Q), TS(Ti)).

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Timestamp-Based Protocols

© Kalasalingam academy of research and education COURSE NAME


Timestamp-Based Protocols (Cont.)

Suppose that transaction Ti issues write(Q).


 If TS(Ti) < R-timestamp(Q), then the value of Q that Ti is producing was needed previously, and the system
assumed that that value would never be produced.
 Hence, the write operation is rejected, and Ti is rolled back.
 If TS(Ti) < W-timestamp(Q), then Ti is attempting to write an obsolete value of Q.
 Hence, this write operation is rejected, and Ti is rolled back.
 Otherwise, the write operation is executed, and W-timestamp(Q) is set to TS(Ti).

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Example Use of the Protocol
A partial schedule for several data items for transactions with
timestamps 1, 2, 3, 4, 5

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Correctness of Timestamp-Ordering Protocol

The timestamp-ordering protocol guarantees serializability since all the arcs in the precedence graph are
of the form:

Thus, there will be no cycles in the precedence graph


Timestamp protocol ensures freedom from deadlock as no transaction ever waits.
But the schedule may not be cascade-free, and may not even be recoverable.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Fourth Lesson Summary:
Deadlock Prevention
Deadlock Detection
Topic 1
Deadlock Recovery
Deadlock handling
Timestamp Based Protocol
Topic 2
Deadlock Prevention Strategies Example
Correctness

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Lesson 5:Database Recovery Techniques
Database systems, like any other computer system, are subject to failures but the data stored in it 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.

COURSE NAME DATABASE MANAGEMENT SYSTEMS


© Kalasalingam academy of research and education
Database Recovery Techniques

© Kalasalingam academy of research and education COURSE NAME


System - Log information
When the transaction is executed successfully commit is done.
When commit is done it is permanent save.
When transaction is committed, roll back cannot be done.
When transaction is failed, it is aborted.
Aborted transactions can be rolled back from the point of failure.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Undoing the transaction

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Deferred - update

Once the transaction has reached its commit point, this technique does not physically update the
database.
All transaction updates are recorded in the local transaction workspace.
 It will not have changed the database in any way so UNDO is not needed. if a transaction fails
before reaching its commit point,
 It may be REDO the the operations, because their effect is not yet written in the database.
It is No-undo/redo algorithm

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Deferred update

© Kalasalingam academy of research and education COURSE NAME


Deferred update

© Kalasalingam academy of research and education COURSE NAME


Immediate - update

Before the transaction reaches its commit point., the database may be updated by some operations of a transaction.
These operations are recorded in a log on disk.
Recovery is still possible.
 The effect of its operation must be undone, if a transaction fails to reach its commit point.
we require both undo and redo i.e. the transaction must be rolled back.
This technique is undo/redo algorithm.

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Immediate update

© Kalasalingam academy of research and education COURSE NAME


Immediate update

© Kalasalingam academy of research and education COURSE NAME


Shadow paging in brief
Atomicity and Durability is provided by this database recovery technique.
The current directory is copied into a shadow directory, when a transaction began
executing.
A shadow page is allocated in which changes are made, when a page is to be modified,
and all pages that refer to original are updated to refer new replacement page, when it is
ready to become durable,

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS


Shadow paging

COURSE NAME
Shadow paging

COURSE NAME
This unit focuses on the basic concepts of Transaction Management and
concepts, Transaction recovery and ACID properties in Database Management
Topic 1 System.
Transaction Concepts
Topic 2 Lesson 1: Represents the introduction to Transaction recovery and ACID
ACID properties properties.
Topic 3
Lesson 2: Represents the operations of serializability such as conflict and serial
Database Recovery Techniques schedules.
Topic 4
System Log information Lesson 3: Represents the lock based protocols such as two phase locking with
Topic 5 example and lock table implementation.
Undoing
Lesson 4: Introduces the concept of Deadlock handling, prevention and
Topic 6 detection strategies and timestamp ordering protocol.
Deferred Update
Topic 7 Lesson 5: Describes the database recovery techniques such as deferred update,
immediate update, shadow paging.
Immediate Update
Topic 8
Shadow paging Fourth Unit Summary
COURSE NAME : DATABASE MANAGEMENT SYSTEMS
© Kalasalingam academy of research and education
Thank You!

© Kalasalingam academy of research and education DATABASE MANAGEMENT SYSTEMS

You might also like