Tuesday, July 5, 2016

Two Phase Commit Protocol

Two Phase Commit Protocol, Explain 2PC protocol, How does 2 Phase Commit protocol work?, Two phase protocol in handling distributed transactions, 2PC and distributed concurrency control

Two Phase Commit protocol in Distributed Database

Two Phase Commit (2PC) Protocol
Consider a transaction T initiated at site Sitei. And, at that site the transaction coordinator is TCi. When the transaction started, TCi distributes the sub-transactions to the sites where the data needed for those sub-transactions available. When T completed its execution at all the sites at which T has executed, the transaction managers (TMs) of those sites inform TCi about the completion. Then TCi starts the 2PC protocol. It works as follows;

Set of messages used for communication in 2PC protocol are,

<prepare T>
send by the coordinator to all the participating sites for preparing for commit. It is always sent by the coordinator whenever a transaction is ready.
<ready T>
send by the transaction manager of the participating site as reply for <prepare T> message, if the sending site is ready for commit the ongoing transaction.
<abort T>
send by the transaction manager of the participating site and later by the coordinator to all the participating site, if any one or more of the participating sites are not ready to commit.
<no T>
it is the log written to the log file of the local system by the transaction manager of the participating site, if it is not ready to commit (which also send <abort T> to the coordinator)
<commit T>
send by the coordinator if all the sites are ready for a commit.

Phase 1: Transaction Coordinator TCi inserts a <preapare T> message into the log file, and forces the log into stable storage (for example, hard disk) for the recovery purpose. Then it sends <prepare T> message to all the sites where the transaction T is being executed. On receiving such message, the TM of the participating site must decide to commit or not based on its status. If the TM of the receiving site decided not to commit for some reasons (failure of transaction, message failure, locking etc.), it write <no T> to its log, and sends <abort T> message to the coordinator TCi. If the TM is read to commit, then it sends <ready T> message to the coordinator TCi. In both the cases, (i.e., no T, or ready T), the messages first written into the stable storage of that site where it is decided and send back to the coordinator.

Phase 2: when TCi receives reply messages for <prepare T> message, or after the pre-specified time interval, the TCi can decide the fate of the transaction. Transaction T can be committed if it received <ready T> message from all the participating sites of the transaction T. Then TCi write a message <commit T> into its stable storage and send <commit T> to all the participating sites for them to commit the transaction. If any one of the reply is <abort T> or no reply on the specified time interval, the transaction must be aborted. In this case, a <abort T> message must be written into stable storage and sent to all the participating sites to abort as well.


How does 2PC protocol work?

What is two phase commit protocol in distributed transactions

Explain 2PC protocol

What are the two phases in 2PC protocl

How distributed transactions are managed using two phase commit protocol?

No comments:

Post a Comment

Featured Content

Multiple choice questions in Natural Language Processing Home

MCQ in Natural Language Processing, Quiz questions with answers in NLP, Top interview questions in NLP with answers Multiple Choice Que...

All time most popular contents

data recovery