DBMS Module 5

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

2) Why concurrency control is needed? Explain with example.

 Concurrency Control in Database Management System is a procedure of managing


simultaneous operations without conflicting with each other.
 It ensures that Database transactions are performed concurrently and accurately to
produce correct results without violating data integrity of the respective Database.
 Though for any practical Database, it would have a mix of READ and WRITE
operations and hence the concurrency is a challenge.
 Therefore, Concurrency Control is the most important element for proper
functioning of a Database Management System where two or more database
transactions are executed simultaneously, which require access to the same data.
 Reasons for using Concurrency control method is DBMS:
1. To apply Isolation through mutual exclusion between conflicting transactions
2. To resolve read-write and write-write conflict issues
3. To preserve database consistency through constantly preserving execution
obstructions
4. The system needs to control the interaction among the concurrent transactions.
This control is achieved using concurrent-control schemes.
5. Concurrency control helps to ensure serializability

 Assume that two people who go to electronic kiosks at the same time to buy a movie
ticket for the same movie and the same show time.

 However, there is only one seat left in for the movie show in that particular theatre.
Without concurrency control in DBMS, it is possible that both moviegoers will end up
purchasing a ticket. However, concurrency control method does not allow this to
happen. Both moviegoers can still access information written in the movie seating
database. But concurrency control only provides a ticket to the buyer who has
completed the transaction process first.

 An ideal concurrency control DBMS mechanism has the following objectives:

 Must be resilient to site and communication failures.


 It allows the parallel execution of transactions to achieve maximum
concurrency.
 Its storage mechanisms and computational methods should be modest to
minimize overhead.
 It must enforce some constraints on the structure of atomic actions of
transactions.

3) Explain the undo and redo operations with recovery techniques that use each.

 Undo/Redo is a database transaction log for handling transaction crash recovery.


 This algorithm stores all the values and changes made during transactions in a
separate memory in case of failure or crash.
 It utilizes the stored value to restore the loss due to failure.

 This algorithm is a combination of two approaches


 UNDO: It stands for undone and restores the data value items that are
updated by any transaction to their previous value.
 REDO: It stands for re-done and it set the value of all the data updated by the
transaction to the new value.
 The UNDO/REDO recovery algorithm is a very flexible algorithm but the
only disadvantage it faces is that it requires more storage to store both old as
well as newly updated values.

NO-UNDO/REDO Recovery Protocol

 System must impose NO-STEAL rule.

 Recovery subsystem analyses the log, and creates two lists:

a. Active Transaction list: All active (uncommitted) transaction ids are entered
in this list.

b. Committed Transaction list: Transactions committed after the last checkpoint


are entered in this table.

 During recovery, transactions in commit list are redone; transactions in active list are
ignored (because of NO-STEAL rule, none of their writes have been applied to the
database on disk).

 Some transactions may be redone twice; this does not create inconsistency because
REDO is “idempotent”, that is, one REDO for an AFIM is equivalent to multiple REDO
for the same AFIM.

UNDO/NO-REDO Recovery Protocol

 In this method, FORCE rule is imposed by system (AFIMs(After Image) of a


transaction are flushed to the database on disk under Write Ahead Logging before
the transaction commits).

 Transactions in active list are undone; transactions in committed list are ignored
(because based on FORCE rule, all their changes are already written to the database
on disk).
4) When deadlock and starvation problem occur? Explain how these can be resolved.
Deadlock:

 Deadlock occurs when each transaction T in a set of two or more transactions is


waiting for some item that is locked by some other transaction T′ in the set.
 Hence, each transaction in the set is in a waiting queue, waiting for one of the other
transactions in the set to release the lock on an item.
 But because the other transaction is also waiting, it will never release the lock.

 Transition T1 holds a lock on some rows in student table and T2 holds lock on some
rows of Grade table.
 But T1 want to update the table held by T2(Grade) and vice versa. (Further explain)
 All activity comes to a halt and remains at a standstill forever unless the DBMS
detects the deadlock and abort one of the transactions.
 Two schemes that prevent deadlock are called wait-die and wound-wait.
1. Wait-die: In wait-die, an older transaction is allowed to wait for a younger
transaction, whereas a younger transaction requesting an item held by an
older transaction is aborted and restarted.
2. Wound-wait: The wound-wait approach does the opposite: A younger
transaction is allowed to wait for an older one, whereas an older transaction
requesting an item held by a younger transaction preempts the younger
transaction by aborting it.

Starvation:

 Another problem that may occur when we use locking is starvation, which occurs
when a transaction cannot proceed for an indefinite period of time while other
transactions in the system continue normally.
 This may occur if the waiting scheme for locked items is unfair in that it gives priority
to some transactions over others.
 One solution for starvation is to have a fair waiting scheme, such as using a first-
come-first-served queue; transactions are enabled to lock an item in the order in
which they originally requested the lock.
 The wait-die and wound-wait schemes discussed previously avoid starvation,
because they restart a transaction that has been aborted with its same original
timestamp, so the possibility that the same transaction is aborted repeatedly.

5) Write and explain the Two-phase locking protocols for concurrency control.

 As binary locking does not guarantee serializability, to guarantee serializability some


additional protocol called the Two-phase protocol is used.
 A transaction is said to follow the Two-phase locking protocol if locking and
unlocking can be done in two phases.
 Expanding or growing (first) phase, during which new locks on items can be
acquired but none can be released;
 Shrinking (second) phase, during which existing locks can be released but no new
locks can be acquired.
 If lock conversion is allowed, then upgrading of locks (from read-locked to write-
locked) must be done during the expanding phase, and downgrading of locks (from
write- locked to read-locked) must be done in the shrinking phase.
 Example for transaction that shows how unlocking and locking works in Two-phase
locking.

T1 T2
1 Read-Lock(A)
2 Read-Lock(A)
3 Write-Lock(B)
4 ……. …….
5 Unlock(A)
6 Write-lock(C)
7 Unlock(A)
8 Unlock(A)
9 Unlock(C)
10 ……. …….
 In transaction T1:
1. Growing phase is from step 1-3.
2. Shrinking phase is from step 5-7.
3. Lock point at 3.
 In transaction T2:
1. Growing phase is from step 2-6.
2. Shrinking phase is from step 8-9.
3. Lock point at 6.
 Here lock point is the point a which growing phase ends.
 The locking protocol, by enforcing two-phase locking rules, also enforces
serializability.
 Some drawbacks of 2-PL are
1. Cascading rollback is possible under 2-PL.
2. Deadlock and Starvation are possible.

6) Explain ARIES algorithm with example.

 ARIES uses a steal / no-force approach for writing and it is based on three Concepts.
1. write-ahead logging
2. Repeating history during redo
3. logging changes during undo
 The ARIES recovery procedure consists of 3 main steps.
1. Analysis.
2. REDO
3. UNDO.
1. The analysis step:
o Identifies the dirty pages in the buffer by the set of transactions active at the
time of the crash.
o The appropriate point in the log where the REDO Operation should start is
also determined.

2. The REDO phase:

o reapplies updates from the log to the database


o Certain info in the ARIES log will provide the start point for REDO, from which
REDO operations are applied until the end of log is reached.
3. The UNDO phase:
o The log is scanned backward of the operations of transactions that were
active at the time of the crash. are undone in reverse order.

7) What are the anomalies occurring due to interleave execution? Explain them with
example.

You might also like