
When multiple Resource Managers are combined into a single transaction it is commonplace that both Resource Managers
support a two-phase commit protocol.
D.4.3 Commit Protocols
One-phase Commit
A one-phase commit protocol will commit the transaction as a single action. It is most often used when a transaction is involved
with a single Transacted Resource. Most Transacted Resources support a one-phase commit protocol. It is sometimes used in
a last resource commit optimisation.
Two-phase Commit
The two-phase commit protocol prepares all two-phase Resource Managers involved in the transaction. Each Resource Manager
responds whether or not it was able to prepare the transaction. When a Resource Manager responds that it is able to prepare
a transaction, it is making the promise that it will be able to commit the transaction
2
. If the Transaction Manager receives a
negative confirmation of prepare it will roll-back the transaction. When the Transaction Manager receives positive confirmation
of prepare from every Resource Manager it will commit the transaction by instructing each Resource Manager to commit the
transaction.
Last Resource Commit Optimisation
There is an optimisation in the two phase commit protocol termed Last Resource Commit. Last Resource Commit means that the
Transaction Manager will prepare all but one Resource Manager in the transaction, and wait for the responses from the Resource
Managers. When it has positive acknowledgment of the ability to prepare a transaction it will instruct the last Resource Manager
to commit the transaction. The outcome of the commit (either the commit was successful or failed) is used as a vote for prepare,
if the last Resource Manager committed the Transaction Manager will instruct the other Resource Managers to commit, if the
last Resource Manager did not commit the transaction the Transaction Manager will instruct the other Resource Managers to
roll-back.
The reason why this optimisation is mentioned is because a Resource Manager that does not support the two-phase commit
protocol can be used as the last resource, and provided that there is at most one Resource Manager that supports only one-phase
commit the system as a whole will provide reasonable semantics.
The developer should be aware of the following case when using the Last Resource Commit optimisation: the last Resource
which will be instructed to perform a one-phase commit fails before returning the success or failure of the commit to the
Transaction Manager.
In this case the Transaction Manager is unable to ascertain the state of the Resource Manager
3
. This means that the last
Resource may or may not have committed the transaction, but the Transaction Manager may or may not commit or roll-back
the two-phase resources.
2
Resource Managers support the roll-back a transaction at any point prior to committing the transaction.
3
For example the Resource Manager becomes unreachable due to network failure or Resource Manager failure
Open Cloud Rhino 1.4.3 Administration Manual v1.1 187
Commentaires sur ces manuels