The two-phase commit is initiated by the FINISH statement in the application program.
A distinction is made in the two-phase commit between subtransactions with and without an UPDATE flag. Every subtransaction initially has no UPDATE flag, regardless of the open mode (READY) of the database(s). It is only when an updating DML statement is successfully executed for a database that a subtransaction receives the UPDATE flag.
First phase of the two-phase commit
The distribution component in the user task sends
the FINISH statement to all secondary subtransactions without an UPDATE flag.
a PETA (preliminary end of transaction) statement to all secondary subtransactions with an UPDATE flag.
The PETA statement creates a fail-safe log of the following information in the RLOG file of the respective configuration:
all pages that were updated by the respective secondary subtransaction,
the roll-back information, and
the names of all configurations involved (in case a warm start is required).
In the steps that follow, references to “secondary subtransactions” essentially mean “secondary subtransactions with an UPDATE flag”, since the remaining secondary subtransactions have already been terminated.
The secondary subtransactions execute the PETA statement and report to the primary subtransaction whether or not the PETA statement could be executed without errors.
If the primary subtransaction has not received a message from every secondary subtransaction, it checks whether the execution of the PETA statement was successful for all secondary subtransactions.
Step 4a. or 4c. is then performed accordingly.
If the primary subtransaction has not received a message from all secondary subtransactions before a time interval that depends on PP CHCKTIME expires, the primary subtransaction is terminated with FINISH WITH CANCEL, and the secondary subtransactions are also instructed to terminate with FINISH WITH CANCEL.
The application program is assigned status code 122.
Second phase of the two-phase commit
4a.
If all secondary subtransactions have executed the PETA statement successfully, the primary subtransaction is terminated by committing the updates (with FINISH). If the FINISH on the primary subtransactions succeeds, step 4b. is executed.
Otherwise, i.e. if the FINISH on the primary subtransaction could not be completed successfully, the secondary subtransactions are rolled back.
4b.
All secondary subtransactions are instructed to terminate with FINISH.
4c.
If all secondary subtransactions could not successfully execute the PETA statement, the primary subtransaction is terminated by rolling back the updates (FINISH WITH CANCEL), and the secondary subtransactions are also instructed to terminate with FINISH WITH CANCEL.