0
$\begingroup$

Two phase commit is used in distributed transaction. For example, a client sends a transaction to two databases with a coordinator.

  • step1: client get a global transaction id from coordinator
  • step2: client send the transaction to two databases respectively
  • step3: client send the commit flag to coordinator
  • step4: coordinator send prepare flag to two databases, and two databases response prepare ack
  • step5: coordinator send commit flag to two databases, and two databases response commit ack
  • step6: coordinator response commit ack to client

My questions are

  • What is the global transaction id in step1 used for?
  • And two phase commit is used to ensure the atomic in ACID, but how does it ensure the serializability? For examples, if client A sends transaction A and client B sends transaction B to databases simutaniously, then two databases may execute two transactions in different orders. Then two databases may end with non consistent states.
$\endgroup$
1
$\begingroup$

Let me try to explain this using an example. Suppose there is coordinator and two participants named P1 & P2. Now suppose both P1 & P2 creates a transaction to modify a variable A and no other transaction is raised in between, in this case coordinator know that both participants are doing same this coordinator will raise a commit message indicating that both participants can commit and changes will be saved.

Now let's take other example Suppose variable A depends on variable B, now participant P1 raises message to modify variable A and at the same time participant P2 raises message to modify both B & A, in this case coordinator know that participants are going out of sync by executing these commands so master will decline this transaction since it will not serialize.

An assumption about the outcome of transactions, either commit, or abort, can save both messages and logging operations by the participants during the 2PC protocol's execution. For example, when presumed abort, if during system recovery from failure no logged evidence for commit of some transaction is found by the recovery procedure, then it assumes that the transaction has been aborted, and acts accordingly. [Wikipedia]

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.