10 DS - Ch17
10 DS - Ch17
Distributed transactions
(a) Flat transaction (b) Nested transactions
M
X
T11
X
Client T1 N
T Y
T 12
T
T
T21
T2
Client
Y
Z the nested transaction is more P
T22
efficient because requests can
be run in parallel - with
several servers,
A flat client transaction completes each of In the nested case, subtransactions
its requests before going on to the next one. at the same level can run
Therefore, each transaction accesses concurrently, so T1 and T2 are
servers’ objects sequentially concurrent.
Flat and nested distributed transactions
BranchY
Each server is shown with join
a participant, which joins participant
the transaction by C c.deposit(4);
invoking the join method D d.deposit(3);
in the Note:
coordinator
the coordinator is in one of the servers, e.g. BranchX
BranchZ
Note that the TID (T) is passed with each request e.g. withdraw(T,3)
Flat and nested distributed transactions
Coordinator interface
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.
Atomic commit protocols
2
yes
no
3
doCommit
4 doAbort
Concurrency control in distributed transactions
TimeOut Protocol
canCommit?
At step 2 and 3 no
commit decision
made.
no
OK to abort.
Coordinator will
either not collect
doAbort
all commit votes
or will vote for
abort.
Concurrency control in distributed transactions
TimeOut Protocol
1 canCommit?
At step 4
• Cohort cannot
2 communicate with
yes coordinator
3 Coordinator
mayhave decided •Has decided, it just
doCommit
• Cohort must block picks up from where
4
until it left off
communication •A cohort that
re-established crashed after voting
• Might ask other commit, it must block
cohorts. until it discovers.
Concurrency control in distributed transactions
Blocking
1 canCommit? canCommit?
Blocking can
occur if:
2
yes
•Coordinatoor
crashes. no
3
•Cohort cannot
doCommit communicate
4 with coordinator. doAbort
•Between 2 and 4
The TID of a subtransaction is an extension of its parent's TID, so that a
subtransaction can work out the TID of the top-level transaction.
The client finishes a set of nested transactions by calling closeTransaction or
abortTransacation in the top-level transaction.
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.
This is the interface of the coordinator of a subtransaction.
◦ It allows it to open further subtransactions
◦ It allows its subtransactions to enquire about its status A
subtransaction
Client starts by using OpenTransaction to open a top-level starts after its
parent and
transaction.
finishes before
◦ This returns a TID for the top-level transaction it.
◦ The TID can be used to open a subtransaction
◦ The subtransaction automatically joins the parent and a TID is returned.
Transaction T decides whether
12
tooncommit
T has provisionally committed and T has aborted, but the fate of T
depends
11
its parent T and eventually on the top-level transaction, T.
1
12