TD_02_Transactions_C..

Transcription

TD_02_Transactions_C..
Transactions
Exercice 1
Pour chacune des exécutions ci-dessous, donner le graphe de sérialisation, et conclure sur la
sérialisabilité des exécutions.
1. r1[x]r2[y]w1[y]r2[x]w2[x]
Conflits :
r1(x)-w2(x) ; r2(y)-w1(y)
Graphe
T1↔T2
Cycle dans le graphe donc exécution non sérialisable
2. r1[x]r1[y]r2[y]w2[z]w1[z]w3[z]w3[x]
Conflits :
r1(x)-w3(x) ; w2(z)-w1(z);w2(z)-w3(z) ; w1(z)-w3(z)
Graphe
Pas de cycle donc exécution sérialisable
3. r1[y]w2[z]w1[z]w3[z]w3[x]w1[x]
Conflits :
w2(z)-w1(z) ;w2(z)-w3(z) ;w1(z)-w3(z) ; w3(x)-w1(x) ;
Graphe
Cycle dans le graphe donc exécution non sérialisable
Exercice 2
Soit les 5 exécutions suivantes :
S1 : r1[x]w1[x]r2[z]r1[y]w1[y]r2[x]w2[x]w2[z]
S2 : r1[x]w1[x]w3[x]r2[y]r3[y]w3[y]w1[y]r2[x]
S3 : r1[x]r3[y]w1[y]w4[x]w1[t]w5[x]r2[z]r3[z]w2[z]w5[z]r4[t]r5[t]
S4 : r1[x]r1[t]r3[z]r4[z]w2[z]r4[x]r3[x]w4[x]w4[y]w3[y]w1[y]w2[t]
S5 : r1[x]r4[x]w4[x]r1[y]r4[z]w4[z]w3[y]w3[z]w1[t]w2[z]w2[t]
Pour chacune de ces exécutions :
1. Trouver le graphe de sérialisation et en déduire si l'exécution est sérialisable.
2. Trouver le résultat de l'exécution en utilisant un verrouillage à 2 phases (on suppose que chaque
transaction effectue un commit à la fin de chaque exécution).
3. Quelles transactions seraient défaites en utilisant un système d'estampillage.
S1 : r1[x]w1[x]r2[z]r1[y]w1[y]r2[x]w2[x]w2[z]
Graphe de Sérialisation :
T1 → T2
Verrouillage 2 phases
r1[x] : acquisition du verrou en lecture (partagé) sur x par T1 et exécution
w1[x] : acquisition du verrou exclusif par T1 sur x
r2[z] : acquisition du verrou partagé sur z par T2
r1[y] : acquisition du verrou partagé sur y par T1
w1[y] : acquisition du verrou exclusif sur y par T1
r2[x] : Verrouillage impossible de x par T2, car T1 a un verrou exclusif sur x
→ T2 est en attente, l'exécution poursuivra quand T1 aura relâché ses verrous (au commit ou rollback).
Estampillage :
r1(x) OK RTM(x)=1
w1(x) OK WTM(x)=1
r2(z) OK RTM(z)=2
r1(y) OK RTM(y)=1
w1(y) OK WTM(y)=1
r2(x) OK RTM(x)=2
w2(x) OK WTM(x)=2
w2(z) OK WTM(z)=2
aucune transaction défaite
S2 : r1[x]w1[x]w3[x]r2[y]r3[y]w3[y]w1[y]r2[x]
Graphe de Sérialisation :
Verrouillage deux phases :
r1[x]w1[x] : OK, T1 verrouille exclusivement x
w3[x] : T3 en attente de T1
r2[y] : OK, T2 possède un verrou partagé sur y
w1[y] : T1 attend T2
r2[x] : T2 attend T1
Situation d'interblocage. T2 sera certainement annulée (rollback libérant ses verrous).
Les transactions pourront alors se poursuivre
Estampillage :
r1(x) OK RTM(x)=1
w1(x) OK WTM(x)=1
w3(x) OK WTM(x)=3
r2(y) OK RTM(y)=3
r3(y) OK RTM(y)=3
w3(y) OK WTM(y)=3
w1(y) non => transaction 1 défaite
r2(x) non => transaction 2 défaite
S3 : r1[x]r2[x]w2[x]r3[x]r4[z]w1[x]w3[y]w3[x]w1[y]w5[x]w1[z]w5[y]r5[z]
Graphe de Sérialisation :
Verrouillage deux phases :
r1[x]r2[x] : OK
w2[x] : mise en attente de T2, T2 attend T1
r3[x] : OK
r4[z] : OK
w1[x] : mise en attente de T1, T1 attend T2
…..
Estampillage :
r1(x) OK RTM(x)=1
r2(x) OK RTM(x)=2
Grégory Fonlupt - Transactions - 2/5
w2(x) OK WTM(x)=2
r3(x) OK RTM(x)=3
r4(z) OK RTM(z)=4
w1(x) non => transaction 1 défaite
w3(y) OK WTM(y)=3
w3(x) OK WTM(x)=3
w5(x) OK WTM(x)=5
w5(y) OK WTM(y)=5
r5(z) OK RTM(z)=5
S4 : r1[x]r3[y]w1[y]w4[x]w1[t]w5[x]r2[z]r3[z]w2[z]w5[z]r4[t]r5[t]
Graphe de Sérialisation :
Verrouillage 2 phases :
r1[x]r3[y] : OK
w1[y]T1 attend T3
w4[x] T4 attend T1
w5[x] : T5 attend T1
r2[z]r3[z] : OK
T3 Terminée, T1 reprend
w1[y]w1[t]
T1 terminée, T4 ; T3 reprennent
w4[x]
w5[x] T5 attend T4
w2[z]r4[t] : ok
T4 terminée, T5 reprend
w5[x]w5[z]r5[t]
Estampillage :
r1(x) OK RTM(x)=1
r3(y) OK RTM(y)=3
w1(y) non => transaction 1 défaite
w4(x) OK WTM(x)=4
w5(x) OK WTM(x)=5
r2(z) OK RTM(z)=2
r3(z) OK RTM(z)=3
w2(z) non => transaction 2 défaite
w5(z) OK WTM(z)=5
r4(t) OK RTM(t)=4
r5(t) OK RTM(t)=5
S5 : r1[x]r1[t]r3[z]r4[z]w2[z]r4[x]r3[x]w4[x]w4[y]w3[y]w1[y]w2[t]
Graphe de Sérialisation :
Verrouillage 2 phases :
r1[x]r1[t]r3[z]r4[z] OK
w2[z] Bloquée, T2 attend T3 et T4
Grégory Fonlupt - Transactions - 3/5
r4[x]r3[x] OK
w4[x] Bloquée, T4 attend T1 et T3
w3[y] OK
w1[y] Bloquée T1 attend T3
C3 (Fin de T3 seule transaction non bloquée)
w1[y] OK
C1 (Fin de T1)
w4[x]w4[y] OK
C4 (Fin de T4)
w2[z]w2[t] OK
C2
Ordre d'exécution obtenu : r1[x]r1[t]r3[z]r4[z]r4[x]r3[x]w3[y]C3w1[y]C1w4[x]w4[y]C4 w2[z]w2[t]C2
Estampillage :
r1(x) OK RTM(x)=1
r1(t) OK RTM(t)=1
r3(z) OK RTM(z)=3
r4(z) OK RTM(z)=4
w2(z) non => transaction 2 défaite
r4(x) OK RTM(x)=4
r3(x) OK RTM(x)=4
w4(x) OK WTM(x)=4
w4(y) OK WTM(y)=4
w3(y) non => transaction 3 défaite
w1(y) non => transaction 1 défaite
S6 : r1[x]r4[x]w4[x]r1[y]r4[z]w4[z]w3[y]w3[z]w1[t]w2[z]w2[t]
Graphe
Verrouillage 2 phases :
r1[x]r4[x] OK
w4[x] bloquée, T4 attend T1
r1[y]
w3[y] Bloquée T3 attend T1
w1[t] OK
w2[z]
C1
w4[x]
r4[z] Bloquée T4 attend T2
w3[y]
w3[z] Bloquée T4 attend T2
w2[t]
C2
r4[z]w4[z]
C4
w3[z]
C3
Ordre d'exécution obtenu : r1[x]r4[x]r1[y]w1[t]w2[z]C1w4[x]w3[y]w2[t]C2r4[z]w4[z]C4w3[z]C3
Estampillage :
Grégory Fonlupt - Transactions - 4/5
r1(x) OK RTM(x)=1
r4(x) OK RTM(x)=4
w4(x) OK WTM(x)=4
r1(y) OK RTM(y)=1
r4(z) OK RTM(z)=4
w4(z) OK WTM(z)=4
w3(y) OK WTM(y)=3
w3(z) non => transaction 3 défaite
w1(t) OK WTM(t)=1
w2(z) non => transaction 2 défaite
Grégory Fonlupt - Transactions - 5/5

Documents pareils