When the application is ready to commit or back out its changes,
the application invokes RRS to begin the two-phase commit protocol.
The two-phase commit protocol is a set of actions used to make
sure that an application program makes all changes to the collection
of resources represented by a UR or makes no changes to the collection.
The protocol verifies the all-or-nothing changes even if the
application program, the system, RRS, or a resource manager fails.
The phases of the protocol are:
- Phase 1: In the first phase, each resource manager prepares
to commit the changes. A resource manager typically prepares by writing
the unchanged data image, often called undo data, and the changed
data image, often called redo data, in a resource manager log
that it can access during restart.
If the resource manager can
then commit the changes, it tells RRS that it agrees to allow the
commit to continue. If the resource manager cannot commit the changes,
it tells RRS to back out the changes.
The decision to commit
or back out the changes represented by a UR depends on responses from
all of the resource managers. If the decision is to commit the changes,
RRS hardens the decision, meaning that it stores the decision in an
RRS log, and phase 2 begins. If the decision is to back out the changes,
RRS generally does not harden the decision, and phase 2 begins as
soon as the decision is made.
Once a commit decision is hardened,
the application changes are considered to be committed. If the application,
the system, RRS, or a resource manager fails after the decision is
hardened, the application changes will be made during restart. Before
the decision is hardened, a failure of the application, the system,
RRS, or a resource manager would cause the changes to be backed out
during restart.
- Phase 2: In the second phase, the resource managers commit
or back out the changes represented by a UR.
Figure 1 shows the valid states that
can occur as RRS processes a UR. Each arrow represents a valid state
change. Figure 1 also shows how valid
state changes correspond to the phases of the two-phase commit protocol.
You can find definitions of each state in UR states.
Figure 1. UR State Transitions
You can see examples of how the two-phase commit protocol works,
including state changes, in Commit and Backout.