XA two phase commit protocol

The XA two phase commit protocol works as follows:

The XA transaction coordinator (WebSphere) calls all the Resource Managers (RMs) in the transaction and tells them to Prepare to commit. Typically at this point they write the updates and create logs to enable backout, while locking the newly committed data.

Any RM can abort the transaction, in which case the TM tells everyone to roll back.

Once all participants agree to commit, the TM then tells all the RMs to commit (phase 2). At this point all the logs are cleaned up and locks are removed.

If the server crashes in the middle of this process there may be uncomitted transactions in various logs (WebSphere and the resource managers – databases, queueing systems etc). If you delete the tranlog you may leave data in an inconsistent state, and you may leave a database with locks held against rows that were being modified by the transaction that was inflight. This can be dangerous. Normally bringing up all the RMs and then restarting WAS will cause a normal recovery to occur. There are some cases where it is not automatically clear what needs to be done, and an admin may need to explicity go into the database and force a transaction to go away. You may see this in-doubt situation called “heuristic damage”.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s