Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:56:18+00:00 2026-05-25T12:56:18+00:00

I believe most of people know what 2PC (two-phase commit protocol) is and how

  • 0

I believe most of people know what 2PC (two-phase commit protocol) is and how to use it in Java or most of modern languages. Basically, it is used to make sure the transactions are in sync when you have 2 or more DBs.

Assume I’ve two DBs (A and B) using 2PC in two different locations. Before A and B are ready to commit a transaction, both DBs will report back to the transaction manager saying they are ready to commit. So, when the transaction manager is acknowledged, it will send a signal back to A and B telling them to go ahead.

Here is my question: let’s say A received the signal and commited the transaction. Once everything is completed, B is about to do the same but someone unplugs the power cable, causing the whole server shutdown. When B is back online, what will B do? And how does B do it?

Remember, A is committed but B is not, and we are using 2PC (so, the design of 2PC stops working, does not it?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:56:18+00:00Added an answer on May 25, 2026 at 12:56 pm

    On Two-Phase Commit

    Two phase commit does not guarantee that a distributed transaction can’t fail, but it does guarantee that it can’t fail silently without the TM being aware of it.

    In order for B to report the transaction as being ready to commit, B must have the transaction in persistent storage (i.e. B must be able to guarantee that the transaction can commit in all circumstances). In this situation, B has persisted the transaction but the transaction manager has not yet received a message from B confirming that B has completed the commit.

    The transaction manager will poll B again when B comes back online and ask it to commit the transaction. If B has already committed the transaction it will report the transaction as committed. If B has not yet committed the transaction it will then commit as it has already persisted it and is thus still in a position to commit the transaction.

    In order for B to fail in this situation, it would have to undergo a catastrophic failure that lost data or log entries. The transaction manager would still be aware that B had not reported a successful commit.1

    In practice, if B can no longer commit the transaction, it would imply that the disaster that took B out had caused data loss, and B would report an error when the TM asked it to commit a TxID that it wasn’t aware of or didn’t think was in a commitable state.

    Thus, two phase commit does not prevent a catastrophic failure from occuring, but it does prevent the failure from going unnoticed. In this scenario the transaction manager will report an error back to the application if B cannot commit.

    The application still has to be able to recover from the error, but the transaction cannot fail silently without the application being made aware of the inconsistent state.

    Semantics

    • If a resource manager or network goes down in phase 1, the
      transaction manager will detect a fatal error (can’t connect to
      resource manager) and mark the sub-transaction as failed. When the
      network comes back up it will abort the transaction on all of the
      participating resource managers.

    • If a resource manager or network goes down in phase 2, the
      transaction manager will continue to poll the resource manager until
      it comes back up. When it re-connects back to the resource manager
      it will tell the RM to commit the transaction. If the RM returns an
      error along the lines of ‘Unknown TxID’ the TM will be aware that
      there is a data loss issue in the RM.

    • If the TM goes down in phase 1 then the client will block until the
      TM comes back up, unless it times out or receives an error due to the
      broken network connection. In this case the client is made aware of
      the error and can either re-try or initiate the abort itself.

    • If the TM goes down in phase 2 then it will block the client until
      the TM comes back up. It has already reported the transaction as
      committable and no fatal error should be presented to the client,
      although it may block until the TM comes back up. The TM will still
      have the transaction in an uncommitted state and will poll the RMs
      to commit when it comes back up.

    Post-commit data loss events in the resource managers are not handled by the transaction manager and are a function of the resilience of the RMs.

    Two-phase commit does not guarantee fault tolerance – see Paxos for an example of a protocol that does address fault tolerance – but it does guarantee that partial failure of a distributed transaction cannot go un-noticed.

    1. Note that this sort of failure could also lose data from previously committed transactions. Two phase commit does not guarantee that the resource managers can’t lose or corrupt data or that DR procedures don’t screw up.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I believe my most recent commit in Mercurial has become corrupt. I cannot commit
I believe I understand properties for the most part. My question is, if I
I believe that quantifying the productivity increase (extra working hours) is the most effective
I believe lot of people already asked this question before, but i kept getting
After learning more about how monotouch works, I believe I know the answer to
I have a coworker that is against type inference in C#. I believe most
I wrote a program to determine the game tree for tic-tac-toe. I believe most
i have a problem which is i believe basic for most of the RoR
I believe there are a lot of similar questions even on stackoverflow. But most
Why do most people say that data services and the database are the most

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.