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

Adobe Scan 09 Dec 2024

Uploaded by

Aman Sharma
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)
11 views

Adobe Scan 09 Dec 2024

Uploaded by

Aman Sharma
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/ 8

done.

) work the undo used


to Rollback:
isIt
permanently.) done work the save used
to
Commit:
isIt
operations: important two have problem,
we this solve -To
bank. thacceptable
e by not whi
ischdatabase the in remain
4000
X's thenoperation2 executing after transaction
fails debitransaction,
t the wil value
above Forexample:
the inIf
transaction c.
that etpower, software set. thoperations
e in the fnished
all before fail may
or hardware, failure
of the becauseof thatpossible bemay itBut
3500. bewil vahue final X's database So the val
to ue buffer's the write operation
wil
3500. contain third The
wil buffer So500. ofby X value decreasethe operation
wil second The
buffer. ainstoresit database
and from value X's readsoperation first The
)
4000.transaction
is the starting
of before a_sume
the of
Xvalue Let's
W(X); 3.
500; X=X- 2.
operations: follow
ing consists
of which account transaction
an
from debit Considera Exampk: R(X);
bufter. the fromdatabase the to back value the write usedtooperation
is WrWrite(X):
ite
main bufter
in ainstoresit database
and the from Xofvalue the read to
usedoperationis memory.
Read ad(1): Re
transaction: operations
of inma
the are Follow
ing action: ofTrans rations Ope
Cose_Account(Y) 5. Cbse_Account(X) 5.
Baance New Y.balance= 4. Bakance New X.balance= 4.
=Okd_Baance
800 + New_Balance 3. Old_Balance
800 - New_Balance= 3.
Y.balance Bakance= Okd X.balance Bakance= Ok
Open_Account(Y) 1.2 _Account(X) Open 1.
Account: Y's Account: X's
tasks:low-level several contanstransaction
small Thiaccount.
s Y's account
to X's from 800 transfers
Rs bank employee
of Suppose
an Example :
database. the contents
of accessing
the
operations
for pertorm to
user singk performed
aby actions.
isIt series
of action
or transaction an is A
tasks. group
of containsa operation.
It related logicaly of
transaction
set ais Theaction: Trans
Unit-4
600+300=900 Toccurs
= before Total 1.
transaction. the after before
or ined mainta bemust amount total example:
The For
state.consistent
another tostate
consistent one fromdatabase transform
the tousedtransaction
is The "
instance.
database consistent transaction
seesa every that statesdatabase property
of consistent The "
state. stable
new aor
state stable prior either
ts database
in leavea transaction
wil execution
aof The .
transaction. the after and
before consistent database
is the that so
ined mainta constraints
are integrity The ncy: iste Cons
entirely. executed
in be
transaction
must thestate,database correctness
of ensure to
order state.
In database inconsistent
theshows This B.added
to not but fromAdeducted bewilamount the then transaction
T2,
completion
of before transaction
but T1 completion
of the after failstransaction
T the If
400. Rs
consists
of andB 500 Rsconsists
of transaction,
A completion
the of After
Write(B) Write(A)
Y+l00 Y= A-100 A=
Read(B) Read(A)
T2
B.
account account
to A from 100 Transfer
Rs 300. consists
Rs of Band 600
Rs
consists
of AT2. and ofTIconsisting transaction
T following thatassume LetExample:
's
visible. are made changes the al then commits transaction Commit:
a If
visible. not are made changes the al then abortstransaction If
aAbort:
operations: following
two involves
the Atomicity
all.executed
at not completion
isor torun either and unit one
treated
as transaction
is Each partially. transaction
occur cannot the i.e.,midway, noThere
is "
transaction the not, onceif at transaction aborted. is
place take operations
the of al that states Atomicity:
lt
Durability 4.
Isolation
Consistency 3.
2.
Atomicity 1.
Transaction: Property
of
transaction. the after and before database, consistency
maintain used
to a in
are Theseproperties. four ttransaction
he has Transaction
The rty: prope
Unit-4
this executed
in is
step marks total the display
of final example,a calculation mark total the state.In
the saved
to still data
is the but
operation, final executes
its transaction state,committed
a database. partially committed:
the In not Partially
database. the saved
to not
stil records
are the al But here. done record
is updatinga deletion
or Insertion
or example: For
executed. being
transaction
is the state, thtransaction.
is In every of
state first the state
is active The state: Active
Aborted Falled
End Actlve
Bagin
Committed Committed
Partlally
states. following the ofonc intransaction
becan database,
the Transaction:
a In States
of
property. Durability responsibility
of the hDBMS
as the subsyste
of m covery reThe "
failure. system's aof
event the in be
even lbst, cannot stateconsistent That
state.consistent the known
as state reachesa database the completed,
then transaction
is Whena
lailure. system the transaction
byor faulty operation
aof erroneous the bylost cannot be They "
changes. permanent the transaction
made the that states state.
database's perfornance
the of indicate
the to
used property
is durability Dunbility:
ThIte consistent
property. isolation enforced
the DBMS subsystem
the of control
concurrency The "
ends. transaction
TI the unttransaction
il T2 other any accessed
by be
cant item
data that then X,itenm data thc using executed
and being transaction
isT1 dheisokation,
if In "
completed. isone first the transaction
until second the byused
cannot
betransaction execution
a of of
te the at
used whiisch data the that shows Isolation:It
occur. inconsistency
wil
then lails, 12
compketed
but isTl
when case the consistent.
In database
is Therefore,
the
500+400=900 occurs= aflerT Total 2.
Unt-4
Unit-4

Committed: Atransaction is said to be in acommitted state if t executes all is operations


successtully. In this state, all the eftects are now permanently saved on the database system.
Failed state: If any of the checks made by the database recovery system fails, then the
transaction is said to be in the failed state.
query to fetch the
" In the example of total mark cakculat io n, if the database is not able to fire a
marks, then the transaction will fail to execute.
state then the database
Aborted: If any of the checks fail and the transaction has reached a failed
consstent state. If not then it
recovery system will make sure that the database is in its previous
will abort or roll back the transaction to bring the database into a consistent state.
executing the transaction,
" If the transaction fails in the middle of the transaction then before
all the executed transactions are rolled back to its consistent state.
select one of the two
" After abortng the transaction, the database recovery module will
operations:
1. Re-start the transaction
2. Kill the transaction
Schedule: A series of operation from one transaction to another transactio n is known as
schedue. It is used to preserve the order of the
operation in each of the individ ual transaction.

Schedule

Serial
Schedule
Non-serial Serializable
Schedule Schedule

1. Serial Schedule: The serial schedule is a type of schedule where one transaction is executed
completely before starting another transaction. In the serial schedule, when the first transaction
completes its cyce, then the next transaction is executed.
For example: Suppose there are two transactions TI
has no intereaving of operations, then there are the and T2 which have some operations. If it
following two possible outcomes:
1. Execute all the operations of T1 which was
followed by all the operations of T2.
2. Execute all the operations of TI which was
followed by all the operations of T2.
" In the given (a) figure, Schedule A shows the serial
schedule where TI followed by T2..
" In the given (b) figure, Schedule B shows the serial
schedule where T2 followed by T1.
(a)
T1 T2 (b)
T1 T2
read(A);
A:=A- N:
write(A): read(A):
A:=A + M;
Time read(B); write(A):
B: B+N;
write(B); Time read(A):
A:= A-N;
read(A); write(A);
read(B):
A:=A+ M; B:- B +N;
write(A); write(B);

Schedule A
Schedule B

2. Non-serial Schedule:

" If intereaving of operations is allowed, then there will be non-serial


schedule.
" It contains many possible orders in which the system can execute the individ ual operations of
the transactions.
" In the given figure (c) and (d), Schedule C and Schedule D are the non-serial schedules. It has
interleaving of operations.

(c) (d)
T1 T2 T1 T2

read(A): read(A);
A:- A N: A:A- N;
read(A); write(A);
A:A + M: read(A):
write(A): A:=A+ M:
Time read(B): write(A);:
write(A):
read(B):
B:- B+ N: Time
B:- B+ N:
write(B): write(B):

Schedule Schedule D,

3. Serializable sche dule: The serializability of schedules is used to find non-serial schedules that
alow the transaction to execute concurrently without interfering with one another.

" It identifies which schedules are correct when executio ns of the transaction have interleaving
of their operations.
" Anon-serial schedule will be serializab le if is result is equal to the result of its transactions
executed serially.

Here,

Scheduk A and Schedule B are serial schedule.

Schedule Cand Schedule D are Non-serial scheduke.

Testing of Serializability: Serialization Graph is used to test the Serializability of a schedule.


Assume a scheduke S. For S, we construct a graph known as precedence graph. This graph has a
pair G= (, E), where Vconsists a set of vertices, and Econsists a set of edges. The set of
vertices is used to contain all the transactions participating in the scheduke. The set of edges is
used to contain all edges Ti ->Tj for which one of the three conditions hods:
1. Create a node Ti ’ Tj if Ti executes write (Q) before Tj executes read (Q).
2. Create a node Ti ’ TË if Tiexecutes read (Q) before Tj executes write (0).
3. Create a node Ti ’ TË if Ti executes write (Q) before Tj executes write (Q).

A)
Precedence graph for Schedule S

Ti Tj

Ifa precedence graph contains a single edge Ti Ti, then all the instructions of Ti are
executed before the first nstruction ofTj is executed.
" Ifa precedence graph for schedule S contains a cycle, then S is non-seriali zable. If the
precedence graph has no cycle, then S is known as serializable.

For example:
TI T2 T3

Read(A)
Rcad(B)
A:= fi(A)
Read(C)
B: (B)
Write(B)
C:= f(C)
Time Write(C)
Write(A) Read(B)
Read(A)
A:={(A)
Read(C)
Write(A)
C:= f(C)
Write(C)
B:- (B)
Write(B)
Schedule S1

Explanation:
Read(A): In Tl, DO subsequent writes to A, so no new edges
Read(B): In T2, no subsequent writes to B, so no new edges
Read(C): In T3, no subsequent writes to C, so no new edges
Write (B): B is subsequently read by T3, so add edge T2 ’ T3
Wite(C): Cis subsequently read by T1, so add edge T3 ’ TI -
Write(A): Ais subsequently read by T2, soadd edgeTI ’ T2
Write(A): In T2, no subsequent reads to A, so no new edges
Write(C): In T1, no sbsequent reads to C,so no new edges
Write (B): In T3, no subsequent reads to B, SO no new edges
Precedence graph for schedule S1:

T1

T2 T3
The precedence graph for scheduk Sl contains acycle that's why Scheduke SI is non
serializable.

T5 T6
T4
Read(A)
A:= fi(A)
Read(C)
Write(A)
A:= f2(C)
Read(B)
Write(C)
Read(A)
Read(C)
Time B: f3(B)
Wite(B)
C:- f4(C)
Read(B)
Write(C)
A:=fs(A)
Write(A)
B:= f6(B)
Write(B)

Schedule S2

Explanation:
Read(A): In T4,no subsequent writes to A, so no new edges
Read(C): In T4, no subsequent writes to C, so no new edges
Write(A): A is subsequently read by T5, so add cdge T4 ’ TS V
Read(B): In T5,no subsequent writes to B, so no new edges
Write(C): Cis subsequently read by T6, so add edge T4 ’ T6
Write (B);: Ais subsequently read by T6, so add edge TS ’ T6
Write(C): In T6, no subsequent reads to C, so no new edges
Write(A): In T5, no subsequent reads to A, so no new edges
Write (B): In T6, no subsequent reads to B, so no new edges

Precedence graph for schedule S2:

T5

TA T6

The precedence graph for schedule S2 contains no cycle that's why Schedule S2 is serializable.

You might also like