3C03 Concurrency: Distributed Transactions
3C03 Concurrency: Distributed Transactions
Anthony Steed
Reading: Connolly & Begg, Database Systems (3rd edition), Sections 23.1, 23.2.1, 23.2.3, 23.4.123.4.3
Wolfgang Emmerich, Anthony Steed, 1998-2003
Outline
Distributed Transaction Processing Centralised & Distributed 2PL Two Phase Commit Protocol (2PC)
Components of a DDBMS
Data Comms Data Comms Coordinator Coordinator Transaction Transaction Manager Manager Transaction Transaction Server Server Data Comms Data Comms Coordinator Coordinator Transaction Transaction Manager Manager Transaction Transaction Client Client Data Comms Data Comms Coordinator Coordinator Transaction Transaction Manager Manager Transaction Transaction Server Server
Roles of Components
Distributed system components involved in transactions can take the following roles:
Transaction Client Transaction Server Transaction Manager Coordinator
Transaction Manager
Manages transaction on behalf of local clients Understands the begin, commit and abort commands
Transaction Coordinator
Coordinator plays key role in managing transaction. Manages both locally and remotely initiated transactions. Coordinator allocates system-wide unique transaction identifier. Different transactions may have different coordinators.
Wolfgang Emmerich, Anthony Steed, 1998-2003
Transactional Server
Every component with a resource accessed or modified under transaction control. Transactional server has to know coordinator for each transaction. Transactional server registers its participation in a transaction with the coordinator. Transactional server has to implement a transaction protocol (e.g. two-phase commit or centralised 2PL).
Wolfgang Emmerich, Anthony Steed, 1998-2003
Transactional Client
Only sees transactions through the transaction manager. Invokes services from the manager to begin, commit and abort transactions. Implementation of transactions are transparent for the client.
10
Complexity
Assuming N participating servers Centralised 2PL:
1 lock request 1 lock grant n update messages n acknowledgements 1 unlock
Distributed 2PL:
n lock request n lock grant n update messages n acknowledgements n unlock
11
Two-Phase Commit
Multiple autonomous distributed servers:
For a commit, all transactional servers have to be able to commit. If a single transactional server cannot commit its changes every server has to abort.
12
Phase One
Called the voting phase. Coordinator asks all servers if they are able (and willing) to commit. Servers reply:
Ready: it will commit if asked, but does not yet know if it is actually going to commit. Abort: immediately aborts its operations. A server might not reply (maybe it died)
Hence, servers can unilaterally abort but not unilaterally commit a transaction.
Wolfgang Emmerich, Anthony Steed, 1998-2003
13
Phase Two
Called the completion phase. Co-ordinator collates all votes, including its own, and decides to
commit if everyone voted Ready. abort if anyone voted Abort or doesnt vote within a short period.
14
Server Uncertainty
Period when a server must be able to commit, but does not yet know if has to. This period is known as server uncertainty. Usually short (time needed for coordinator to receive and process votes). However, failures can lengthen this process, which may cause problems.
Wolfgang Emmerich, Anthony Steed, 1998-2003
15
Complexity
Assuming N participating servers and in addition to updates on actual databases:
(N-1) Voting requests from coordinator to servers. (N-1) Completion requests from coordinator to servers.
16
Initial Initial
Prepare Received Abort Sent
Waiting Waiting
All Received or timeout
Prepared Prepared
Abort Sent
Commit sent
Acknowledgement
Aborted Aborted
Committed Committed
17
Top level transaction needs to be able to communicate its decision down to all subtransactions so they may react accordingly.
Wolfgang Emmerich, Anthony Steed, 1998-2003
18
Coordinator
Bank1
Bank2
Summary
Centralised and Distributed Two Phase Locking
Trade-off between reliability and performance
20