Vous êtes sur la page 1sur 4

05/01/2016

CS460/660PracticeExercises

PracticeExercisesonTransactions
Solutions
Serializable,ConflictSerializable,Recoverable,andCascadelessSchedules
Recallthat:
Ascheduleisserializableifitseffectsareequivalenttotheeffectsofsomeserialschedule.
Ascheduleisconflictserializableifitcanbetransformedintoaserialscheduleby
swappingpairsofnonconflictingactions.Twoactionconflictiftheyinvolvethesamedata
itemandatleastoneofthemisawrite.
Ascheduleisrecoverableifeverytransactioncommitsonlyafteralltransactionswhose
changestheyreadhavecommitted.
Ascheduleiscascadelesswhenitavoidsdirtyreads:readsofdatathathavebeenmodified
byuncommittedtransactions.
Intheexercisesbelow,determinewhetherornottheprovidedschedulehaseachoftheabove
properties.
1. ScheduleA:
T1
read(X)

write(Y)

commit

T2

read(X)

write(Y)

commit

Isthisscheduleserializable?
Yes,becauseitseffectsareequivalenttothoseoftheserialscheduleT1T2inboth
schedules,T1andT2readtheinitialvalueofX,neithertransactionreadsavalue
writtenbytheother,andT2performsthefinalwriteofY.
...conflictserializable?
Yes,it'sequivalenttotheserialscheduleinwhichT1performsallofitsoperations
andthenT2performsallofitsoperations.Toseethis,wenotethatT2'sreadofX
doesnotconflictwithT1'swriteofY,becausethetwooperationsinvolvedifferent
dataitems.So,thesetwooperationscanbeswappedtogiveustheserialschedule
T1T2(notethatthecommitsdonotmatterwhenitcomestodeterminingconflict
serializability).
...recoverable?
Yes,becausetherearenodirtyreadsi.e.,therearenosituationsinwhichone
transactionreadsavaluethathasbeenwrittenbyanothertransactionthathasyetto
commit.Therefore,there'snoneedtoworryabouttheorderinwhichthetransactions
commit.
...cascadeless?
Yes,becausetherearenodirtyreads.
http://cspeople.bu.edu/dgs/courses/cs460/lectures/practice/txn_practice_solutions.html

1/4

05/01/2016

CS460/660PracticeExercises

2. ScheduleB:
T1
read(X)

read(X)
write(Y)
commit

T2

write(X)

commit

Isthisscheduleserializable?
No.Thisscheduleisnotequivalenttoeitherofthetwopossibleserialschedules
T1T2orT2T1.It'snotequivalenttoT1T2becauseinourscheduleT1'ssecondread
ofXreadsthevaluewrittenbyT2,butintheserialscheduleT1T2itwouldreadthe
initialvalueofX.It'snotequivalenttoT2T1becauseinourscheduleT1'sfirstread
ofXreadstheinitialvalueofX,butinthescheduleT2T1itwouldreadthevalue
writtenbyT2.
...conflictserializable?
No.Wecan'tuseswapsofconsecutivenonconflictingoperationstotransformthis
scheduleintoaserialschedule.Therearetwodifferentpairsofoperationsthat
conflictandsocannotbeswapped:(1)T1:read(X)(thefirsttime)/T2:write(X),and
(2)T2:write(X)/T1:read(X)(thesecondtime).SincewecannotmoveT2'swrite(X)
eitherbeforeorafterallofT1'soperations,there'snowaytoproduceaconflict
equivalentserialschedule.
...recoverable?
No,becauseT1performsadirtyread(readingavalueofXwrittenbyT2beforeT2
commits)andT1commitsbeforeT2does.IfthesystemweretocrashafterT1
committedbutbeforeT2committedorifT2weretoabortafterT1committedthe
systemcouldbeputintoaninconsistentstate,becausetherollbackofT2shouldundo
T2'swriteofX,andyetT1couldhaveperformedanactionbasedonthatwrite.
...cascadeless?
No,becauseT1performsadirtyread.
3. ScheduleC:
T1
read(X)

read(X)
write(Y)

commit

T2

write(X)

commit

Isthisscheduleserializable?
No.Again,apartfromtheorderofthecommitsthisisthesamescheduleasschedule
B,soit'sstillnotequivalenttoeitherofthetwopossibleserialschedules.
...conflictserializable?
http://cspeople.bu.edu/dgs/courses/cs460/lectures/practice/txn_practice_solutions.html

2/4

05/01/2016

CS460/660PracticeExercises

No.Asidefromtheorderingofthecommits,thisisthesamescheduleasscheduleB,
sowestillcan'tperformswapsofconflictingactionstogetaserialschedule.
...recoverable?
Yes.AlthoughT1stillperformsadirtyreadinthisschedule,itnowcommitsafter
T2,whichsatisfiestherequirementforarecoverableschedule.IfT2'swriteisundone
byacrashorabort,T1canalsoberolledback,sinceitwon'thavecommittedyet.
Whilesuchacascadingrollbackisundesirable,itpreventsusfromapossible
inconsistentstate.
...cascadeless?
No,becauseT1stillperformsadirtyread.
4. ScheduleD:
T1

read(A)

write(A)

commit

T2
read(A)

read(B)

write(A)

commit

T3

read(B)

write(A)

commit

Isthisscheduleserializable?
No.Inourschedule,T2'sr(A)readstheinitialvalueofA,butinanyserialschedule
inwhichT1comesbeforeT2,itwouldreadthevalueofAwrittenbyT1,soitcan't
beequivalenttoanyserialscheduleinwhichT1comesbeforeT2.Similarly,inour
schedule,T1'sr(A)readstheinitialvalueofA,butinanyserialscheduleinwhichT2
comesbeforeT1,itwouldreadthevalueofAwrittenbyT2,soitcan'tbeequivalent
toanyserialscheduleinwhichT2comesbeforeT1.Sinceineverypossibleserial
scheduleT1musteithercomebeforeorafterT2,thisscheduleisnotviewequivalent
toanypossibleserialschedule.
...conflictserializable?
No.Wecanseethisbynotingthatwecan'tmoveallofT1'soperationsafterallof
T2'soperations,sincewecan'tswapT1'sw(A)withT2'sw(A)becausetheyconflict,
andwealsocan'tmoveallofT1'soperationsbeforeallofT2'soperations,sinceT1's
w(A)conflictswithT2'sr(A).ThismeansthatT1canneithercomebeforenorafter
T2,whichmeansaconflictequivalentserialscheduleisimpossiblehere.
...recoverable?
Yes,becausetherearenodirtyreadsi.e.,therearenosituationsinwhichone
transactionreadsavaluethathasbeenwrittenbyanothertransactionthathasyetto
commit.Therefore,there'snoneedtoworryabouttheorderinwhichthetransactions
commit.
...cascadeless?
http://cspeople.bu.edu/dgs/courses/cs460/lectures/practice/txn_practice_solutions.html

3/4

05/01/2016

CS460/660PracticeExercises

Yes,becausetherearenodirtyreads.
5. ScheduleE:
T1
read(X)(1)

write(Y)(3)

read(Z)(12)
write(Z)(13)

T2

read(X)(2)

read(Y)(5)
write(X)(6)

T3

read(Y)(4)

read(W)(7)
write(Y)(8)

T4

read(W)(9)
read(Z)(10)
write(W)(11)

Drawaprecedencegraphtodetermineifthisscheduleisconflictserializable.
I'venumberedtheoperationsabovetomakethegrapheasiertodraw.Weaddanedge
fromtransactionAtotransactionBinthegraphiftransactionAwouldhavetocome
beforetransactionBinaserialschedulebecausethereisanoperationintransactionA
thatcomesbeforeaconflictingoperationintransactionB.Forexample:transaction
A:W(X)transactionB:R(X)there'snowayforustoswaptheseoperationssothat
transactionBcomesfirst.
Ifweendupwithacycleinthegraph,itmeansthatwehaveanimpossiblesituation
(eg.,transactionAcomesbeforetransactionB,andtransactionBcomesbefore
transactionA)andthescheduleisnotconflictserializable.
Hereistheprecedencegraph:

Asyoucansee,therearecyclesinthegraph:T1>T3>T4>T1andT1>T2>T3
>T4>T1.Thismeansthatthescheduleisnotconflictserializable.

http://cspeople.bu.edu/dgs/courses/cs460/lectures/practice/txn_practice_solutions.html

4/4

Vous aimerez peut-être aussi