how two phase commit ensure serializability

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.