SlideShare a Scribd company logo
5 March, 2002 1
06-06798 Distributed Systems
Lecture 13:
Transactions
in a Distributed Environment
5 March, 2002 2
Overview
• Distributed transactions
– multiple servers
– atomicity
• Atomic commit protocols
– 2-phase commit
• Concurrency control
– locking
– timestamping
– optimistic concurrency control
• Other issues (deadlocks, recovery)
5 March, 2002 3
Transactions
• Definition
– sequence of server operations
– originate from databases (banking, airline reservation, etc)
– atomic operations or sequences (free from interference by
other clients and server crashes)
– durable (when completed, saved in permanent storage)
• Issues in transaction processing
– need to maximise concurrency while ensuring consistency
• serial equivalence/serializability (= same effect as a serial
execution)
– must be recoverable from failures
5 March, 2002 4
Distributed transactions
• Definition
– access objects which are managed by multiple servers
– can be flat or nested
• Sources of difficulties
– all servers must agree to commit or abort
• two-phase commit protocol
– concurrency control in a distributed environment
• locking, timestamps
• optimistic concurrency control
– failures!
• deadlocks, recovery from aborted transactions
5 March, 2002 5
Transaction handling
• Requires coordinator server, with open/close/abort
• Start new transaction (returns unique TID)
openTransaction() -> trans;
• Then invoke operations on recoverable objects
A.withdraw(100);
B.deposit(300)
• If all goes well end transaction (commit or abort)
– closeTransaction(trans) -> (commit, abort);
• Otherwise
– abortTransaction(trans);
5 March, 2002 6
Distributed transactions
• Flat structure:
– client makes requests to more than one server
– request completed before going on to next
– sequential access to objects
• Nested structure:
– arranged in levels: top level can open sub-transactions
– any depth of nesting
– objects in different servers can be invoked in parallel
– better performance
5 March, 2002 7
Distributed transactions
Client
X
Y
Z
X
Y
M
NT1
T2
T11
Client
P
T
T 12
T
21
T
22
(a) Flat transaction (b) Nested transactions
T
T
E.g. TE.g. T1111, T, T1212 can run in parallelcan run in parallel
5 March, 2002 8
How it works...
• Client
– issues openTransaction() to coordinator in any server
– coordinator executes it and returns unique TID to client
TID = server IP address + unique transaction ID
• Servers
– communicate with each other
– keep track of who is who
– coordinator: responsible for commit/abort at the end
– participant: can join(Trans, RefToParticipant)
• manages object accessed in transaction
• keeps track of recoverable objects
• cooperates with coordinator
5 March, 2002 9
Distributed flat banking transaction
..
BranchZ
BranchX
participant
participant
C
D
Client
BranchY
B
A
participantjoin
join
join
T
a.withdraw(4);
c.deposit(4);
b.withdraw(3);
d.deposit(3);
openTransaction
b.withdraw(T, 3);
closeTransaction
T = openTransaction
a.withdraw(4);
c.deposit(4);
b.withdraw(3);
d.deposit(3);
closeTransaction
Note: the coordinator is in one of the servers, e.g. BranchX
coordinator
5 March, 2002 10
One-phase commit
• Distributed transactions
– multiple servers, must either be committed or aborted
• One-phase commit
– coordinator communicates commit/abort to participants
– keeps repeating the request until all acknowledged
• But… server cannot abort part of a transaction:
– when the server crashed and has been replaced...
– when deadlock has been detected and resolved…
• Problem
– when part aborted, the whole transaction may have to be
aborted
5 March, 2002 11
Two-phase commit
• Phase 1 (voting phase)
(1) coordinator sends canCommit? to participants
(2) participant replies with vote (Yes or No); before voting Yes
prepares to commit by saving objects in permanent storage,
and if No aborts
• Phase 2 (completion according to outcome of vote)
(3) coordinator collects votes (including own)
• if no failures and all Yes, sends doCommit to participants
• otherwise, sends doAbort to participants
(4) participants that voted Yes wait for doCommit or doAbort
and act accordingly; confirm their action to coordinator by
sending haveCommitted
5 March, 2002 12
Communication in 2-phase protocol
Coordinator
step
Participant
statusstepstatus
5 March, 2002 12
Communication in 2-phase protocol
Coordinator
step
Participant
statusstepstatus
canCommit?
1
(waiting for votes)
prepared to commit
5 March, 2002 12
Communication in 2-phase protocol
Coordinator
step
Participant
statusstepstatus
canCommit?
1
(waiting for votes)
prepared to commit
Yes 2
(uncertain)
prepared to commit
5 March, 2002 12
Communication in 2-phase protocol
Coordinator
step
Participant
statusstepstatus
canCommit?
1
(waiting for votes)
prepared to commit
Yes 2
(uncertain)
prepared to commit
doCommit3 committed
5 March, 2002 12
Communication in 2-phase protocol
Coordinator
step
Participant
statusstepstatus
canCommit?
1
(waiting for votes)
prepared to commit
Yes 2
(uncertain)
prepared to commit
doCommit3 committed
haveCommitted 4 committed
5 March, 2002 12
Communication in 2-phase protocol
Coordinator
step
Participant
statusstepstatus
canCommit?
1
(waiting for votes)
prepared to commit
Yes 2
(uncertain)
prepared to commit
doCommit3 committed
haveCommitted 4 committed
done
5 March, 2002 13
What can go wrong...
• In distributed systems
– objects stored/managed at different servers
• Server crashes
– participant: save in permanent storage when preparing to
commit, retrieve data after crash
– coordinator: delay till replaced, or cooperative approach
• Messages fail to arrive (server crash or link failure)
– use timeout for each step that may block (but no reliable
failure detector, asynchronous communication)
– if uncertain, participant prompts coordinator by getDecision
– if in doubt (e.g. initial canCommit? or votes missing), abort!
5 March, 2002 14
Nested transactions
• Top-level transaction
– starts subtransactions with unique TID (extension of the
parent TID)
– subtransaction joins parent transaction
– completes when all subtransactions have completed
– can commit even if one of its subtransactions aborted...
• Subtransactions
– can be independent (e.g. act on different bank accounts)
– can execute in parallel, at different servers
– can provisionally commit or abort
– if parent aborts, must abort too
5 March, 2002 15
Nested banking transaction
a.withdraw(10)
c.deposit(10)
b.withdraw(20)
d.deposit(20)
Client A
B
C
T1
T2
T3
T4
T
D
X
Y
Z
T = openTransaction
openSubTransaction
a.withdraw(10);
closeTransaction
openSubTransaction
b.withdraw(20);
openSubTransaction
c.deposit(10);
openSubTransaction
d.deposit(20);
IfIf b.withdrawb.withdraw aborts due to insufficient funds,aborts due to insufficient funds,
no need to abort the whole transactionno need to abort the whole transaction
5 March, 2002 16
Nested two-phase commit
• Used to decide when top-level transaction commits
• Top-level transaction
– is coordinator in two-phase commit
– knows all subtransactions that joined
– keeps record of subtransaction info
• Subtransactions
– report status back to parent
– when abort: reports abort, ignoring children status (now
orphans)
– when provisionally commit: reports status of all child
subtransactions
5 March, 2002 17
Transaction T decides to commit
1
2
T
11
T
12
T
22
T21
abort (at server M)
provisional commit (at N)
provisional commit (at X)
aborted (at Y)
provisional commit (at N)
provisional commit (at P)
T
T
T
5 March, 2002 17
Transaction T decides to commit
1
2
T
11
T
12
T
22
T21
abort (at server M)
provisional commit (at N)
provisional commit (at X)
aborted (at Y)
provisional commit (at N)
provisional commit (at P)
T
T
T
orphansorphans
5 March, 2002 18
Hierarchic two-phase commit
• Multi-level nested protocol
– coordinator of top-level transaction is coordinator
– coordinator sends canCommit? to coordinator of
subtransactions one level down the tree
– propagate to next level down the tree, etc
– aborted subtransactions ignored
– participants collect replies from children before replying
• if any provisionally committed subtransaction found,
prepares the object and votes Yes
• if none found, assume must have crashed and vote No
• Second phase (completion using doCommit)
– same as before
5 March, 2002 19
Concurrency control
• Needed at each server
– to ensure consistency
• In distributed systems
– consistency needed across multiple servers
• Methods
– Locking
• processes run at different servers can lock objects
– Timestamping
• global unique timestamps
– Optimistic concurrency control
• validate transaction at multiple servers before committing
5 March, 2002 20
Locking
• Locks
– control availability of objects
– lock manager held at the same server as objects
– to acquire lock: contact server
– to release: must delay until transactions commit/abort
• Issues
– locks acquired independently
– cyclic dependencies may arise
T: locks A for writing; U: locks B for writing;
T: wants to read B - must wait; U: wants to read A - must wait;
– distributed deadlock detection and resolution needed
5 March, 2002 21
Timestamp ordering
• If a single server...
– coordinator issues unique timestamp to each transaction
– versions of objects committed in timestamp order
– ensures serializability
• In distributed transactions
– coordinator issues globally unique timestamps to the client
opening transaction:
<local timestamp, server ID>
– synchronised clocks sometimes used for efficiency
– objects committed in global timestamp order
– conflicts resolved, or else abort
5 March, 2002 22
Optimistic concurrency control
• If a single server...
– alternative to locking (avoids overhead and deadlocks)
– transactions allowed to proceed but
– validated before allowed to commit: if conflict arises may be
aborted
• transactions given numbers at the start of validation
• serialised according to this order
• In distributed transactions
– must be validated by multiple independent servers (in the
first phase of two-phase commit protocol)
– global validation needed (serialise across servers)
– parallel also possible
5 March, 2002 23
Other issues
• Distributed deadlocks!
– often unavoidable, since cannot predict dependencies and
server crashes possible
– use deadlock detection, priorities, etc
• Recovery
– must ensure all of committed transactions and none of the
aborted transactions recorded in permanent storage
– use logging, recovery files, shadowing, etc
• See textbook for more info
5 March, 2002 24
Summary
• Transactions
– crucial to the running of large distributed systems
– atomic, durable, serializable
– order of updates important
– require two-phase commit protocol
• Distributed transactions
– run on multiple servers
– can be flat or nested
– hierarchical two-phase commit
– concurrency control adapted to distributed environment

More Related Content

What's hot

15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 
Dbms
DbmsDbms
Optimistic Algorithm and Concurrency Control Algorithm
Optimistic Algorithm and Concurrency Control AlgorithmOptimistic Algorithm and Concurrency Control Algorithm
Optimistic Algorithm and Concurrency Control Algorithm
Shounak Katyayan
 
Transaction slide
Transaction slideTransaction slide
Transaction slide
shawon roy
 
Concepts of Data Base Management Systems
Concepts of Data Base Management SystemsConcepts of Data Base Management Systems
Concepts of Data Base Management Systems
Dinesh Devireddy
 
Transaction
TransactionTransaction
Transaction
Amin Omi
 
Transaction states and properties
Transaction states and propertiesTransaction states and properties
Transaction states and properties
Chetan Mahawar
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Gyanmanjari Institute Of Technology
 
Transaction states PPT
Transaction states PPTTransaction states PPT
Transaction states PPT
Pondicherry Central University
 
DBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlDBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency Control
Mukesh Tekwani
 
Transactions
TransactionsTransactions
Transactions
Ketaki_Pattani
 
Ch15
Ch15Ch15
Recovery in Multi database Systems
Recovery in Multi database SystemsRecovery in Multi database Systems
Recovery in Multi database Systems
Moutasm Tamimi
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbms
Nancy Gulati
 
Advanced DBMS presentation
Advanced DBMS presentationAdvanced DBMS presentation
Advanced DBMS presentation
Hindustan Petroleum
 
Transaction processing ppt
Transaction processing pptTransaction processing ppt
Transaction processing ppt
Javed Khan
 
Ch17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theoryCh17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theorymeenatchi selvaraj
 

What's hot (20)

15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Dbms
DbmsDbms
Dbms
 
Unit 06 dbms
Unit 06 dbmsUnit 06 dbms
Unit 06 dbms
 
Optimistic Algorithm and Concurrency Control Algorithm
Optimistic Algorithm and Concurrency Control AlgorithmOptimistic Algorithm and Concurrency Control Algorithm
Optimistic Algorithm and Concurrency Control Algorithm
 
Transaction slide
Transaction slideTransaction slide
Transaction slide
 
Concepts of Data Base Management Systems
Concepts of Data Base Management SystemsConcepts of Data Base Management Systems
Concepts of Data Base Management Systems
 
Transaction
TransactionTransaction
Transaction
 
Transaction states and properties
Transaction states and propertiesTransaction states and properties
Transaction states and properties
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
 
A
AA
A
 
Transaction states PPT
Transaction states PPTTransaction states PPT
Transaction states PPT
 
DBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlDBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency Control
 
Transactions
TransactionsTransactions
Transactions
 
Ch15
Ch15Ch15
Ch15
 
Recovery in Multi database Systems
Recovery in Multi database SystemsRecovery in Multi database Systems
Recovery in Multi database Systems
 
Transaction management transparencies
Transaction management transparenciesTransaction management transparencies
Transaction management transparencies
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbms
 
Advanced DBMS presentation
Advanced DBMS presentationAdvanced DBMS presentation
Advanced DBMS presentation
 
Transaction processing ppt
Transaction processing pptTransaction processing ppt
Transaction processing ppt
 
Ch17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theoryCh17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theory
 

Similar to Lec13s transaction

Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)
Peter R. Egli
 
3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query
M Rezaur Rahman
 
Atomicity for transactions involving foreign server in PostgreSQL
Atomicity for transactions involving foreign server in PostgreSQLAtomicity for transactions involving foreign server in PostgreSQL
Atomicity for transactions involving foreign server in PostgreSQL
Ashutosh Bapat
 
Distributed Transaction
Distributed TransactionDistributed Transaction
Distributed Transaction
Pratik Tambekar
 
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit ProtocolsDistributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Sachin Chauhan
 
DBMS UNIT V.pptx
DBMS UNIT V.pptxDBMS UNIT V.pptx
DBMS UNIT V.pptx
NIVETHA37590
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction Processing
Amrit Kaur
 
9 queuing
9 queuing9 queuing
9 queuing
ashish61_scs
 
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture [WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
WSO2
 
Transactions (Distributed computing)
Transactions (Distributed computing)Transactions (Distributed computing)
Transactions (Distributed computing)Sri Prasanna
 
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
DHANUSHKUMARKS
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactionsNilu Desai
 
19. Distributed Databases in DBMS
19. Distributed Databases in DBMS19. Distributed Databases in DBMS
19. Distributed Databases in DBMSkoolkampus
 
Chapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error RecoveryChapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error Recovery
Kunal Anand
 
4. concurrency control
4. concurrency control4. concurrency control
4. concurrency controlAbDul ThaYyal
 
basil.pptx
basil.pptxbasil.pptx
basil.pptx
YongraeJo
 
Flink Forward Berlin 2017: Piotr Nowojski - "Hit me, baby, just one time" - B...
Flink Forward Berlin 2017: Piotr Nowojski - "Hit me, baby, just one time" - B...Flink Forward Berlin 2017: Piotr Nowojski - "Hit me, baby, just one time" - B...
Flink Forward Berlin 2017: Piotr Nowojski - "Hit me, baby, just one time" - B...
Flink Forward
 
Tranasaction management
Tranasaction managementTranasaction management
Tranasaction management
Dr. C.V. Suresh Babu
 
6 two phasecommit
6 two phasecommit6 two phasecommit
6 two phasecommit
ashish61_scs
 

Similar to Lec13s transaction (20)

Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query
 
Atomicity for transactions involving foreign server in PostgreSQL
Atomicity for transactions involving foreign server in PostgreSQLAtomicity for transactions involving foreign server in PostgreSQL
Atomicity for transactions involving foreign server in PostgreSQL
 
Distributed Transaction
Distributed TransactionDistributed Transaction
Distributed Transaction
 
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit ProtocolsDistributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit Protocols
 
DBMS UNIT V.pptx
DBMS UNIT V.pptxDBMS UNIT V.pptx
DBMS UNIT V.pptx
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction Processing
 
9 queuing
9 queuing9 queuing
9 queuing
 
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture [WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
 
Transactions (Distributed computing)
Transactions (Distributed computing)Transactions (Distributed computing)
Transactions (Distributed computing)
 
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactions
 
19. Distributed Databases in DBMS
19. Distributed Databases in DBMS19. Distributed Databases in DBMS
19. Distributed Databases in DBMS
 
Chapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error RecoveryChapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error Recovery
 
4. concurrency control
4. concurrency control4. concurrency control
4. concurrency control
 
basil.pptx
basil.pptxbasil.pptx
basil.pptx
 
Flink Forward Berlin 2017: Piotr Nowojski - "Hit me, baby, just one time" - B...
Flink Forward Berlin 2017: Piotr Nowojski - "Hit me, baby, just one time" - B...Flink Forward Berlin 2017: Piotr Nowojski - "Hit me, baby, just one time" - B...
Flink Forward Berlin 2017: Piotr Nowojski - "Hit me, baby, just one time" - B...
 
Tranasaction management
Tranasaction managementTranasaction management
Tranasaction management
 
6 two phasecommit
6 two phasecommit6 two phasecommit
6 two phasecommit
 

More from Alvin Setiawan

Penyelesaian pers-biseksi13
Penyelesaian pers-biseksi13Penyelesaian pers-biseksi13
Penyelesaian pers-biseksi13Alvin Setiawan
 
Penyelesaian persamaan-non-linear
Penyelesaian persamaan-non-linearPenyelesaian persamaan-non-linear
Penyelesaian persamaan-non-linearAlvin Setiawan
 
Pengembangan sistem 1 2
Pengembangan sistem 1 2Pengembangan sistem 1 2
Pengembangan sistem 1 2Alvin Setiawan
 
Modul pelatihan ly_x_untuk_jurnal-feb-2cols
Modul pelatihan ly_x_untuk_jurnal-feb-2colsModul pelatihan ly_x_untuk_jurnal-feb-2cols
Modul pelatihan ly_x_untuk_jurnal-feb-2colsAlvin Setiawan
 
Metode numerik-rinaldi-munir-libre
Metode numerik-rinaldi-munir-libreMetode numerik-rinaldi-munir-libre
Metode numerik-rinaldi-munir-libreAlvin Setiawan
 
Metode numerik-buku-ajar-unila
Metode numerik-buku-ajar-unilaMetode numerik-buku-ajar-unila
Metode numerik-buku-ajar-unilaAlvin Setiawan
 
Met num3 persnonl-inier_baru
Met num3 persnonl-inier_baruMet num3 persnonl-inier_baru
Met num3 persnonl-inier_baruAlvin Setiawan
 
Met num02 persamaan non linier
Met num02 persamaan non linierMet num02 persamaan non linier
Met num02 persamaan non linierAlvin Setiawan
 
Membuat dokumen dengan latex ver.0.3
Membuat dokumen dengan latex   ver.0.3Membuat dokumen dengan latex   ver.0.3
Membuat dokumen dengan latex ver.0.3Alvin Setiawan
 
Membangun website e-commerce_berbasis_php_dan_my_sql
Membangun website e-commerce_berbasis_php_dan_my_sqlMembangun website e-commerce_berbasis_php_dan_my_sql
Membangun website e-commerce_berbasis_php_dan_my_sqlAlvin Setiawan
 
M8 perancangan terinci
M8 perancangan terinciM8 perancangan terinci
M8 perancangan terinciAlvin Setiawan
 

More from Alvin Setiawan (20)

Penyelesaian pers-biseksi13
Penyelesaian pers-biseksi13Penyelesaian pers-biseksi13
Penyelesaian pers-biseksi13
 
Penyelesaian persamaan-non-linear
Penyelesaian persamaan-non-linearPenyelesaian persamaan-non-linear
Penyelesaian persamaan-non-linear
 
Pengembangan sistem 1 2
Pengembangan sistem 1 2Pengembangan sistem 1 2
Pengembangan sistem 1 2
 
Pedoman ta2008
Pedoman ta2008Pedoman ta2008
Pedoman ta2008
 
Pbw week 01 basics
Pbw week 01   basicsPbw week 01   basics
Pbw week 01 basics
 
Paper
PaperPaper
Paper
 
Nl eqn lab
Nl eqn labNl eqn lab
Nl eqn lab
 
Modul6
Modul6Modul6
Modul6
 
Modul pelatihan ly_x_untuk_jurnal-feb-2cols
Modul pelatihan ly_x_untuk_jurnal-feb-2colsModul pelatihan ly_x_untuk_jurnal-feb-2cols
Modul pelatihan ly_x_untuk_jurnal-feb-2cols
 
Ml2 f304213
Ml2 f304213Ml2 f304213
Ml2 f304213
 
Micro sim template_2
Micro sim template_2Micro sim template_2
Micro sim template_2
 
Metode numerik-rinaldi-munir-libre
Metode numerik-rinaldi-munir-libreMetode numerik-rinaldi-munir-libre
Metode numerik-rinaldi-munir-libre
 
Metode numerik-buku-ajar-unila
Metode numerik-buku-ajar-unilaMetode numerik-buku-ajar-unila
Metode numerik-buku-ajar-unila
 
Metode regula falsi
Metode regula falsiMetode regula falsi
Metode regula falsi
 
Metode biseksi
Metode biseksiMetode biseksi
Metode biseksi
 
Met num3 persnonl-inier_baru
Met num3 persnonl-inier_baruMet num3 persnonl-inier_baru
Met num3 persnonl-inier_baru
 
Met num02 persamaan non linier
Met num02 persamaan non linierMet num02 persamaan non linier
Met num02 persamaan non linier
 
Membuat dokumen dengan latex ver.0.3
Membuat dokumen dengan latex   ver.0.3Membuat dokumen dengan latex   ver.0.3
Membuat dokumen dengan latex ver.0.3
 
Membangun website e-commerce_berbasis_php_dan_my_sql
Membangun website e-commerce_berbasis_php_dan_my_sqlMembangun website e-commerce_berbasis_php_dan_my_sql
Membangun website e-commerce_berbasis_php_dan_my_sql
 
M8 perancangan terinci
M8 perancangan terinciM8 perancangan terinci
M8 perancangan terinci
 

Lec13s transaction

  • 1. 5 March, 2002 1 06-06798 Distributed Systems Lecture 13: Transactions in a Distributed Environment
  • 2. 5 March, 2002 2 Overview • Distributed transactions – multiple servers – atomicity • Atomic commit protocols – 2-phase commit • Concurrency control – locking – timestamping – optimistic concurrency control • Other issues (deadlocks, recovery)
  • 3. 5 March, 2002 3 Transactions • Definition – sequence of server operations – originate from databases (banking, airline reservation, etc) – atomic operations or sequences (free from interference by other clients and server crashes) – durable (when completed, saved in permanent storage) • Issues in transaction processing – need to maximise concurrency while ensuring consistency • serial equivalence/serializability (= same effect as a serial execution) – must be recoverable from failures
  • 4. 5 March, 2002 4 Distributed transactions • Definition – access objects which are managed by multiple servers – can be flat or nested • Sources of difficulties – all servers must agree to commit or abort • two-phase commit protocol – concurrency control in a distributed environment • locking, timestamps • optimistic concurrency control – failures! • deadlocks, recovery from aborted transactions
  • 5. 5 March, 2002 5 Transaction handling • Requires coordinator server, with open/close/abort • Start new transaction (returns unique TID) openTransaction() -> trans; • Then invoke operations on recoverable objects A.withdraw(100); B.deposit(300) • If all goes well end transaction (commit or abort) – closeTransaction(trans) -> (commit, abort); • Otherwise – abortTransaction(trans);
  • 6. 5 March, 2002 6 Distributed transactions • Flat structure: – client makes requests to more than one server – request completed before going on to next – sequential access to objects • Nested structure: – arranged in levels: top level can open sub-transactions – any depth of nesting – objects in different servers can be invoked in parallel – better performance
  • 7. 5 March, 2002 7 Distributed transactions Client X Y Z X Y M NT1 T2 T11 Client P T T 12 T 21 T 22 (a) Flat transaction (b) Nested transactions T T E.g. TE.g. T1111, T, T1212 can run in parallelcan run in parallel
  • 8. 5 March, 2002 8 How it works... • Client – issues openTransaction() to coordinator in any server – coordinator executes it and returns unique TID to client TID = server IP address + unique transaction ID • Servers – communicate with each other – keep track of who is who – coordinator: responsible for commit/abort at the end – participant: can join(Trans, RefToParticipant) • manages object accessed in transaction • keeps track of recoverable objects • cooperates with coordinator
  • 9. 5 March, 2002 9 Distributed flat banking transaction .. BranchZ BranchX participant participant C D Client BranchY B A participantjoin join join T a.withdraw(4); c.deposit(4); b.withdraw(3); d.deposit(3); openTransaction b.withdraw(T, 3); closeTransaction T = openTransaction a.withdraw(4); c.deposit(4); b.withdraw(3); d.deposit(3); closeTransaction Note: the coordinator is in one of the servers, e.g. BranchX coordinator
  • 10. 5 March, 2002 10 One-phase commit • Distributed transactions – multiple servers, must either be committed or aborted • One-phase commit – coordinator communicates commit/abort to participants – keeps repeating the request until all acknowledged • But… server cannot abort part of a transaction: – when the server crashed and has been replaced... – when deadlock has been detected and resolved… • Problem – when part aborted, the whole transaction may have to be aborted
  • 11. 5 March, 2002 11 Two-phase commit • Phase 1 (voting phase) (1) coordinator sends canCommit? to participants (2) participant replies with vote (Yes or No); before voting Yes prepares to commit by saving objects in permanent storage, and if No aborts • Phase 2 (completion according to outcome of vote) (3) coordinator collects votes (including own) • if no failures and all Yes, sends doCommit to participants • otherwise, sends doAbort to participants (4) participants that voted Yes wait for doCommit or doAbort and act accordingly; confirm their action to coordinator by sending haveCommitted
  • 12. 5 March, 2002 12 Communication in 2-phase protocol Coordinator step Participant statusstepstatus
  • 13. 5 March, 2002 12 Communication in 2-phase protocol Coordinator step Participant statusstepstatus canCommit? 1 (waiting for votes) prepared to commit
  • 14. 5 March, 2002 12 Communication in 2-phase protocol Coordinator step Participant statusstepstatus canCommit? 1 (waiting for votes) prepared to commit Yes 2 (uncertain) prepared to commit
  • 15. 5 March, 2002 12 Communication in 2-phase protocol Coordinator step Participant statusstepstatus canCommit? 1 (waiting for votes) prepared to commit Yes 2 (uncertain) prepared to commit doCommit3 committed
  • 16. 5 March, 2002 12 Communication in 2-phase protocol Coordinator step Participant statusstepstatus canCommit? 1 (waiting for votes) prepared to commit Yes 2 (uncertain) prepared to commit doCommit3 committed haveCommitted 4 committed
  • 17. 5 March, 2002 12 Communication in 2-phase protocol Coordinator step Participant statusstepstatus canCommit? 1 (waiting for votes) prepared to commit Yes 2 (uncertain) prepared to commit doCommit3 committed haveCommitted 4 committed done
  • 18. 5 March, 2002 13 What can go wrong... • In distributed systems – objects stored/managed at different servers • Server crashes – participant: save in permanent storage when preparing to commit, retrieve data after crash – coordinator: delay till replaced, or cooperative approach • Messages fail to arrive (server crash or link failure) – use timeout for each step that may block (but no reliable failure detector, asynchronous communication) – if uncertain, participant prompts coordinator by getDecision – if in doubt (e.g. initial canCommit? or votes missing), abort!
  • 19. 5 March, 2002 14 Nested transactions • Top-level transaction – starts subtransactions with unique TID (extension of the parent TID) – subtransaction joins parent transaction – completes when all subtransactions have completed – can commit even if one of its subtransactions aborted... • Subtransactions – can be independent (e.g. act on different bank accounts) – can execute in parallel, at different servers – can provisionally commit or abort – if parent aborts, must abort too
  • 20. 5 March, 2002 15 Nested banking transaction a.withdraw(10) c.deposit(10) b.withdraw(20) d.deposit(20) Client A B C T1 T2 T3 T4 T D X Y Z T = openTransaction openSubTransaction a.withdraw(10); closeTransaction openSubTransaction b.withdraw(20); openSubTransaction c.deposit(10); openSubTransaction d.deposit(20); IfIf b.withdrawb.withdraw aborts due to insufficient funds,aborts due to insufficient funds, no need to abort the whole transactionno need to abort the whole transaction
  • 21. 5 March, 2002 16 Nested two-phase commit • Used to decide when top-level transaction commits • Top-level transaction – is coordinator in two-phase commit – knows all subtransactions that joined – keeps record of subtransaction info • Subtransactions – report status back to parent – when abort: reports abort, ignoring children status (now orphans) – when provisionally commit: reports status of all child subtransactions
  • 22. 5 March, 2002 17 Transaction T decides to commit 1 2 T 11 T 12 T 22 T21 abort (at server M) provisional commit (at N) provisional commit (at X) aborted (at Y) provisional commit (at N) provisional commit (at P) T T T
  • 23. 5 March, 2002 17 Transaction T decides to commit 1 2 T 11 T 12 T 22 T21 abort (at server M) provisional commit (at N) provisional commit (at X) aborted (at Y) provisional commit (at N) provisional commit (at P) T T T orphansorphans
  • 24. 5 March, 2002 18 Hierarchic two-phase commit • Multi-level nested protocol – coordinator of top-level transaction is coordinator – coordinator sends canCommit? to coordinator of subtransactions one level down the tree – propagate to next level down the tree, etc – aborted subtransactions ignored – participants collect replies from children before replying • if any provisionally committed subtransaction found, prepares the object and votes Yes • if none found, assume must have crashed and vote No • Second phase (completion using doCommit) – same as before
  • 25. 5 March, 2002 19 Concurrency control • Needed at each server – to ensure consistency • In distributed systems – consistency needed across multiple servers • Methods – Locking • processes run at different servers can lock objects – Timestamping • global unique timestamps – Optimistic concurrency control • validate transaction at multiple servers before committing
  • 26. 5 March, 2002 20 Locking • Locks – control availability of objects – lock manager held at the same server as objects – to acquire lock: contact server – to release: must delay until transactions commit/abort • Issues – locks acquired independently – cyclic dependencies may arise T: locks A for writing; U: locks B for writing; T: wants to read B - must wait; U: wants to read A - must wait; – distributed deadlock detection and resolution needed
  • 27. 5 March, 2002 21 Timestamp ordering • If a single server... – coordinator issues unique timestamp to each transaction – versions of objects committed in timestamp order – ensures serializability • In distributed transactions – coordinator issues globally unique timestamps to the client opening transaction: <local timestamp, server ID> – synchronised clocks sometimes used for efficiency – objects committed in global timestamp order – conflicts resolved, or else abort
  • 28. 5 March, 2002 22 Optimistic concurrency control • If a single server... – alternative to locking (avoids overhead and deadlocks) – transactions allowed to proceed but – validated before allowed to commit: if conflict arises may be aborted • transactions given numbers at the start of validation • serialised according to this order • In distributed transactions – must be validated by multiple independent servers (in the first phase of two-phase commit protocol) – global validation needed (serialise across servers) – parallel also possible
  • 29. 5 March, 2002 23 Other issues • Distributed deadlocks! – often unavoidable, since cannot predict dependencies and server crashes possible – use deadlock detection, priorities, etc • Recovery – must ensure all of committed transactions and none of the aborted transactions recorded in permanent storage – use logging, recovery files, shadowing, etc • See textbook for more info
  • 30. 5 March, 2002 24 Summary • Transactions – crucial to the running of large distributed systems – atomic, durable, serializable – order of updates important – require two-phase commit protocol • Distributed transactions – run on multiple servers – can be flat or nested – hierarchical two-phase commit – concurrency control adapted to distributed environment