Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views14 pages

DBMS - Unit 4

Module 4 covers Transactions Management, defining transactions and explaining ACID properties, which ensure reliability in database systems. It discusses transaction states, serial and serializable schedules, view serializability, concurrency control, and lock-based protocols, emphasizing the importance of managing concurrent transactions to prevent deadlocks and ensure recoverability. Additionally, it outlines deadlock detection and recovery methods, as well as log-based recovery techniques for maintaining database integrity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

DBMS - Unit 4

Module 4 covers Transactions Management, defining transactions and explaining ACID properties, which ensure reliability in database systems. It discusses transaction states, serial and serializable schedules, view serializability, concurrency control, and lock-based protocols, emphasizing the importance of managing concurrent transactions to prevent deadlocks and ensure recoverability. Additionally, it outlines deadlock detection and recovery methods, as well as log-based recovery techniques for maintaining database integrity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Module 4

Transactions Management

1. Define Transaction:
Ans: A transaction is a unit of program execution that accesses and possibly updates
various data items.

2. Explain ACID properties of transaction.


Ans: Atomicity: Either all operations of the transaction are properly reflected in the
database or none are.

Consistency: Execution of a transaction in isolation preserves the consistency


of the database.

Isolation: Although multiple transactions may execute concurrently, each


transaction must be unaware of other concurrently executing transactions.
Intermediate transaction results must be hidden from other concurrently
executed transactions.

That is, for every pair of transactions Ti and Tj, it appears to Ti that either Tj,
finished execution before Ti started, or Tj started execution after Ti finished.

Durability : After a transaction completes successfully, the changes it has made


to the database persist, even if there are system failures.

3. Draw and explain the transaction state diagram.


Ans: Transaction state diagram:
Different states of transaction are as follows:

Active – the initial state; the transaction stays in this state while it is
executing

Partially committed – after the final statement has been executed.

Failed -- after the discovery that normal execution can no longer proceed.

Aborted – after the transaction has been rolled back and the database
restored to its state prior to the start of the transaction. Two options after it
has been aborted:

1.Restart the transaction can be done only if no internal logical error

2.Kill the transaction

Committed – after successful completion.

4. Explain serial schedule and serializable schedule with


example.
Ans: Schedule – a sequences of instructions that specify the chronological
order in which instructions of concurrent transactions are executed
Serial Schedules:
Schedules in which the transactions are executed non-interleaved, i.e., a serial schedule is one
in which no transaction starts until a running transaction has ended are called serial schedules.
Schedule 1: In below schedule1, T2 starts after T1 is completed. So this is the serial schedule.

Serializable schedule:
The schedule which is equivalent to any serial schedule is known as Serializable schedule.

Schedule2: Above schedule2 is not a serial schedule but it is equivalent to schedule1 so it is


known as Serializable schedule.
If a schedule S can be transformed into a schedule S´ by a series of swaps of non-conflicting
instructions, we say that S and S´ are conflict equivalent.

We say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedule

6. Explain View Serializability.


Let S and S' be two schedules with the same set of transactions. S and S' are view
equivalent if the following three conditions are met, for each data item Q,
1. If in schedule S, transaction Ti reads the initial value of Q, then in schedule S' also
transaction Ti must read the initial value of Q.
2. If in schedule S transaction Ti executes read(Q), and that value was produced by
transaction Tj (if any), then in schedule S’ also transaction Ti must read the value of Q
that was produced by the same write(Q) operation of transaction Tj .
3. The transaction (if any) that performs the final write(Q) operation in schedule S must
also perform the final write(Q) operation in schedule S’.

A schedule S is view serializable if it is view equivalent to a serial schedule.


■ Every conflict serializable schedule is also view serializable.
■ Below is a schedule which is view-serializable but not conflict serializable.

OR
● A schedule will view serializable if it is view equivalent to a serial schedule.

● If a schedule is conflict serializable, then it will be view serializable.

● The view serializable which does not conflict serializable contains blind writes.

View Equivalent

Two schedules S1 and S2 are said to be view equivalent if they satisfy the following
conditions:

1. Initial Read:
An initial read of both schedules must be the same. Suppose two schedule S1 and S2.
In schedule S1, if a transaction T1 is reading the data item A, then in S2, transaction T1
should also read A.

2. Updated Read:

In schedule S1, if Ti is reading A which is updated by Tj then in S2 also, Ti should read


A which is updated by Tj.

3. Final Write:

A final write must be the same between both the schedules. In schedule S1, if a
transaction T1 updates A at last then in S2, final writes operations should also be done
by T1.

7. Define Concurrency Control and explain lock based


protocol in detail.
Ans: Concurrency Control is the management procedure that is required for controlling
concurrent execution of the operations that take place on a database.It prevents two users from
editing the same record at the same time and also serializes transactions for backup and
recovery.Concurrency can simply be said to be executing multiple transactions at a time. It is
required to increase time efficiency.

Advantages

The advantages of concurrency control are as follows −

● Waiting time will be decreased.


● Response time will decrease.
● Resource utilization will increase.
○ System performance & Efficiency is increased

Lock-Based Protocol

A lock is a variable associated with a data item that describes a status of data item with respect
to possible operation that can be applied to it. They synchronize the access by concurrent
transactions to the database items. It is required in this protocol that all the data items must be
accessed in a mutually exclusive manner. Let me introduce you to two common locks which are
used and some terminology followed in this protocol.

1. Shared Lock (S): also known as Read-only lock. As the name suggests it can be
shared between transactions because while holding this lock the transaction does
not have the permission to update data Shared Locks, which are often denoted as
lock-S(), is defined as locks that provide Read-Only access to the information
associated with them. Whenever a shared lock is used on a database, it can be read
by several users, but these users who are reading the information or the data items
will not have permission to edit it or make any changes to the data itemson the data
item. S-lock is requested using lock-S instruction.
2. Exclusive Lock (X): Data item can be both read as well as written.This is Exclusive
and cannot be held simultaneously on the same data item. X-lock is requested using
lock-X instruction. Exclusive Lock allows the data item to be read as well as written.
This is a one-time use mode that can't be utilized on the exact data item twice. To
obtain X-lock, the user needs to make use of the lock-x instruction. After finishing the
'write' step, transactions can unlock the data item. By imposing an X lock on a
transaction that needs to update a person's account balance, for example, you can
allow it to proceed. As a result of the exclusive lock, the second transaction is unable
to read or write. The other name for an exclusive lock is write lock.

A transaction may be granted a lock on an item if the requested lock is


compatible with locks already held on the item by other transactions
Any number of transactions can hold shared locks on an item,

lBut if any transaction holds an exclusive on the item no other transaction may

hold any lock on the item.

If a lock cannot be granted, the requesting transaction is made to wait till all
incompatible locks held by other transactions have been released. The lock is
then granted.

The Two-Phase Locking Protocol:

This protocol ensures conflict-serializable schedules.

Phase 1: Growing Phase

Transaction may obtain locks

Transaction may not release locks

Phase 2: Shrinking Phase

Transaction may release locks

Transaction may not obtain locks

The protocol assures serializability. It can be proved that the transactions can be
serialized in the order of their lock points (i.e., the point where a transaction
acquired its final lock).
8. What is recoverable schedule? Why is recoverability of schedules
desirable?

Ans: if a transaction Tj reads a data item previously written by a transaction Ti , then


the commit operation of Ti appears before the commit operation of Tj .
OR
A recoverable schedule is basically a schedule in which the commit operation of a
particular transaction that performs read operation is delayed until the uncommitted
transaction either commits or roll backs.

Example of Recoverable Schedule:

Here, transaction T2 is reading the value written by transaction T1 and the commit of T2 occurs
after the commit of T1. Hence, it is a recoverable schedule.

● Recoverable schedules are desirable because failure of a transaction might


otherwise bring the system into an irreversibly inconsistent state.
9. Deadlocks:
System is deadlocked if there is a set of transactions such that every
transaction in the set is waiting for another transaction in the set.

Consider the partial schedule

Neither T3 nor T4 can make progress — executing lock-S(B) causes T4 to wait


for T3 to release its lock on B, while executing lock-X(A) causes T3 to wait for T4
to release its lock on A.
n Such a situation is called a deadlock.
To handle a deadlock one of T3 or T4 must be rolled back
l

and its locks released.


When a deadlock occurs there is a possibility of cascading roll-backs.

Cascading roll-back is possible under two-phase locking. To avoid this, follow a modified
protocol called strict two-phase locking -- a transaction must hold all its exclusive locks
till it commits/aborts.
Rigorous two-phase locking is even stricter. Here, all locks are held till commit/abort.
In this protocol transactions can be serialized in the order in which they commit.

Deadlock prevention protocols ensure that the system will never enter into a
deadlock state. Some prevention strategies :
Require that each transaction locks all its data items before it begins execution
(predeclaration).

Impose partial ordering of all data items and require that a transaction can lock
data items only in the order specified by the partial order.

Following schemes use transaction timestamps for the sake of deadlock


prevention alone.

wait-die scheme — non-preemptive

older transaction may wait for younger one to release data item. (older means
smaller timestamp) Younger transactions never Younger transactions never wait
for older ones; they are rolled back instead.

a transaction may die several times before acquiring needed data item

wound-wait scheme — preemptive

older transaction wounds (forces rollback) of younger transaction instead of


waiting for it. Younger transactions may wait for older ones.

may be fewer rollbacks than wait-die scheme.

Both in wait-die and in wound-wait schemes, a rolled back transactions is restarted


with its original timestamp. Older transactions thus have precedence over newer ones,
and starvation is hence avoided.

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

lV is a set of vertices (all the transactions in the system).lE is a set of edges; each element is an
ordered pair Ti —->Tj.

nIf 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.
nWhen 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.

Wait-for graph without a cycle

Wait-for graph with a cycle

10. Deadlock Recovery:

l Some transaction will have to rolled back (made a victim) to break deadlock.
Select that transaction as victim that will incur minimum cost.

l Rollback -- determine how far to roll back transaction

4 Total rollback: Abort the transaction and then restart it.


4 More effective to roll back transaction only as far as necessary to break
deadlock.

l Starvation happens if same transaction is always chosen as victim. Include the


number of rollbacks in the cost factor to avoid starvation.

11. Log-Based Recovery:


A log is kept on stable storage.
The log is a sequence of log records, and maintains a record of update activities on the
database.

When transaction Ti starts, it registers itself by writing a

<Ti start>log record

Before Ti executes write(X), a log record

<Ti, X, V1, V2>

is written, where V1 is the value of X before the write (the old value), and V2 is the
value to be written to X (the new value).

When Ti finishes it last statement, the log record <Ti commit> is written.
Two approaches using logs
1. Deferred database modification
2. Immediate database modification
The immediate-modification scheme allows updates of an uncommitted transaction to
be made to the buffer, or the disk itself, before the transaction commits
Update log record must be written before database item is written
We assume that the log record is output directly to stable storage
(Will see later that how to postpone log record output to some extent)
Output of updated blocks to stable storage can take place at any time before or after
transaction commit
Order in which blocks are output can be different from the order in which they are
written.
The deferred-modification scheme performs updates to buffer/disk only at the time of
transaction commit
Simplifies some aspects of recovery
But has overhead of storing local copy

You might also like