Escolar Documentos
Profissional Documentos
Cultura Documentos
Part 2
Exercises on transaction
management
Maurizio Lenzerini, Riccardo Rosati
Corso di laurea magistrale in Ingegneria Gestionale
Sapienza Università di Roma
Anno Accademico 2013/2014
http://www.dis.uniroma1.it/~rosati/gd/
Exercise 1
Data management 2
Exercise 1 – solution (1)
Data management 3
Exercise 1 – solution (2)
Data management 4
Exercise 1 – solution (3)
Data management 5
Exercise 1 – solution (4)
S4 is not view-serializable. If S4 were view-serializable, one of the
following serial schedules should be view-equivalent to S4 (where we
denote by r’1(x) the second read of x done by T1):
S’: r2(x), w2(x), r1(x), r’1(x)
→ READS-FROM(S’)={(r1(x), w2(x)), (r’1(x), w2(x))}
Now, since:
READS-FROM(S4)={(r’1(x), w2(x))}
it follows that there exists no serial schedule which is view-equivalent to
S4!
S4 presents the unrepeatable read anomaly, because T1 reads two
different values for x (without making any update on x in the meantime).
Data management 6
Exercise 2
r1(x), w2(x), r3(x), r1(y), r4(z), w2(y), r1(v), w3(v), r4(v), w4(y), w5(y), w5(z)
Data management 7
Exercise 3
Data management 8
Exercise 4
Illustrate the actions of the universion timestamp-based scheduler
for the following input sequence:
Data management 9
Exercise 4 – solution (1)
• Before the scheduler receives its input, the timestamps are as
follows:
wts(A) = wts(B) = rts(A) = rts(B) = 0, cb(A)=cb(B)=true
• Then, the scheduler reacts as follows (requests → answers →
updates):
– r1(A) → ok → ts(T1)=1, rts(A)=1, since ts(T1)>= wts(A) and
cb(A)=true
– r2(B) → ok → ts(T2)=2, rts(B)=2, since ts(T2)>= wts(B) and
cb(B)=true
– r3(A) → ok → ts(T3)=3, rts(A)=3, since ts(T3)>= wts(A) and
cb(A)=true
– r2(A) → ok → rts(A)=3, since ts(T2)>= wts(A), cb(A)=true
and max(ts(T2),rts(A))=3
– w1(A) → no: T1 is aborted, because ts(T1)<rts(A)=3
– w3(A) → ok → wts(A)=3 e cb(A)=false, because ts(T3)=
rts(A) and ts(T3)>=wts(A)
Data management 10
Exercise 4 – solution (2)
sl2(A), sl2(B), r2(B), sl3(A), r3(A), r2(A), c2, u2(A), xl3(A), w3(A), c3, u3(A), u3(B)
Data management 11
Exercise 5
Data management 12
Exercise 5 - solution
Before the scheduler receives its input, the timestamps are as follows:
wts(A) = wts(B) = rts(A) = rts(B) = 0
Then, the scheduler reacts as follows (requests → answers → updates):
– r1(B) → ok → ts(T1)=1, rts(B)=1, since ts(T1)>= wts(B) and
rts(B)=max(ts(T1),rts(B))
– w1(A) → ok → wts(A)=1 and cb(A)=false, since ts(T1)>= wts(A) and
ts(T1)>= rts(A)
– w2(B) → ok → ts(T2)=3, wts(B)=3 and cb(B)=false, since ts(T2)>=
wts(B) and ts(T2)>= rts(B)
– w1(B) → T1 waits for cb(B)=true (i.e., T1 waits for commit or rollback of
T2), since ts(T1) = rts(B) and ts(T1)<wts(B)
– r2(A) → T2 waits for cb(A)=true (i.e., T2 waits for commit or rollback of
T1)
DEADLOCK!
Data management 13
Exercise 6
Data management 14
Exercise 7
Given the schedule
S = r1(A), r2(B), r3(B), w4(A), r2(A), w5(A), r4(A), r3(A), r5(A),
show the differences between the execution of S by the universion-
based timestamp scheduler and the execution of S by the
multiversion-based timestamp scheduler.
Data management 15