<2, C,3, 6
<1, B, 2, >
‘Dump completes
END DUMP>
Log taken during a dump
‘Note that we did not show 7; committing: It would be unusual that a transaction remained
active during the entire time a full dump was in progress, but that possibility doesn’t affect the
correctness of the recovery method.
Recovery Using an Archive and Log:
‘Suppose that a media failure occurs, and we must reconstruct the database from the most
recent archive and whatever prefix of the log has reached the remote site and has not been fost in
the crash We perform the following steps:
1. Restore the database from the archive.
{a) Find the most recent full dump and reconstruct the database from it (i.¢., copy
the archive into the database).
(b) If there are later incremental dumps, modify the database according to each,
carlest first eee
e 2. Modify the database using the surviving tog, Use the method of recovery appropriate to the
Jog method being usedPART—A_ [2 mark questions |
J) Transaction Management: The two principal tasks of the transaction manager are assuring
recoverability of database actions through logging, and assuring correct, concurrent behavior of
transactions through the scheduler (not discussed in this chapter)
2) Database Elements: The database is divided into elements, which are typically disk blocks, but
could be tuples, extents of a class, or many other units. Database elements are the units for both
logging and scheduling
3) Logging: A record of every important action of a transaction —~ beginning, changing a database
‘element, committing, or aborting —is stored on a log. The log must be backed up on disk at a time
that is related to when the corresponding database changes migrate to disk, but that time depends
‘on the particular logging method used.
4) Recovery: When a system crash occurs, the log is used to repair the database, restoring it to a
consistent state.
$) Logging Methods: ‘The three principal methods for logging are undo, redo, and undo‘tedo,
named for the way(s) that they are allowed to fix the database during recovery.
6) Undo Logging —_: This method logs only the old value, each time a database element is
changed. With undo logging, a new value of a database element can only be written to disk after
the log record for the change has reached disk, but before the commit record for the transaction
performing the change reaches disk. Recovery is done by restoring the old value for every
‘uncommitted transaction,
7) Redo Logging: Were, only the new value of database clements is logged. With this form of
fogging. values of a database element can only be written to disk after both the log record of its
‘change and the commit record for its transaction have reached disk, Recovery involves rewriting
the new value for every committed transaction.
8 Undo/Redo Logging: In this method, both old and new values are logged. Undo/redo logging is
more flexible than the other methods, since it requires only that the log record of a change appear
on the disk befine the change itself does. There is no requirement about when the commit recon
appears. Recovery is effected by redoing committed transactions and undoing the uncommitted
(ansactions.9 Check pointing: Since all methods require; im principle, looking at the entire log from the dawn
of history when a recovery is necessary, the DBMS must occasionally checkpoint the log, 10 assure
that no log records prior to the checkpoint will be needed during a recovery. Thus, old log records
‘can eventually be thrown away and its disk space reused.
10) Nonguiescent Check pointing : To avoid shutting down the system while a checkpoint 1s
made, techniques associated with each logging method allow the checkpoint to be made while the
system is in operation and database changes are occurring. The only cost is that some log records
prior to the nonquiescent checkpoint may need to be examined during recovery
I) Archiving: While logging protects against system failures involving only the loss of main
memory, archiving is necessary to protect against failures where the contents of disk are lost
Archives are copies of the database stored in a safe place.
12) Recovery from Media Failures: When a disk is lost, it may be restored by starting with a full
backup of the database, modifying it according to any later incremental backups, and finally
recovering to a consistent database state by using an archived copy of the log,
13) Incremental Backups _; Instead of copying the entire database to an archive periodically, a
le complete backup can be followed by several incremental backups, where only the changed
data is copied to the archive
14) Nonqmescent Archiving : Techniques for making a backup of the data while the database is
in operation exist. They involve making log records of the beginning and end of the archiving, as
‘well as performing a checkpoint for the log during the archiving.
‘Scrializability
‘Serislizabilty is a widely accepted standard that ensures the consistency of @ schedile. A
‘schedule is consistent if and only if it is serializable. A schedule is said to be serializable if the
interleaved transactions produces the result, which 1s equivalent to the result produced by
executing individual transactions separately.‘Transaction | Transaction
th t
read(X)
wnte(X)
read(X)
write(X)
read(Y)
write(Y)
read(Y)
wnite(Y)
Serial Schedule Two interleaved transaction Schedule
The above two schedules produce the same result, these schedules are said to be
serializable. The transaction may be interleaved in any order and DBMS doesn’t provide any
‘guarantee about the order in which they are executed.
‘There two differemt types of Serializability. They are,
1) Conflict Serializability
ii) View Serializabitity
i) Conflict Serializability:
Consider a schedule Si, consisting of two successive instructions I, and Is belonging to
transactions T, and Ty refer to different data items then it is very easy to swap these instructions.
‘The result of swapping these instructions doesn’t have any impact on the remaining
instructions in the schedule. If t, and In refers to same data item then the following four cases must
be considered,
Case Ts Ins read(x), te» read(x),
Case 2 Ly = read(x), Ip = write(x),
Case 3 TNS WHAETRT. ta ready, Ce
Cased: 1, = write(x), Ip = write(x),Nd NINO NSEC eel ee AY Yt
BSN)
SAN
DAN SASoky
Case | Here, both I, and Ip are read instructions. In this case, the execution order of the
instructions is not considered since the same data item x is read by both the transactions T, and
To.
Case2 : Here.1, and Ipyare read and write instructions respectively. If the execution order of
instructions ts I4 > I, then transaction Ts cannot read the value written by transaction Ts in
instruction Is. but order is lu Ia, then transaction Ta can read the value written by transaction Tw
Therefore in this case, the execution order of the instructions is important
Case3 : Here,Iy and Ieare write and read instructions respectively. If the execution order of
instructions is [4 1, then transaction Ty can read the value written by transaction Ta, but order
is In Is, then transaction Ts cannot read the value written by transaction Tu. Therefore in this
case, the execution order of the instructions is important.
Case 1: Here, both Iq and In ate write instructions. In this ease, the execution order of the
instructions doesn’t matter. If a read operation is performed before the write operation, then the
data item which was already stored in the database is read,
ii) View Serializability:
Two schedules S: and $:* consisting of some set of transactions are said to be view equivalent,
i the following conditions are satisfied,
1) [fa transaction T, in schedule $; performs the read operation on the initial value of data
item x, then the same transaction in schedule $;* must also perform the read operation on the initial
value of x.
2) Ifa transaction T, in schedule S) reads the value x, which was written by transaction Ty,
then Ta in schedule $\* must also perform the read the value x written by transaction Tp,
3) Ifa transaction T, in schedule S; performs the final write operation on data item x, then
the same transaction in schedule S," must also perform the final write operation on x.Example:
View Serialtzability Schedule S:
‘The view equivalence leads to another notion called view serializability. A schedule say S
is said to be view Serializable, if it is view equivalent with the serial schedule.
Every conflict Serializable schedule ts view Serializable but every view Serializable is not
conflict Serializable.
Concurrency Control,
In a multiprogramming environment where multiple transactions can be executed
simultaneously, itis highly important fo contro! the concurrency of transactions
We have concurrency control protocols to ensure atomicity, isolation, and serializability of
concurrent transactions.
Why DBMS needs a concurrency control? es ES o
In general, concuirency control is an essential part of TM. It isa mechanism for correctness
when two or more database transactions that access the same data or data set are executed
/ ann cnn nnAEAnE ER REEEERERREENER
Dane O14
TOEP Pant ah COEconcurrently with time overlap, According to Wikipedia org, if multiple transactions-arc executed
serially or sequentially, data is consistent in a database. However, if concurrent transactions with
interleaving operations are executed, some unexpected data and inconsistent result may occur
Data interference is usually caused by a write operation among transactions on the same set of data
in DBMS. For example, the lost update problem may occur when a second transaction writes a
second value of data content on top of the first value written by a first concurrent transaction. Other
Problems such as the dirty read problem, the incorrect summary problem
Concurs v Conti fechnic iz
The following techniques are the various concurrency control techniques. They are:
1. concurrency control by Locks
2. Concurrency Control by Timestamps
3. Concurrency Control by Validation
1, Concurrency control by Locks
A lock is nothing but a mechanism that tells the DBMS whether a particular data item is
being used by any transaction for read/write purpose.
‘There are two types of operations, i.e, read and write, whose basic nature are different, the
locks for read and write operation may behave differently.
The simple rule for locking can be derived from here. Ifa transaction is reading the content
of a sharable data item, then any number of other processes can be allowed to read the
content of the same data item. But if any transaction is writing into a sharable data item,
then no other transaction will be allowed to read or write that same data item
Depending upon the rules we have found, we can classify the locks into two types
‘Shared Lock: A transaction may acquire shared lock on a data item in order to read its content
‘The lock is shared in the sense that any other transaction can acquire the shared lock on that same
data item for reading purpose.
Exclusive Lock: A transaction may acquire exclusive lock on a data item in order to both
_——1ead/writeimto it. The lock is excusive in the sense that no other transaction can acquire any kind of
lock (either shared or exclusive) on that same data item.
‘The relationship between Shared and Exclusive Lock ean be represented by the following table
which is known as Lock Matrix,
SE EERE“Shared ~~ Exclusive
‘Shared TRUE FALSE
Exclusive FALSE FALSE
‘Two Phase Locking Protocol
‘The use of locks has helped us to create neat and clean concurrent schedule. The Two Phase
Locking Protocol defines the rules of how to acquire the locks on a data item and how to release
the locks,
‘The Two Phase Locking Protocol assumes that a transaction can only be in one of two phases.
In this phase the transaction can only acquire locks, but cannot release any lock
voy
‘The transaction enters the growing phase as soon as it acquires the first lock it wants.
Vv
It cannot release any lock at this phase even if it has finished working with a locked data
item,
> Ultimately the transaction reaches a point where all the lock it may need has been acquired
This point is called Lock Point.
® After Lock Point has been reached, the transaction enters the shrinking phase: In this phase
the transaction can only release locks, but cannot acquire any new lock
> The transaction enters the shrinking phase as soon as it releases the first lock after crossing
the Lock Point.
> There are two different versions of the Two Phase Locking Protocol. They are:
1, Strict Two Phase Locking Protocol
2. Rigorous Two Phase Locking Protocol
>In this protocol, a transaction may release all the shared locks after the Lock Point has been
reached, but it cannot release any of the exclusive locks until the transaction commits. This
protocol helps in creating cascade less schedule.A Cascading Schedule is a typical problem faced while creating concurrent schedule Consider
the following schedule onee again,
ci BR
Lock-X (A)
Read A;
A=A- 100;
Write A;
Unlock (A)
Lock-S (A)
Read A;
‘Temp=A*0.1;
Unlock (A)
Lock-X(C)
Read C:
mC + Temp;
Write C;
Unlock (C)
Lock-X (B)
Read B
Be B+ 100,
Write B:
Unlock (B)
+ The schedule is theoretically corect, but avery strange kind of problem may arise here
T releases the exclusive lock on A, and immediately after that the Context Switch is made
acquires-2-shared lock-on.A.1o reed i-value_pesform-a caleulation_-pdate-the- content of
‘account C and then issue COMMIT. However, TI is not finshed yet. What if the remaining
portion of TI encounters a problem (power failure, disc failure etc) and cannot be committed?.
an exclusive lock.
that are assigned-based-on- their age:
instruction ty of transaction Tw then it can be said that ts i executed before by if and only if Ts(T 4)
i) Ts(Ta) < WTS(x)
= ii) Ts(Ta) GOWTS(x)
Case |; If a transaction Ta wants to read the initial value of some data item x that had been
‘overwritten by some younger transaction then, the transaction T, cannot perform the read
operation and therefore the transaction must be rejected. Then the transaction Ta must be rolled
and restarted with a new timestamp.
r ‘ase 2: Ifa transaction T, wants to read the initial value of some data item x that had not been
— updated then the transaction can execute the read operation. Once the value has been read,
gn conte read umestamp val (RTS(x)) which is set to the largest value of RTS(x} and
y
. ‘ii) Logical Counter: When a transaction enters the system. then it is assigned a timestamp whichis |2) IFTA executes write(x) instruction, then the following two cases must be considered,
i) Ts(Ta) < RTS(x)
ii) Ts(Ta) < WTS(x)
iii) Ts(Ta) >OWTS(x)
L emasl
| Case I: Meg senan (swale to eine fig vats of anne data gaze x oo which We «
yperation has been performed by some younger transaction, then the transaction cannot execu
he write operation. This is because the value of data item x that is being generated by Tx
‘equired previously and therefore, the system assumes that the value will never be generated.
write operation is thereby rejected and the transaction T, must be rolled back and should
' -estarted with new timestamp value.
|
Case 2 \fa transaction T, wants to write a new value to some data item x, that was overwritt
| ee cn ene a raiain eana teal
‘9 inconsistency of data item. ‘Therefore, the write operation is rejected and the transaction
2 rolled back with a new timestamp value.
Ue
Case 3 - Ifa transaction Ta wants to write a new value on some data item x that was not
dy a younger transaction, then the transaction can executed the write operation. Once the value
seen written, changes occur on WTS(x) value which is set to the value of Ts(T'4).
A,
2xample:
The above schedule can be executed under the timestamp protocol when Ts{T 1} < Ts(T2. |
|. Concurrency Control by Validation
Validation techniques are also called as Optimistic techniques.
vy
> [fread only transactions are executed without employing any of the concurrency control
mechanisms, then the result generated 1s m inconsistent state
However if concurrency control schemes are used then the execution of transactions may
be delayed and overhead may be resulted. To avoid such issue, optimistic concurrency
control mechanism is used that reduces the execution overhead
> But the problem in reducing the overhead is that, prior knowledge regarding the conflicting
required to gain such knowledge
Let us consider that every transaction T, is executed in two or three-phases during its life-time
phases involved in optimistic concurrency control are,
eeu
SY
1) Read Phase
2) Validation Phase and
3) Write Phase
Ay Read phase: In this phase, the copies of the data items (their values) are stored in local variables
the modifications are made to these local variables and the actual values are not modified in
is phase.
WN
checked upon each update. If the conflicts occur between the transaction, then it is aborted and
transactions will not be known, Therefore, a mechanism called “monitoring” the system 1s
WZ Validation Phase: This phase follow's the read phase where the assurance of the serializability |
else it is committed.
Write Phase : The successful completion of the validation phase leads to the write phase in
rhich all the changes are made to the orginal copy of data items, This phase is applicable only to
Ae read-write transaction. Each transaction ts assigned three timestamps as follows,
i) When execution is initiated (T)
ii) At the start of the validation phase V(T)
ui) At the end of the validation phase E(T)Qualifying conditions for successful validation:
Consider two transactions, transaction Ta, transaction Ts and let the timestamp of transact
Ta is less than the timestamp of transaction Tp ie:, Ts (Tx) < Ts (Ta) then,
PILLS
1) Before the start of transaction Ts, transaction Tx must complete its execution. i¢., E(Ta) < MT
2) The values written by transaction T must not be necessarily matched with the values read by . a
transaction Ty. T must execute the write phase before Tp initiate the execution of validation pha
‘Le. Tp) < E(Ta) < V(Ta)
| 3) If transaction T. starts its execution before transaction Ts completes. then the write phase
transaction Ts must be finished before transaction T, starts the validation phase.
i) The efficiency of optimistic techniques lie in the scarcity of the conflicts.
ii) It doesn’t cause the significant delays.
iti) Cascading rollbacks never occurs.
fafa Pe oaaee
Disadvantages:
i) Wastage in processing time during the rollback of aborting transactions which are very
ji) Hence, when one process is m its critical section ( a portion of its code), no other process,
allowed to enter. This is the principal of mutual exclusion,
|
Weennnn ania,