Professional Documents
Culture Documents
TRANSACTIONS
Flat and Nested
Committing a Distributed Transaction
X
Client T1 N
T T 12
Y
T
T
T
21
T2
Client
Y
P
Z
T
22
X
Client T1 N
T T 12
Y
T
T
T
In the nested case, sub-transactions at the same 21
T2
level can run concurrently,Client
so T1 and T2 are
concurrent, and as they invoke objects in
different servers, they can run in parallel. Y
P
Z
T
22
A flat client transaction completes each of its requests
before going on to the next one. Therefore, each transaction
May 2018 accesses
Distributed servers’ objects sequentially
Transactions 4
Nested Banking Transaction
client transfers $10 from A to C and then transfers $20 from B to D
X
Client T A a.withdraw(10)
1
T
T = openTransaction Y
openSubTransaction T B b.withdraw(20)
2
a.withdraw(10);
openSubTransaction
b.withdraw(20); Z
openSubTransaction
c.deposit(10); T
3 C c.deposit(10)
openSubTransaction
d.deposit(20); T D d.deposit(20)
4
closeTransaction (T)
May 2018 Distributed Transactions 5
Nested Banking Transaction
client transfers $10 from A to C and then transfers $20 from B to C
X
Requests can be run in Client T A a.withdraw(10)
parallel - 1
with several servers, the T
nested transaction is
more efficient
T = openTransaction Y
openSubTransaction T B b.withdraw(20)
2
a.withdraw(10);
openSubTransaction
b.withdraw(20); Z
openSubTransaction
c.deposit(10); T
3 C c.deposit(10)
openSubTransaction
d.deposit(20); T D d.deposit(20)
4
closeTransaction (T)
May 2018 Distributed Transactions 6
The Coordinator of a Flat
Distributed Transaction
◦ Servers execute requests in a distributed transaction
◦ When it commits they must communicate with one another to
coordinate their actions
◦ A client starts a transaction by sending an openTransaction request
to a coordinator in any server
◦ It returns a TID unique in the distributed system(e.g. server ID + local transaction
number)
◦ At the end, it will be responsible for committing or aborting it
◦ Each server managing an object accessed by the transaction is a
participant - it joins the transaction
◦ A participant keeps track of objects involved in the transaction
◦ At the end it cooperates with the coordinator in carrying out the commit protocol
◦ Note that a participant can call abortTransaction
May 2018 Distributed Transactions 7
A Flat Distributed Banking
Transaction
openTransaction join participant
closeTransaction
A a.withdraw(4);
.
join
Branch X
T
participant
b.withdraw(T, 3);
Client B b.withdraw(3);
T = openTransaction
join Branch Y
a.withdraw(4);
c.deposit(4); participant
b.withdraw(3);
d.deposit(3); C c.deposit(4);
closeTransaction
D d.deposit(3);
Note: the coordinator is in one of the servers, e.g. BranchX
Branch Z
Note that the TID (T) is passed with each request e.g. withdraw(T,3)
May 2018 Distributed Transactions 8
openTransaction goes to the coordinator
A Flat Distributed Banking
Transaction join
openTransaction participant
closeTransaction
A client’s (flat) banking A a.withdraw(4);
transaction involves .
accounts A, B, C and join
D at servers Branch X, Branch X
Branch Y and Branch
Z T
participant
b.withdraw(T, 3);
Client B b.withdraw(3);
T = openTransaction
join Branch Y
a.withdraw(4);
c.deposit(4); Each server is shown with a
participant, which joins the participant
b.withdraw(3);
d.deposit(3); transaction by invoking the join c.deposit(4);
method in the coordinator C
closeTransaction
D d.deposit(3);
Note: the coordinator is in one of the servers, e.g. BranchX
Branch Z
May 2018
Note that the TID (T) isDistributed
passed with each request e.g. withdraw(T,3)
Transactions 9
The Join Operation
◦ The interface for Coordinator includes
◦ openTransaction, closeTransaction and abortTransaction
◦ openTransaction returns a TID which is passed with each operation so that servers
know which transaction is accessing its objects
◦ The Coordinator interface provides an additional method, join,
which is used whenever a new participant joins the transaction:
◦ join(Trans, reference to participant)
◦ Informs a coordinator that a new participant has joined the transaction Trans.
◦ The coordinator records the new participant in its participant list.
◦ The fact that the coordinator knows all the participants and each participant knows
the coordinator will enable them to collect the information that will be needed at
commit time.
ATOMIC COMMIT
PROTOCOLS
1PCP & 2PCP
Distributed Transactions 11
Atomic Commit Protocols
◦ Transaction atomicity requires that at the end,
◦ Either all of its operations are carried out or none of them.
CONCURRENCY
CONTROL IN
DISTRIBUTED
TRANSACTIONS
Locking
Distributed Transactions 20
Concurrency Control in
Distributed Transactions
◦ Each server manages a set of objects and is responsible for
ensuring that they remain consistent when accessed by
concurrent transactions
◦ Therefore, each server is responsible for applying concurrency control to
its own objects.
◦ The members of a collection of servers of distributed transactions are
jointly responsible for ensuring that they are performed in a serially
equivalent manner
◦ Therefore if transaction T is before transaction U in their conflicting
access to objects at one of the servers then they must be in that order at all
of the servers whose objects are accessed in a conflicting manner by both
T and U
Write(B) at Y locks B
U V W
d.deposit(10) lock D
U V at Y b.deposit(10) lock B
a.deposit(20) lock A at Y
V W at Z W U at X
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
C D A
Z X V
Held
Waits Held by by
for U
V U
B Waits for
Held
by •
May 2018 Distributed Transactions 26
Y
Deadlock Detection - Local WAIT-
FOR GRAPHS
◦ Local wait-for graphs can be built, e.g.
◦ server Y: U V added when U requests b.withdraw(30)
◦ server Z: V W added when V requests c.withdraw(20)
◦ server X: W U added when W requests a.withdraw(20)
◦ To find a global cycle, communication between the servers is needed
◦ CENTRALIZED DEADLOCK DETECTION
◦ One server takes on role of global deadlock detector
◦ The other servers send it their local graphs from time to time
◦ It detects deadlocks, makes decisions about which transactions to abort and informs the
other servers
◦ Usual problems of a centralized service - poor availability, lack of fault tolerance and no
ability to scale
◦ Other alternate is when the local graphs are shared with each other and global graph
is created at each participant. A participant can volunteer to release locks.
T
T U V T
U V
X Y