Professional Documents
Culture Documents
Distributed Transactions (A) Flat Transaction (B) Nested Transactions
Distributed Transactions (A) Flat Transaction (B) Nested Transactions
1 Distributed transactions
X M
T
11
X
Client T1 N
T
Y T
12
T T
T
21
Client T
2
Y
Z P
T
22
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 1
Figure 13.2 Nested banking transaction
X
Client T1 A a.withdraw(10)
T
T = openTransaction
openSubTransaction Y
a.withdraw(10); T
2 B b.withdraw(20)
openSubTransaction
b.withdraw(20);
openSubTransaction Z
c.deposit(10);
openSubTransaction T C c.deposit(10)
3
d.deposit(20);
closeTransaction T D d.deposit(20)
4
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 2
Figure 13.3 A distributed banking transaction
coordinator
join participant
openTransaction
closeTransaction A a.withdraw(4);
.
join
BranchX
T participant
b.withdraw(T, 3);
Client B b.withdraw(3);
T = openTransaction
a.withdraw(4); join BranchY
c.deposit(4);
b.withdraw(3); participant
d.deposit(3); c.deposit(4);
closeTransaction C
D d.deposit(3);
BranchZ
Note: the coordinator is in one of the servers, e.g. BranchX
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 3
Figure 13.4 Operations for two-phase commit protocol
canCommit?(trans) Yes / No
Call from coordinator to participant to ask whether it can commit a transaction.
Participant replies with its vote.
doCommit(trans)
Call from coordinator to participant to tell participant to commit its part of a
transaction.
doAbort(trans)
Call from coordinator to participant to tell participant to abort its part of a transaction.
haveCommitted(trans, participant)
Call from participant to coordinator to confirm that it has committed the transaction.
getDecision(trans) Yes / No
Call from participant to coordinator to ask for the decision on a transaction after it
has voted Yes but has still had no reply after some delay. Used to recover from server
crash or delayed messages.
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 4
Figure 13.5 The two-phase commit protocol
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 5
Figure 13.6 Communication in two-phase commit protocol
Coordinator Participant
haveCommitted 4 committed
done
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 6
Figure 13.7 Operations in coordinator for nested transactions
openSubTransaction(trans) subTrans
Opens a new subtransaction whose parent is trans and returns a unique
subtransaction identifier.
getStatus(trans) committed, aborted, provisional
Asks the coordinator to report on the status of the transaction trans. Returns values
representing one of the following: committed, aborted, provisional.
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 7
Figure 13.8 Transaction T decides whether to commit
T abort (at M)
11
T1 provisional commit (at X)
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 8
Figure 13.9 Information held by coordinators of nested transactions:
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 9
Figure 13.10 canCommit? for hierarchic two-phase commit protocol
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 10
Figure 13.12 Interleavings of transactions U, V and W
U V W
d.deposit(10) lock D
b.deposit(10) lock B
a.deposit(20) lock A at Y
at X
c.deposit(30) lock C
b.withdraw(30) wait at Y at Z
c.withdraw(20) wait at Z
a.withdraw(20) wait at X
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 11
Figure 13.13 Distributed deadlock
(a) (b)
W W
Held by Waits for
C D A
Z X
V
Held
Waits Held by by
for
V U U
B Waits for
Held
by
Y
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 12
Figure 13.14 Local and global wait-for graphs
local wait-for graph local wait-for graph global deadlock detector
T
T U V T
U V
X Y
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 13
Figure 13.15 Probes transmitted to detect deadlock
W
W U V W Held by Waits for
Deadlock
detected C
A
Z
Initiation X
W
Waits
for U
V
V
U
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 14
Figure 13.16 Two probes initiated
(a) initial situation (b) detection initiated at object (c) detection initiated at object
requested by T requested by W
Waits for T T
W
Waits for T T U T
V
V U W
V
T
U
V
U
U
U
U
W Waits
W
T
W
for Waits
V
W W for
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 15
Figure 13.17 Probes travel downhill
(a) V stores probe when U starts waiting (b) Probe is forwarded when V starts waiting
W W UV probe
Waits V W queue
U for C
U V
U
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 16
Figure 13.18 Types of entry in a recovery file
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 17
Figure 13.19 Log for banking service
P0 P1 P2 P3 P4 P5 P6 P7
Object:A Object:B Object:C Object:A Object:B Trans:T Trans:T Object:C Object:B Trans:U
100 200 300 80 220 prepared committed 278 242 prepared
<A, P1> <C, P5>
<B, P2> <B, P6>
P0 P3 P4
Checkpoint End
of log
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 18
Figure 13.20 Shadow versions
P0 P0' P0" P1 P2 P3 P4
Version store 100 200 300 80 220 278 242
Checkpoint
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 19
Figure 13.21 Log with entries relating to two-phase commit protocol
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 20
Figure 13.22 Recovery of the two-phase commit protocol
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 21
Figure 13.23 Nested transactions
top of stack
T11
T1 A1 A11 A11 A12 A12 A2 A2
T T12 A1 A11 A12
T2
T1 T11 T12 T2
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 Pearson Education 2001 22