Commitment Control
Commitment Control
ERserver
iSeries
Commitment control
Version 5 Release 3
ERserver
iSeries
Commitment control
Version 5 Release 3
Note
Before using this information and the product it supports, be sure to read the information in
“Notices,” on page 105.
You can use commitment control to design an application so the system can restart the application if a
job, an activation group within a job, or the system ends abnormally. With commitment control, you can
have assurance that when the application starts again, no partial updates are in the database due to
incomplete transactions from a prior failure.
See the following information to get commitment control up and running on your iSeries(TM) server.
Note: Read the Code example disclaimer for important legal information.
To help you see where technical changes have been made, this information uses:
v The
To find other information about what’s new or changed this release, see the Memo to Users.
If you need Adobe Acrobat Reader to view or print these PDFs, you can download a copy from the
Adobe Web site (www.adobe.com/products/acrobat/readstep.html)
You can also design an application so that commitment control can restart the application if a job, an
activation group within a job, or the system ends abnormally. With commitment control, you can have
assurance that when the application starts again, no partial updates are in the database due to incomplete
transactions from a prior failure.
Transaction
A transaction is a group of individual changes to objects on the system that appears as a single atomic
change to the user.
Commitment control 3
v Simple or complex transactions on the local system that involve objects other than database files.
The following programming languages and APIs support commit and rollback operations:
The following links provide more information about these programming languages and APIs:
v COBOL/400 User’s Guide
Commit operation
A commit operation makes permanent all changes made under commitment control since the previous
commit or rollback operation. The system also releases all locks related to the transaction.
The system performs the following steps when it receives a request to commit:
v The system saves the commit identification, if one is provided, for use at recovery time.
v The system writes records to the file before performing the commit operation if both of the following
are true:
– Records were added to a local or remote database file under commitment control.
The system must perform all of the previous steps correctly for the commit operation to be successful.
Rollback operation
A rollback operation removes all changes made since the previous commit or rollback operation. The
system also releases all locks related to the transaction. The system performs the following steps when it
receives a request to roll back:
v The system clears records from the I/O buffer if both of the following are true:
– If records were added to a local or remote database file under commitment control.
– If SEQONLY(*YES) was specified when the file was opened so that blocked I/O is used by the
system and a partial block of records exists that has not yet been written to the database.
Otherwise, the I/O feedback area and I/O buffers remain unchanged.
v The system makes a call to the commit or rollback exit program for each API commitment resource
that is present in the commitment definition. If a location has more than one exit program registered,
the system calls the exit programs for that location in reverse order from the order in which they were
registered.
v If a record was deleted from a file, the system adds the record back to the file.
v The system removes any changes to records that have been made during this transaction, and places
the original records (the before-images) back into the file.
v If any records were added to the file during this transaction, they remain in the file as deleted records.
v If any record changes were made to resources assigned to a journal during the transaction, the system
adds a journal entry of C RB to the journal indicating that a rollback operation occurred. The journal
also contains images of the record changes that were rolled back. Before the rollback operation was
requested, the before-images and after-images of changed records were placed in the journal. The
system also writes C RB entry to the default journal if any committable resources are assigned to that
journal.
v The system positions the open files under commitment control at one of the following positions:
– The last record accessed in the previous transaction
– At the open position if no commit operation has been performed for the file using this commitment
definition
This consideration is important if you are doing sequential processing.
v The system does not roll back noncommittable changes for database files. For example, opened files are
not closed, and cleared files are not restored. The system does not reopen or reposition any files that
were closed during this transaction.
v The system unlocks record locks that were acquired for commitment control purposes and makes those
records available to other users.
Commitment control 5
v The commit identification currently saved by the system remains the same as the commit identification
provided with the last commit operation for the same commitment definition.
v The system reverses or rolls back object-level committable changes made during this transaction.
v Object locks that were acquired for commitment control purposes are unlocked and those objects are
made available to other users.
v The system establishes the previous commitment boundary as the current commitment boundary.
v The system changes information in the commitment definition to show that the current transaction has
been ended.
The system must perform all of the previous steps correctly for the rollback operation to be successful.
Commitment definition
You create a commitment definition when you use the Start Commitment Control (STRCMTCTL)
command to start commitment control on your system. Also, DB2(R) UDB for iSeries(TM) automatically
creates a commitment definition when the isolation level is other than No Commit. The commitment
definition contains information that pertains to the resources that are being changed under commitment
control within that job. The system maintains the commitment control information in the commitment
definition as the commitment resources change, until the commitment definition is ended. Each active
transaction on the system is represented by a commitment definition. A subsequent transaction can reuse
a commitment definition after each commit or rollback of an active transaction.
For commitment definitions with job-scoped locks, only the job that starts commitment control knows
that commitment definition. No other job knows that commitment definition.
Programs can start and use multiple commitment definitions. Each commitment definition for a job
identifies a separate transaction that has committable resources associated with it. These transactions can
be committed or rolled back independently from transactions that are associated with other commitment
definitions that are started for the job.
For rules about commitment definitions and independent disk pools see “Commitment control and
independent disk pools” on page 21.
Commitment definitions with job-scoped locks can be used only by programs that run in the job that
started the commitment definitions. In comparison, more than one job can use commitment definitions
with transaction-scoped locks.
The most common scope is to the activation group. The activation-group-level commitment definition is
the default scope when the STRCMTCTL command explicitly starts the commitment definition, or an SQL
application that runs with an isolation level other than No Commit implicitly starts the commitment
definition. Only programs that run within that activation group use that commitment definition. Many
activation-group-level commitment definitions can be active for a job at one time. However, each
activation-group-level commitment definition can be associated only with a single activation group. The
programs that run within that activation group can associate their committable changes only with that
activation-group-level commitment definition.
When iSeries(TM) Navigator, the Work with Commitment Definitions (WRKCMTDFN) command, the
Display Job (DSPJOB) command, or the Work with Job (WRKJOB) command display an
activation-group-level commitment definition, these fields display the following:
v The commitment definition field displays the name of the activation group. It shows the special value
*DFTACTGRP to indicate the default activation group.
v The activation group field displays the activation group number.
v The job field displays the job that started the commitment definition.
v The thread field displays *NONE.
A commitment definition can be scoped to the job only by issuing STRCMTCTL CMTSCOPE(*JOB). Any
program running in an activation group that does not have an activation-group-level commitment
definition started uses the job-level commitment definition, if it has already been started by another
program for the job. You can only start a single job-level commitment definition for a job.
When iSeries Navigator, the Work with Commitment Definitions (WRKCMTDFN) command, the Display
Job (DSPJOB) command, or the Work with Job (WRKJOB) command display a job-level commitment
definition, these fields display the following:
v The commitment definition field displays the special value *JOB.
v The activation group field displays a blank.
v The job field displays the job that started the commitment definition.
v The thread field displays *NONE.
For a given activation group, the programs that run within that activation group can use only a single
commitment definition. Therefore programs that run within an activation group can either use the
job-level or the activation-group-level commitment definition, but not both at the same time. In a
multi-threaded job that does not use SQL server mode, transactional work for a program will be scoped
to the appropriate commitment definition with respect to the activation group of the program, regardless
Commitment control 7
of which thread performs it. If multiple threads use the same activation group, they must cooperate to
perform the transactional work and ensure that commits and rollbacks occur at the correct time.
Even when the job-level commitment definition is active for the job, a program can still start the
activation-group-level commitment definition if no program running within that activation group has
performed any commitment control requests or operations for the job-level commitment definition.
Otherwise, you must first end the job-level commitment definition before you can start the
activation-group-level commitment definition. Commitment control requests or operations for the
job-level commitment definition that can prevent the activation-group-level commitment definition from
being started include:
v Opening (full or shared) a database file under commitment control.
v Using the Add Commitment Resource (QTNADDCR) API to add an API commitment resource.
v Committing a transaction.
v Rolling back a transaction.
v Adding a remote resource under commitment control.
v Using the Change Commitment Options (QTNCHGCO) API to changing commitment options.
v Bringing the commitment definition to a rollback required state using the Rollback Required
(QTNRBRQD) API.
v Sending a user journal entry that includes the current commit cycle identifier by using the Send
Journal Entry (QJOSJRNE) API with the Include Commit Cycle Identifier parameter.
Likewise, if the programs within an activation group are currently using the activation-group-level
commitment definition, the commitment definition must first be ended before programs running within
that same activation group can use the job-level commitment definition.
When opening a database file, the open scope for the opened file can be either to the activation group or
to the job with one restriction: if a program is opening a file under commitment control and the file is
scoped to the job, then the program making the open request must use the job-level commitment
definition.
Explicitly-named commitment definitions are started by the system when it needs to perform its own
commitment control transactions without affecting any transactions used by an application. An example
of a function that starts these types of commitment definitions is the problem log. An application cannot
start explicitly named commitment definitions.
When iSeries Navigator, the Work with Commitment Definitions (WRKCMTDFN) command, the Display
Job (DSPJOB) command, or the Work with Job (WRKJOB) command display an explicitly-named
commitment definition, these fields display the following:
v The commitment definition field displays the name given to it by the system.
v The activation group field displays a blank.
v The job field displays the job that started the commitment definition.
v The thread field displays *NONE.
Transaction-scoped commitment definitions are started with the XA APIs for Transaction Scoped Locks.
These APIs use commitment control protocols that are thread based or SQL connection based, and not
activation group based. In other words, the APIs are used to associate the commitment definition with a
particular thread or SQL connection while the transactional work is performed, and to commit or rollback
When iSeries Navigator, the Work with Commitment Definitions (WRKCMTDFN) command, the Display
Job (DSPJOB) command, or the Work with Job (WRKJOB) command display a transaction-scoped
commitment definition, these fields display the following:
v The commitment definition field displays the special value *TNSOBJ.
v The activation group field displays a blank.
v The job field displays the job that started the commitment definition.
v The thread field displays the thread to which the commitment definition is attached (or *NONE if the
commitment definition is not currently attached to any thread).
Only Integrated Language Environment(R) (ILE) compiled programs can start commitment control for
activation groups other than the default activation group. Therefore, a job can use multiple commitment
definitions only if the job is running one or more ILE compiled programs. For more information about
the Integrated Language Environment(R), see the Programming topic in the information center.
Original Program Model (OPM) programs run in the default activation group, and by default use the
*DFTACTGRP commitment definition. In a mixed OPM and ILE environment, jobs must use the job-level
commitment definition if all committable changes made by all programs are to be committed or rolled
back together.
An opened database file scoped to an activation group can be associated with either an
activation-group-level or job-level commitment definition. An opened database file scoped to the job can
be associated only with the job-level commitment definition. Therefore, any program, OPM or ILE, that
opens a database file under commitment control scoped to the job needs to use the job-level commitment
definition.
Application programs do not use the commitment definition name to identify a particular commitment
definition when making a commitment control request. Commitment definition names are primarily used
in messages to identify a particular commitment definition for a job.
Commitment control 9
For activation-group-level commitment definitions, the system determines which commitment definition
to use based on which activation group the requesting program is running in. This is possible because the
programs that run within an activation group at any point in time can only use a single commitment
definition.
For transactions with transaction-scoped locks, the XA APIs and the transaction related attributes added
to the CLI determine which commitment definition the invoking thread uses.
The following table shows how files are committed or rolled back if the scenario in the previous figure
changes:
The following links have more information about resources under commitment control:
v “Types of committable resources” on page 13
v “Local and remote committable resources” on page 14
v “Access intent of a committable resource” on page 15
Resource type How to place it under How to remove it from What kinds of Restrictions
commitment control commitment control changes are
committable
FILE- local Opening under Closing the file, if no Record level changes No more than
database files commitment control1 changes are pending. 500 000 000 records
can be locked for a
single transaction2.
If changes are pending
when the file is closed,
after performing the next
commit or rollback
operation.
DDL- Running SQL under Performing a commit or Object level changes, Only object-level
object-level commitment control rollback operation after such as: changes made using
changes to the object-level change. v Create SQL SQL are under
local SQL Package commitment control.
tables and SQL
v Create SQL Table
collections.
v Drop SQL Table
DDM- remote Opening under Closing the file, if no Record level changes
distributed commitment control. changes are pending.
data Commitment control
management support for DDM has
(DDM) file more information about If changes are pending
commitment control and when the file is closed,
distributed data after performing the next
management. commit or rollback
operation.
LU 6.2- Starting the Ending the conversation
protected conversation3
conversation
DRDA(R)- Using SQL CONNECT Ending the connection
distributed statement
relational
database
Commitment control 13
Resource type How to place it under How to remove it from What kinds of Restrictions
commitment control commitment control changes are
committable
API- local API Add Commitment Remove Commitment The user program The application must
commitment Resource (QTNADDCR) Resource (QTNRMVCR) determines this. provide an exit
resource API API Journal entries may program to be called
be written by the during commit,
user program using rollback, or
the Send Journal resynchronization
Entry (QJOSJRNE) operations.
API to assist with
tracking these
changes.
TCP-TCP/IP Using SQL CONNECT Ending the SQL
connection statement to an RDB connection, or closing the
defined to use TCP/IP DDM file if no changes
connections, or opening are pending. If the DDM
a DDM file defined with file is closed with changes
a TCP/IP location pending, the connection is
closed after performing
the next commit or
rollback operation.
Notes:
1
For details on how to place a database file under commitment control, see the appropriate language reference
manual. “Related information for commitment control” on page 103 links to language manuals that you can
use.
2
You can use a QAQQINI file to reduce the limit of 500 000 000. See “Manage transaction size” on page 67
for instructions.
3
When a DDM connection is started, the DDM file specifies PTCCNV(*YES), and the DDM file is defined with
an SNA remote location, an LU6.2 resource is added with the DDM resource.
When a DRDA connection is started, an LU6.2 resource is added with the DRDA resource if both of the
following are true:
v The program is using the distributed unit of work connection protocols.
v The connection is to an RDB defined with an SNA remote location. For more information about starting
protected conversions, see APPC Programming.
A local committable resource resides on the same system as the application. Each journal associated with
resources under commitment control can be thought of as a local location. All the resources that are
registered without a journal (optionally for both DDL resources and API resources) can be thought of as a
separate local location.
If a committable resource resides on an independent disk pool, the resource is not considered local if the
commitment definition resides on a different disk pool. See “Commitment control and independent disk
pools” on page 21 for more information about committable resources and independent disk pools.
A remote committable resource resides on a different system from the application. A remote location
exists for each unique conversation to a remote system. A commitment definition may have one or more
remote locations on one or more remote systems.
14 iSeries: Commitment control
When you place a local resource under commitment control for the system disk pool, or any independent
disk pool, you must use DRDA(R) to access resources under commitment control in any other
independent disk pool.
The following shows the types of committable resources and their locations:
The access intent determines how the resources participate together in a transaction. The following table
shows what access intents are possible for a particular type of resource and how the system determines
the access intent for a resource when it is registered:
Resource type Possible access intents How the access intent is determined
FILE Update, read-only Based on how the file was opened
DDL Update Always update
API Update Always update
DDM Update, read-only Based on how the file was opened
LU62 Undetermined Always undetermined
(R)
DRDA Update, read-only, undetermined For DRDA Level 1, the access intent is
update if no other remote resources are
registered. Otherwise, the access intent is
read-only. For DRDA Level 2, the access
intent is always undetermined.
TCP Undetermined Always undetermined
The access intent of resources that are already registered determines whether a new resource can be
registered. The following rules apply:
v A one-phase resource whose access intent is update cannot be registered when any of the following is
true:
– Resources whose access intent is update are already registered at other locations.
– Resources whose access intent is undetermined are already registered at other locations.
– Resources whose access intent is undetermined are already registered at the same location and the
resources have been changed during the current transaction.
Commitment control 15
v A two-phase resource whose access intent is update cannot be registered when a one-phase resource
whose access intent is update is already registered.
If a committable resource resides on an independent disk pool, the resource is not considered local a local
resource or a two-phase resource if the commitment definition resides on a different disk pool. See
“Commitment control and independent disk pools” on page 21 for more information about committable
resources and independent disk pools.
A two-phase resource is also called a protected resource. Remote resources and API committable
resources must be registered as one-phase resources or two-phase resources when they are placed under
commitment control. The following table shows what types of committable resources can coexist in a
commitment definition with a one-phase resource:
If only the after images are being journaled for a database file when that file is opened under
commitment control, the system automatically starts journaling both the before and after images. The
before images are written only for changes to the file that occur under commitment control. If other
changes that are not under commitment control occur to the file at the same time, only after-images are
written for those changes.
The system automatically writes record-level committable changes and object-level committable changes
to a journal. For record-level changes, the system then uses the journal entries, if necessary, for recovery
purposes; the system does not use entries from object-level committable changes for recovery purposes.
Furthermore, the system does not automatically write journal entries for API commitment resources.
However, the exit program for the API resource can use the Send Journal Entry (QJOSJRNE) API to write
journal entries to provide an audit trail or to assist with recovery. The content of these entries is
controlled by the user exit program.
The system uses a technique other than a journal to perform recovery for object-level commitment
resources. Recovery for API commitment resources is accomplished by calling the commit and rollback
exit program associated with each particular API commitment resource. The exit program has the
responsibility for performing the actual recovery that is necessary for the situation.
For more information about journaling, see the Journal management topic.
Commitment control entries are written to a local journal if at least one of the following is true:
v The journal is specified as the default journal on the Start Commitment Control (STRCMTCTL)
command.
v At least one file journaled to the journal is opened under commitment control.
v At least one API commitment resource associated with the journal is registered under commitment
control.
Commitment control 17
Entry type Description Where it is written When it is written
C LW End transaction To the default journal, if When the commit or
one is specified on the rollback operation has
STRCMTCTL command. completed.
The system writes an LW
header record and one or
more detail records. These
entries are written only if
OMTJRNE(*NONE) is
specified on the
STRCMTCTL command or
if a system error occurs.
C EC End commitment control To the journal. When the End
Commitment Control
(ENDCMTCTL) command
is completed.
To a local journal that is not When a commit boundary
the default journal. is established, following the
point when all committable
resources associated with
that journal have been
removed from commitment
control.
Start of savepoint or nested To the journal. When the application
commit cycle. creates an SQL
C SB SAVEPOINT, or when the
system creates an internal
nested commit cycle to
handle a series of database
functions as a single
operation2.
The commit cycle identifier is the journal sequence number of the C SC journal entry written for the
commit cycle. The commit cycle identifier is placed in each journal entry written during the commit cycle.
If more than one journal is used during the commit cycle, the commit cycle identifier for each journal is
different.
You can specify that the fixed-length portion of the journal entry includes transaction information by
specifying the Logical Unit of Work (*LUW) value for the Fixed-Length Data (FIXLENDTA) parameter of
the Create Journal (CRTJRN) or Change Journal (CHGJRN) command. By specifying the FIXLENDTA
(*LUW) parameter, the fixed-length portion of each C SC journal entry will contain the Logical Unit of
Work ID (LUWID) of the current transaction. Likewise for XA transactions, if you specify the
FIXLENDTA (*XID) parameter, the fixed-length portion of each C SC journal entry will contain the XID of
the current transaction. The LUWID or XID can help you find all the commit cycles for a particular
transaction if multiple journals or systems are involved in the transaction.
You can use the Send Journal Entry (QJOSJRNE) API to write journal entries for API resources. You have
the option of including the commit cycle identifier on those journal entries.
You can use the commit cycle identifier to apply or remove journaled changes to a commitment boundary
using the Apply Journaled Changes (APYJRNCHG) command or the Remove Journaled Changes
(RMVJRNCHG) command. These limitations apply:
v Most object-level changes made under commitment control are written to the journal but are not
applied or removed using the APYJRNCHG and RMVJRNCHG commands.
v The QJOSJRNE API writes user-created journal entries with a journal code of U. These entries cannot be
applied or removed using the APYJRNCHG and RMVJRNCHG commands. They must be applied or
removed with a user-written program.
Record locking
When a job holds a record lock and another job attempts to retrieve that record for update, the requesting
job waits and is removed from active processing until one of the following occurs:
v The record lock is released.
Commitment control 19
v The specified wait time ends.
More than one job can request a record to be locked by another job. When the record lock is released, the
first job to request the record receives that record. When waiting for a locked record, specify the wait
time in the WAITRCD parameter on the following create, change, or override commands:
v Create Physical File (CRTPF)
v Create Logical File (CRTLF)
v Create Source Physical File (CRTSRCPF)
v Change Physical File (CHGPF)
v Change Logical File (CHGLF)
v Change Source Physical File (CHGSRCPF)
v Override Database File (OVRDBF)
Programs keep record locks over long durations for one of the following reasons:
v The record remains locked while the workstation user is considering a change.
v The record lock is part of a long commitment transaction. Consider making smaller transactions so a
commit operation can be performed more frequently.
v An undesired lock has occurred. For example, assume a file is defined as an update file with unique
keys, and the program updates and adds additional records to the file. If the workstation user wants to
add a record to the file, the program may attempt to access the record to determine whether the key
already exists. If it does, the program informs the workstation user that the request made is not valid.
When the record is retrieved from the file, it is locked until it is implicitly released by another read
operation to the same file, or until it is explicitly released.
The duration of the lock is much longer if LCKLVL(*ALL) is specified because the record that was
retrieved from the file is locked until the next commit or rollback operation. It is not implicitly released
by another read operation and cannot be explicitly released.
Another function that can put a lock on a file is the save-while-active function. The Save your server
while it is active topic has more information about the save-while-active function.
When you start commitment control, the “Commitment definition” on page 6 is created in the
QRECOVERY library. Each independent disk pool or independent disk pool group has its own version of
a QRECOVERY library. On an independent disk pool, the name of the QRECOVERY library is
QRCYxxxxx, where xxxxx is the number of the independent disk pool. For example, the name of the
QRECOVERY library for independent disk pool 39 is QRCY00039. Furthermore, if the independent disk
pool is part of a disk pool group, only the primary disk pool has a QRCYxxxxx library.
When you start commitment control, the commitment definition is created in the QRECOVERY library of
the independent disk pool that is associated with that job, making commitment control active on the
independent disk pool.
Using the Set ASP Group (SETASPGRP) command while commitment control is active on an independent
disk pool has the following effects:
v If you switch from an independent disk pool, and resources are registered with commitment control on
the disk pool, the SETASPGRP command fails with message CPDB8EC, reason code 2, ″The thread has
an uncommitted transaction.″ This message if followed by message CPFB8E9.
v If you switch from an independent disk pool and no resources are registered with commitment control,
the commitment definitions are moved to the independent disk pool to which you are switching.
v If you switch from the system disk pool (ASP group *NONE), commitment control is not affected. The
commitment definitions stay on the system disk pool.
v If you use a notify object, the notify object must reside on the same independent disk pool or
independent disk pool group as the commitment definition.
v If you move the commitment definition to another independent disk pool or independent disk pool
group, the notify object must also reside on that other independent disk pool or independent disk pool
group. The notify object on the other independent disk pool or independent disk pool group is
updated if the commitment definition ends abnormally. If the notify object is not found on the other
independent disk pool or independent disk pool group, the update fails with message CPF8358.
Commitment control 21
pool group. If the journal is not found on the other independent disk pool or independent disk pool
group, the commitment definition is moved, but no default journal is used from this point on.
Since each independent disk pool is a separate SQL database, in the XA environment each independent
disk pool is also considered a separate resource manager. For an application server to perform a
transaction which targets two different independent disk pools, the transaction manager must also use a
two-phase commit protocol.
For more information about independent disk pools, see the Independent disk pools topic.
Save consideration
A save operation is prevented if the job performing the save has one or more active commitment
definitions with any of the following types of committable changes:
v A record change to a file that resides in the library being saved. For logical files, all the related physical
files are checked.
v Any object-level changes within a library that is being saved.
v Any API resource that was added using the Add Commitment Resource (QTNADDCR) API and with
the Allow normal save processing field set to the default value of N.
This prevents the save operations from saving to the save media changes that are due to a partial
transaction.
Note: If you use the new save with partial transactions feature the object can be saved without ending a
commitment definition.
Commitment control 23
Object locks and record locks prevent pending changes from commitment definitions in other jobs from
being saved to the save media. This is true only for API commitment resources if locks are acquired when
changes are made to the object or objects associated with the API commitment resource.
The input file is an update file with a code in the records to indicate that a record was processed. This
file and any files updated are placed under commitment control. When the code is present in the input
file, it represents a completed transaction. The program reads through the input file and bypasses any
records with the completed code. This allows the same program logic to be used for normal and starting
again conditions.
If the batch application contains input records dependent on one another and contains switches or totals,
a “Commit notify object” on page 47 can be used to provide information about starting again. The values
held in the notify object are used to start processing again from the last committed transaction within the
input file.
If input records are dependent on one another, they can be processed as a transaction. A batch job can
lock a maximum of 500 000 000 records. You can reduce this limit by using a Query Options File
(QAQQINI). Use the QRYOPTLIB parameter of the Change Query Attributes (CHGQRYA) command to
specify a Query Options File for a job to use. Use the COMMITMENT_CONTROL_LOCK_LEVEL value
in the Query Options File as the lock limit for the job.
Any commit cycle that exceeds 2000 locks will probably slow down system performance noticeably.
Otherwise, the same locking considerations exist as for interactive applications, but the length of time
records are locked in a batch application may be less important than in interactive applications.
Under two-phase commit, the system performs the commit operation in two waves:
v During the prepare wave, a resource manager issues a commit request to its transaction manager. The
transaction manager informs any other resources it manages and the other transaction managers that
the transaction is ready to be committed. All the resource managers must respond that they are ready
to commit. This is called the vote.
v During the committed wave, the transaction manager that initiates the commit request decides what to
do, based on the outcome of the prepare wave. If the prepare wave completes successfully and all
participants vote ready, the transaction manager instructs all the resources it manages and the other
transaction managers to commit the transaction. If the prepare wave does not complete successfully, all
the transaction managers and resource managers are instructed to roll back the transaction.
When remote resources are under commitment control, the initiator sends a commit request to all remote
agents. The request is sent throughout the transaction program network. Each agent responds with the
results of the commit operation.
If errors occur during the prepare wave, the initiator sends a rollback request to all agents. If errors occur
during the committed wave, the system attempts to bring as many locations as possible to committed
status. These attempts may result in a heuristic mixed state. See “States of the transaction for two-phase
commitment control” on page 27 for more information about the possible states.
Any errors are sent back to the initiator where they are signaled to the user. If a default journal was
specified on the Start Commitment Control (STRCMTCTL) command, C LW entries are written. If errors
occur, these entries are written, even if OMTJRNE(*LUWID) was specified. You can use these entries,
along with the error messages and the status information for the commitment definition, to attempt to
synchronize the committable resources manually.
When remote resources are under commitment control, the initiator sends a rollback request to all remote
agents. The request is sent throughout the transaction program network. Each agent responds with the
results of the rollback operation.
FILE
Database manager
Commitment control 25
DDM
Database manager
DDL
Database manager
DRDA(R)
Communications transaction program
LU62
Communications transaction program
API
API exit program
The following figures shows the basic roles in a transaction. The structure shown in the figures is called a
transaction program network. The structure can be in a single-level tree and a multi-level tree.
When an application on System A issues a commit request, the resource manager on System A becomes
the initiator. For DRDA distributed unit of work over TCP/IP, the initiator is called the coordinator.
The resource managers for the other three systems (B, C, and D) become agents for this transaction. For
DRDA distributed unit of work over TCP/IP, agents are sometimes called participants.
If the application is using APPC communications to perform the two-phase commit, the relationship
between systems can change from one transaction to the next. The following figure shows the same
systems when an application on System B issues the commit request. This configuration is a multi-level
tree.
The roles in this figure do not apply to DRDA distributed unit of work over TCP/IP because multi-level
transactions trees are not supported.
The transaction program network has another level because System B is not communicating directly with
System C and System D. The resource manager in System A now has the roles of agent and cascaded
initiator.
To improve performance of LU6.2 two-phase transactions, the initiator may assign the role of last agent
to one of the agents. The last agent does not participate in the prepare wave. In the committed wave, the
last agent commits first. If the last agent does not commit successfully, the initiator instructs the other
agents to roll back.
For DRDA distributed unit of work over TCP/IP, the coordinator might assign the role of resync server
to a participant. The resync server is responsible is to resynchronize the other participants in the event
that there is a communications failure with the coordinator, or the coordinator has a systems failure.
Commitment control 27
previous transaction. The system uses the state to decide whether to commit or roll back if a transaction
is interrupted by a communications or system failure. If multiple locations are participating in a
transaction, the states of the transactions at each location may be compared to determine the correct
action (commit or rollback). This process of communicating between locations to determine the correct
action is called resynchronization.
Not needed
Each location can make the correct decision independently.
May be necessary
Each location can make the correct decision, but the initiator may need to be informed of the
decision.
Required
The state of each location must be determined before the correct decision can be made.
v Action taken by a communications or system failure.
Commitment control 29
State name Description Resynchronization if the Action taken by a
transaction is interrupted communications or system
failure
Heuristic Mixed (HRM) Some resource managers May be necessary The operator must perform
have committed. Some a restore operation at all
have rolled back. Operator participating locations to
intervention was used or a bring the database to a
system error occurred. consistent state.
Heuristic mixed does not
appear as a status on the
commitment definition
displays. Notification
messages are sent to the
operator.
The following links describe the commitment options, and reasons to use them:
v “Commitment definition for two-phase commit: Allow vote read-only”
v “Commitment definition for two-phase commit: Not wait for outcome” on page 32
v “Commitment definition for two-phase commit: Indicate OK to leave out” on page 35
v “Commitment definition for two-phase commit: Not select a last agent” on page 38
v “Vote reliable affect on flow of commit processing” on page 38
If you are using a DRDA(R) distributed unit of work over TCP/IP connection, the only option that applies
is Allow vote read-only.
Commitment definition for two-phase commit: Allow vote read-only: Normally, a transaction manager
participates in both phases of commit processing. To improve the performance of commit processing, you
can set up some or all locations in a transaction to allow the transaction manager to vote read-only. If the
location has no committable changes during a transaction, the transaction manager votes read-only
during the prepare wave. The location does not participate in the committed wave. This improves overall
performance because the communication flows that normally occur during the committed wave are
eliminated during transactions in which no updates are made at one or more remote locations.
After you start commitment control, you can use the Change Commitment Options (QTNCHGCO) API to
change the Vote read-only permitted option to Y. You may want to do this if the following is true:
v One or more remote systems often do not have any committable changes for a transaction.
v A transaction does not depend on where the file cursor (next record) was set by the previous
transaction. When a location votes read-only, the application is never notified if the transaction is rolled
back. The location has committed any read operations to the database files and, thus, moved the cursor
position. The position of the file cursor is typically important only if you do sequential processing.
If your commitment definition is set up to allow vote read-only, the application waits for the next
message flow from another location.
The Vote read-only permitted option is intended for applications that are client/server in nature. If the
purpose of program A is only to satisfy requests from program I, not to do any independent work, it is
appropriate to allow the Vote read-only option for program A.
Flow of commit processing without last agent optimization when agent votes read-only
Following is a description of the events for normal processing without last agent optimization when the
agent votes read-only. This describes a basic flow. The sequence of events can become much more
complex when the transaction program network has multiple levels or when errors occur.
1. Application program A does a receive request to indicate that it is ready to receive a request from
program I.
2. The initiator application (I) issues a commit instruction.
3. The transaction manager for the initiator (TM-I) takes the role of initiator for this transaction. It starts
the prepare wave by sending a prepare message to all the other locations that are participating in the
transaction.
4. The transaction managers for every other location take the role of agent (TM-A). The application
program A is notified by TM-A that a request to commit has been received. For ICF files, the
notification is in the form of the Receive Take Commit (RCVTKCMT) ICF indicator being set on.
5. The application program A responds by issuing a commit instruction (or a rollback instruction). This
is the application program’s vote.
6. If application program A has used the Change Commitment Options API (QTNCHGCO) to set the
Vote read-only permitted commitment option to Y, and no changes have been made at the agent
during the transaction, the agent (TM-A) responds to the initiator (TM-I) with a reset message. There
will be no committed wave for the agent.
7. A return is sent to the application program (A) to indicate that the transaction is complete at agent
TM-A.
Commitment control 31
8. The next time the initiator (TM-I) issues any message to the agent (TM-A), either a data flow or a
commitment instruction, TM-I causes its current transaction ID to be sent with the message. The
reason for this is that a new transaction ID may have been generated at TM-I if a communications
failure had occurred between TM-I and another system during the commit operation.
9. A return is sent to the application program (A) to indicate that the transaction is complete at agent
TM-A. The return is delayed until after the next message is received because a new transaction ID
must be received from TM-I before the next transaction can be started by application A.
For more information about two-phase commitment control see “Roles in commit processing” on page 25
and “States of the transaction for two-phase commitment control” on page 27.
Commitment definition for two-phase commit: Not wait for outcome: When a communications or
systems failure occurs during a commit operation such that resynchronization is required, the default is
to wait until the resynchronization is finished before the commit operation completes.
Note: The Not wait for outcome option does not apply if you
are using a DRDA(R) distributed unit of work over
TCP/IP connection. DRDA distributed unit of work over
TCP/IP connections never wait for outcome.
After you start commitment control, you can use the QTNCHGCO (Change Commitment Options) API to
specify that the commitment definition does not wait for the outcome of resynchronization. If you specify
N (No) for the Wait for outcome option, the system uses a database server job (QDBSRVnn) to handle
resynchronization asynchronously.
Note: These database server jobs are started during the IPL
process. If you change the options for commitment
control, this has no effect on the number of jobs that the
system starts.
This topic only refers to two values for the resolved Wait for outcome option, Y (Yes) and N (No). There
are actually two more values that you can specify, L (Yes or Inherit from Initiator) and U (No or Inherit
from Initiator). When you use these values, the actual value used during each commit operation is
resolved to Yes or No by the system. The QTNCHGCO (Change Commitment Options) API topic has
more details about these values.
The wait for outcome (WFO) option does not affect normal, error-free commit processing. If an error
occurs, the WFO option determines whether the application waits for resynchronization or not, with the
following conditions:
v If the resolved WFO option is Y (Yes), the application waits for the result of the resynchronization.
v If the resolved WFO option is N (No) and a communication failure occurs during the prepare wave or
rollback of a location that supports presumed abort protocols, no resynchronization is performed and
the commitment definition is rolled back.
In the following figure, the commitment definition for the initiator (I) uses the default value of Y (Yes) for
the Wait for outcome option. When communications between TM-I and TM-A is lost, both application A
and application I wait until the transaction is resynchronized.
In the following figure, the commitment definition for the initiator has the resolved WFO set to N (No).
TM-A meets condition 3 in the preceding list, while TM-I meets condition 4. Control is returned to
Commitment control 33
application I after one attempt to resynchronize with TM-A. A database server job attempts to
resynchronize. Application I never receives the return indicator when the commit request has completed
successfully. Control is not returned to the agent application (A) until after communications is
reestablished. This depends on the timing of the failure. In this case, the communications failure occurs
before the commit message is received from the initiator, leaving TM-A in doubt as to whether to commit
or rollback. When the transaction manager is in doubt, it retains control until the resynchronization is
completed, regardless of the resolved WFO value at that system.
If you want the applications at all systems to continue before resynchronization completes, you must
either change the resolved WFO option to N (No) on all systems, or set the initiator to N and the rest of
the systems to U (No or Inherit from Initiator). But remember that the resolved WFO option is ignored
when the transaction manager is in doubt as to whether to commit or rollback, and always waits until
resynchronization completes before returning control.
Commitment definition for two-phase commit: Indicate OK to leave out: Normally, the transaction
manager at every location in the transaction program network participates in every commit or rollback
operation. To improve performance, you can set up some or all locations in a transaction to allow the
transaction manager to indicate OK to leave out.
Commitment control 35
Note: The Indicate OK to leave out option does not apply if
you are using a DRDA(R) distributed unit of work over
TCP/IP connection.
If no communications flows are sent to the location during a transaction, the location is left out when a
commit or rollback operation is performed. This improves overall performance because the
communications flows that normally occur during the commit or rollback are eliminated during
transactions in which no data is sent to one or more remote locations.
After you start commitment control, you can use the Change Commitment Options (QTNCHGO) API to
change the OK to leave out option to Y (Yes). You may want to do this if one or more remote systems
often are not involved in a transaction.
If your commitment definition is set up to indicate OK to leave out, the application waits for the next
message flow from another location.
The OK to leave out option is intended for applications that are client/server in nature. If the only
purpose of program A is to satisfy requests from program I and not do any independent work, then it is
appropriate to allow the OK to leave out option for program A.
Flow of commit processing without last agent optimization when agent votes OK to leave out
The following figure shows the flow of messages among the application programs and the transaction
managers when an application program issues a commit instruction without last agent optimization when
the agent indicates OK to leave out. Both the initiator application program and the agent application
programs are unaware of the two-phase commit processing. The numbers in parentheses () in the figure
correspond to the numbered items in the description that follows.
Commitment control 37
Note: Any change to the OK to leave out commitment option
does not take effect until the next successful commit
operation.
7. When the initiator (TM-I) receives all the votes, the TM-I sends a commit message. This starts the
committed wave.
8. Each agent (TM-A) commits and responds with a reset message.
9. A return is sent to the application program (I) to indicate that the transaction is complete at the
initiator.
10. Any number of transactions may occur on TM-I, none of which require changes to TM-A or data
from TM-A. TM-A is not included in these transactions.
11. The next time the initiator (TM-I) issues a message to the agent (A), a new transaction ID is sent
with the message. If the initiator performs any commit or rollback operations before sending a
message to the agent, no messages are sent to the agent during those operations (the agent is ’left
out’ of those commits or rollbacks). Because one or more transactions may have been committed or
rolled back at the initiator while the agent was left out, the initiator must communicate its current
transaction ID when the next message is sent to the agent.
12. A return is sent to the application program (A) to indicate that the original commit is complete and
that it is participating in the current transaction.
Commitment definition for two-phase commit: Not select a last agent: By default, the transaction
manager for the initiator is free to select any agent as a last agent during a commit operation.
Note: The Not select last agent option does not apply if you are
using a DRDA(R) distributed unit of work over TCP/IP
connection.
In case of a multi-level tree, any agent selected as a last agent by its initiator is also free to select a last
agent of its own. Performance is improved when a last agent is selected during the commit operation
because two communications flows are eliminated between an initiator and its last agent (the prepare
phase is eliminated for these systems).
However, when the initiator sends the request commit to its last agent, it must wait until it has received
the last agent’s vote before it can continue. This is regardless of the Wait for outcome value for the
commitment definition. During normal, error-free commit processing, this is not an issue. But, if an error
occurs during this window, the initiator cannot continue until resynchronization completes. If the initiator
application is handling requests from a user at a terminal, this can be a usability consideration.
You must consider whether the improved performance during normal commit operations is more
important than the impact on usability when such an error occurs. Note that if the error occurs before the
request commit is sent to the last agent, the LUW will immediately roll back and the initiator will not
wait. Therefore, the window when an error can cause the initiator to wait is quite small, so such an error
is rare.
If you decide that the usability impact is not worth the improved performance, you can change your
commitment definitions to not select a last agent. After you start commitment control, you can use the
Change Commitment Options (QTNCHGCO) API to change the Last agent permitted option to N.
Vote reliable affect on flow of commit processing: Vote reliable is an optimization that improves
performance by returning earlier to the initiator application after a commit operation and eliminating one
message during a commit operation. There is no explicit vote reliable optimization for DRDA(R)
distributed unit of work over TCP/IP. However, OS/400(R) never requests a reset (forget) confirmation for
TCP/IP connections. Therefore a reset (forget) is always implied for TCP/IP connections.
Vote reliable can be thought of as a promise by an agent to its initiator that no heuristic decisions will be
made at the agent if communications failure occurs while the agent is in doubt. An agent that is using the
vote reliable optimization sends an indicator to the initiator during the prepare wave of the commit. If
the initiator is also using the vote reliable optimization, it then sends an indicator to the agent that no
reset is required in response to the commit message. This eliminates the reset message, and allows the
transaction manager to return to the application at the initiator as soon as the commit message is sent.
Consider using the vote reliable optimization if the following conditions are true:
v It is unlikely that a heuristic decision will be made at an in doubt agent in the event of a systems or
communications failure unless the failure cannot be repaired.
v Your program logic does not need the results of previous transactions to ensure that your database files
remain synchronized.
The vote reliable optimization will be used by OS/400 only if all the following conditions are true:
v The initiator and agent locations support the presumed abort level of commitment control.
v The initiator location accepts the vote reliable indication from the agent. On OS/400 initiators, this
depends on the value of two commitment options:
– The value of the Wait for outcome commitment option must be No (Yes is the default).
– The value of the Accept vote reliable commitment option must be Yes (Yes is the default).
v The agent location votes reliable during the prepare wave. OS/400 agents always vote reliable. This is
because heuristic decisions can be made only through a manual procedure that warns of the possible
negative side effects of making a heuristic decision.
The following figure shows the flow of messages among the application programs and the transaction
managers when the vote reliable optimization is used. Both the initiator application program and the
agent application programs are unaware of the two-phase commit processing. The numbers in
parentheses () in the figure correspond to the numbered items in the description that follows.
Commitment control 39
Following is a description of the events for normal processing without last agent optimization when the
agent votes reliable. This describes a basic flow. The sequence of events can become much more complex
when the transaction program network has multiple levels or when errors occur.
1. Application program A does a receive request to indicate that it is ready to receive a request from
program I.
2. The initiator application (I) issues a commit instruction.
3. The transaction manager for the initiator (TM-I) takes the role of initiator for this transaction. It starts
the prepare wave by sending a prepare message to all the other locations that are participating in the
transaction.
4. The transaction managers for every other location take the role of agent (TM-A). The application
program A is notified by TM-A that a request to commit has been received. For ICF files, the
notification is in the form of the Receive Take Commit (RCVTKCMT) ICF indicator being set on.
5. The application program A responds by issuing a commit instruction (or a rollback instruction). This
is the application program’s vote.
6. The agent (TM-A) responds to the initiator (TM-I) with a request commit message. OS/400 systems
send a vote reliable indicator with the request commit.
7. When the initiator (TM-I) receives all the votes, the TM-I sends a commit message. If the Wait for
outcome commitment option is N (No) and the Accept vote reliable commitment option is Y (Yes), a
no reset indicator is sent with the commit message. This tells the agent that no reset message is
required in response to the commit.
8. The transaction is complete. A return is sent to the application programs (I and A). This return
indicates that the commit operation was successful. If a heuristic damage occurs at system A due to a
Be familiar with the information in these books, particularly the XA Specification, before attempting to
use the XA transaction support provided by DB2 UDB for iSeries. You can find these books at the Open
Group Web site
Commitment control 41
Communication Protocol
The protocols used by CRMs to communicate with each other. This is outside the scope of DB2 UDB
for iSeries and is not discussed here.
The XA Specification is the part of the DTP model that describes a set of interfaces that is used by the TM
and RM components of the DTP model. DB2 UDB for iSeries implements these interfaces as a set of
UNIX(R) style APIs and exit programs. See XA APIs for detailed documentation of these APIs and for
more information about how to use DB2 UDB for iSeries as an RM.
A Global transaction may contain changes both outside and within DB2 UDB for iSeries. A global
transaction is coordinated by an external Transaction Manger using the Open Group XA architecture, or
another similar architecture. An application commits or rolls back a global transaction using interfaces
provided by the Transaction Manager. The Transaction Manager uses commit protocols defined by the XA
architecture, or another architecture, to complete the transaction. DB2 UDB for iSeries acts as an XA
Resource Manager when participating in a global transaction. There are two types of global transactions:
v Transaction-scoped locks: Locks acquired on behalf of the transaction are scoped to the transaction.
The transaction can move from one job or thread to another.
v Job-scoped locks: Locks acquired on behalf of the transaction are scoped to the job. The transaction
cannot move from the job that started it.
If you are running XA transactions against a database that resides on the local system, use the XA APIs
for transaction-scoped locks. These APIs have fewer restrictions than the XA APIs for job-scoped locks,
and provide better performance in the following situations:
v If multiple SQL connections are ever used to work on a single XA transaction branch.
v If a single SQL connection is used to work on multiple, concurrent XA transaction branches.
In these situations, a separate job must be started to run XA transaction branches when you use the XA
APIs for Job Scoped Locks.
If you are running against a database that resides on a remote system, you must use the XA APIs for Job
Scoped Locks.
Understand the following considerations and restrictions before using DB2 UDB for iSeries as a RM. The
term ″thread″ refers to either a job that is not thread capable, or a single thread within a thread capable
job.
The following considerations apply to both transactions with transaction-scoped locks and transactions
with job-scoped locks unless noted otherwise.
CLI considerations
v If the CLI is used to perform XA transactions, more than one connection may be made in the same
thread after the db2xa_open() API is used. The connections may be used in other threads to perform
XA transactions, as long as those other threads first use the db2xa_open() API with the same Xainfo
parameter value.
Note: The following consideration applies only to transactions with job-scoped locks.
v If the CLI is used to perform XA transactions, the connection that is used to start a transaction branch
must be used for all work on that transaction branch. If another thread is to join the transaction
branch, the connection handle for the connection used to start the transaction branch must be passed to
the joining thread so that it can perform work over that same connection. Likewise, if a thread is to
resume the transaction branch, the same connection must be used.
Note: The following applies to transactions with transaction-scoped locks and job-scoped locks.
Since CLI connection handles cannot be used in a different job, the join function is limited to threads
running in the same job that started the transaction branch when the CLI is used.
Commitment control 43
Note: These considerations for a remote relational database apply only to transactions with job-scoped
locks.
v XA connections to a remote relational database are supported only if the relational database resides on
a system that supports Distributed Unit of Work (DUW) DRDA(R) connections. This includes systems
running DRDA over SNA LU6.2 conversations. This also includes systems using V5R1 when running
DRDA using TCP/IP connections.
v Before using the XA join function, the db2xa_open() API must be used in the joining thread. The same
relational database name and RMID must be specified on the db2xa_open() API in both the thread that
started the transaction branch and the joining thread. If the transaction branch is active when a join is
attempted, the joining thread is blocked. The joining thread remains blocked until the active thread
suspends or ends its association with the transaction branch.
Recovery consideration
v The manual heuristic commit and rollback support that is provided for all commitment definitions can
be used if it becomes necessary to force a transaction branch to commit or roll back while it is in a
prepared state. See “When to force commits and rollbacks and when to cancel resynchronization” on
page 101 for details.
Note: The following item applies only to transactions with job-scoped locks.
v If an association between a thread and an existing transaction branch is suspended or ended using the
db2xa_end() API, the thread may start a new transaction branch. If the connection used to start the
new transaction branch was used earlier to start a different transaction branch, and the thread’s
association with that transaction branch has been ended or suspended by the db2xa_end() API, a new
SQL server job may be started. A new SQL server job is needed only if the first transaction branch has
not yet been completed by the db2xa_commit() or db2xa_rollback() API. In this case, another
completion message SQL7908 is sent to the job log identifying the new SQL server job, just as the
connection’s original SQL server job was identified when the connection was established. All SQL
requests for the new transaction branch are routed to the new SQL server job. When the transaction
branch is completed by the db2xa_commit() or db2xa_rollback() API, the new SQL server job is
recycled and returned to the prestart job pool.
v A transaction branch will be marked Rollback Only by the system when the following situations occur:
– A thread ends when it is still associated with the transaction branch.
– The db2xa_close() API is used in a thread that has an active association with the transaction branch.
v A transaction branch will be rolled back by the system if any threads are still associated with it when
any of the following situations occur:
– The connection that is related to the transaction branch is ended.
– The job that started the transaction branch is ended.
– The system fails.
v There is one situation where a transaction branch will be rolled back by the system, regardless of
whether there are still associated threads. This occurs when the SQL server job that the connection’s
work is being routed to is ended. This can only happen when the End Job (ENDJOB) CL command is
used against that job.
Note: The following item applies only to transactions with job-scoped locks.
There are cases where it is desirable for transactional work to be scoped to the thread, rather than an
activation group. In other words, each thread would have its own commitment definition and
transactional work for each commitment definition would be independent of work performed in other
threads.
This is supported by DB2(R) UDB for iSeries(TM) by using the Change Job (QWTCHGJB) API to change
the job to run in SQL server mode. When an SQL connection is requested in SQL server mode, it is
routed to a separate job. All subsequent SQL operations that are performed for that connection are also
routed to that job. When the connection is made, completion message SQL7908 is sent to the SQL server
mode job’s job log indicating which job the SQL requests are being routed to. The commitment definition
is owned by the job that is indicated in this message. If errors occur, it may be necessary to look at the
job logs for both jobs to understand the source of the problem because no real work is being done in the
job performing the SQL statements.
When running in SQL server mode, only SQL interfaces may be used to perform work under
commitment control. Embedded SQL or Call Level Interface (CLI) may be used. All connections made
through embedded SQL in a single thread are routed to the same back-end job. This allows a single
commit request to commit the work for all the connections, just as it would in a job that is not running in
SQL server mode. Each connection made through the CLI is routed to a separate job. The CLI requires
work that is performed for each connection to be committed or rolled back independently.
You cannot perform the following operations under commitment control when running in SQL server
mode:
v Record changes that are made with interfaces that are not SQL interfaces
v Changes to DDM files
v Changes to API commitment resources
You cannot start commitment control directly in a job running in SQL server mode. For more information
about SQL server mode, see the following pages in the Database topic:
v Run DB2 CLI in SQL server mode
v Starting DB2 CLI in SQL Server Mode
v Restrictions for running DB2 CLI in server mode
Commitment control 45
Start commitment control
To start commitment control, use the STRCMTCTL (Start Commitment Control) Command.
Note: Commitment control does not need to be started by SQL applications. SQL implicitly starts
commitment control at connect time when the SQL isolation level is not *NONE.
When you use the STRCMTCTL command you can specify these things:
Commit lock-level
Specify the lock-level with the LCKLVL parameter on the STRCMTCTL command. The level you
specify becomes the default level of record locking for database files that are opened and placed
under commitment control for the commitment definition. See “Commit lock level” on page 48 for
more information.
Transaction entries are written to the default journal regardless of the value of the OMTJRNE
parameter under these conditions:
v A system error occurs during a commit or rollback operation.
v A manual change is made to a resource that participated in a transaction, and the change caused
a heuristic mixed condition. See “States of the transaction for two-phase commitment control” on
page 27 for a description of the heuristic mixed condition. This type of manual change is called a
“When to force commits and rollbacks and when to cancel resynchronization” on page 101.
You can use the information about what resources participated in the transaction to determine what
action to take in these situations.
You can use the Journal entry information finder to show the layouts for the entry-specific data for
transaction (commitment control) journal entries.
The commit identification of the last successful transaction for a commitment definition is placed in the
notify object only if the commitment definition does not end normally. This information can be used to
help determine where processing for an application ended so that the application can be started again.
For independent disk pools, the notify object must reside on the same independent disk pool or
independent disk pool group as the commitment definition. If you move the commitment definition to
another independent disk pool or independent disk pool group, the notify object must also reside on that
other independent disk pool or independent disk pool group. The notify object on the other independent
disk pool or independent disk pool group is updated if the commitment definition ends abnormally. If
the notify object is not found on the other independent disk pool or independent disk pool group, the
update fails with message CPF8358.
If journaled resources participate in the current transaction and a commit operation is performed with a
commit identification, the commit identification is placed in the commit journal entry (journal code and
entry type of C CM) that identifies that particular transaction as being committed. A commit journal
entry containing the commit identification is sent to each journal associated with resources that
participated in the transaction.
The following table shows how you specify the commit identification and its maximum size. If the
commit identification exceeds its maximum size, it is truncated when it is written to the notify object.
Commitment control 47
Language Operation Maximum characters in commit identification
ILE C* _Rcommit function 40001
ILE COBOL* COMMIT verb Not supported
SQL COMMIT statement Not supported
Note:
1
If the notify object is a data area, the maximum size is 2000 characters.
When a notify object is updated with the commit identification, it is updated as follows:
Database file
If a database file is used as the notify object, the commit identification is added to the end of the
file. Any existing records will be left in the file. Because several users or jobs can be changing
records at the same time, each commit identification in the file contains unique information to
associate the data with the job and commitment definition that failed. The file that serves can be
journaled
Data area
If a data area is used as the notify object, the entire content of the data area is replaced when the
commit identification is placed in the data area. If more than one user or job is using the same
program, only the commit identification from the last commitment definition that did not end
normally will be in the data area. Consequently, a single data area notify object may not produce the
correct information for starting the application programs again. To solve this problem, use a
separate data area for each commitment definition for each workstation user or job.
Message queue
If a message queue is used as a notify object, message CPI8399 is sent to the message queue. The
commit identification is placed in the second-level text for message CPI8399. As with using a
database file for the notify object, the contents of each commit identification uniquely identify a
particular commitment definition for a job so that an application program can be started again.
See “Example: Use a notify object to start an application” on page 81 for examples of using a notify
object.
The lock level must be specified with respect to your needs, the wait periods allowed, and the release
procedures used most often.
The following descriptions apply only to files that are opened under commitment control:
The *CS lock level ensures that other jobs are not able to read a record for update that this job has
read. In addition, the program cannot read records for update that have been locked with a record
lock type of *UPDATE in another job until that job accesses a different record.
The *ALL lock level ensures that other jobs are not able to access a record for update that this job
has read. This is different from normal locking protocol. When the lock level is specified as *ALL,
even a record that is not read for update cannot be accessed if it is locked with a record lock type of
*UPDATE in another job.
The following table shows the duration of record locks for files under and not under commitment
control.
Commitment control 49
Request LCKLVL parameter Duration of lock Lock type
Read for update then No commitment control From read to release *UPDATE
release1
*CHG From read to release *UPDATE
*CS From read to release, *UPDATE
commit, or rollback
Then from release to next *UPDATE
read, commit, or rollback
*ALL From read to release, *UPDATE
commit, or rollback
Then from release to next
commit or rollback
Add No commitment control No lock None
*CHG From add to commit or *UPDATE
rollback
*CS From add to commit or *UPDATE
rollback
*ALL From add to commit or *UPDATE
rollback
Write direct No commitment control For duration of write direct *UPDATE
*CHG From write direct to *UPDATE
commit or rollback
*CS From write direct to *UPDATE
commit or rollback
*ALL From write direct to *UPDATE
commit or rollback
Note:
1
If a commit or rollback operation is performed after a read-for-update operation, but before the record is updated,
deleted, or released, the record is unlocked during the commit or rollback operation. The protection on the record is
lost as soon as the commit or rollback completes.
2
If a record is deleted but the commit or rollback has not yet been issued for the transaction, the deleted record does
not remain locked. If the same or a different job attempts to read the deleted record by key, the job receives a record
not found indication. However, if a unique keyed access path exists over the file, another job is prevented from
inserting or updating a record with the same unique key value as that of the deleted record until the transaction is
committed.
A record lock type of *READ is obtained on records that are not read for update when the lock level is
*CS or *ALL. This type of lock prevents other jobs from reading the records for update but does not
prevent the records from being accessed from a read-only operation.
A record lock type of *UPDATE is obtained on records that are updated, deleted, added, or read for
update. This type of lock prevents other jobs from reading the records for update, and prevents jobs
running under commitment control with a record lock level of *CS or *ALL from accessing the records for
even a read-only operation.
Programs that are not using commitment control can read records locked by another job, but cannot read
records for update, regardless of the value specified for the LCKLVL parameter.
The lock level specified for a commitment definition when commitment control is started for an
activation group or for the job applies only to opens associated with that particular commitment
definition.
Within the same job, a program can change a record that has already been changed within the current
transaction as long as the record is accessed again using the same commitment definition. When using
the job-level commitment definition, the access to the changed record can be made from a program
running within any activation group that is using the job-level commitment definition.
If the activation-group-level commitment definition is ended, then programs running within that
activation group can no longer make changes under commitment control, unless the job-level
commitment definition is already started for the job. If the job-level commitment definition is active, then
it is immediately made available for use by the programs running within the activation group that just
ended commitment control.
If the job-level commitment definition is ended, then any program running within the job that was using
the job-level commitment definition can no longer make changes under commitment control without first
starting commitment control again with the STRCMTCTL command.
Before issuing the ENDCMTCTL command, the following must be satisfied for the commitment
definition to be ended:
v All files opened under commitment control for the commitment definition to be ended must first be
closed. When ending the job-level commitment definition, this includes all files opened under
commitment control by any program running in any activation group that is using the job-level
commitment definition.
v All API commitment resources for the commitment definition to be ended must first be removed using
the QTNRMVCR API. When ending the job-level commitment definition, this includes all API
commitment resources added by any program running in any activation group that is using the
job-level commitment definition.
v A remote database associated with the commitment definition to be ended must be disconnected.
v All protected conversations associated with the commitment definition must be ended normally using
the correct synchronization level.
If commitment control is being ended in an interactive job and one or more committable resources
associated with the commitment definition have pending changes, inquiry message CPA8350 is sent to
the user asking whether to commit the pending changes, roll back the pending changes, or cancel the
ENDCMTCTL request.
If commitment control is being ended in a batch job, and one or more closed files associated with the
commitment definition to be ended still have pending changes, the changes are rolled back and a
message is sent:
Commitment control 51
v CPF8356 if only local resources are registered
v CPF835C if only remote resources are registered
v CPF83E4 if both local and remote resources are registered
If a notify object is defined for the commitment definition being ended it may be updated.
When an activation group that has an API registered as the last agent is ending, the exit program for the
API is called to receive the commit or rollback decision. In this case, even though the activation group is
ending normally, a rollback request can still be returned from the API exit program. Thus, the implicit
commit operation might not be performed.
After the commitment definition has successfully ended, all the necessary recovery, if any, has been
performed. No additional recovery is performed for the commitment resources associated with the
commitment definition just ended.
After the commitment definition is ended, the job-level or activation-group-level commitment definition
can then be started again for the programs running within the activation group. The job-level
commitment definition may be started only if it is not already started for the job.
Although commitment definitions can be started and ended many times by the programs that run within
an activation group, the amount of system resources required for the repeated start and end operations
can cause a decrease in job performance and overall system performance. Therefore, it is recommended
that a commitment definition be left active if a program to be called later will use it.
For more information for on how the system updates the notify object, see “Updates to the notify object”
on page 60.
The following pages describe the situations in which the system ends commitment control ends implicitly,
and what actions, if any, to take:
v “Commitment control during activation group end”
v “Implicit commit and rollback operations” on page 53
v “Commitment control during normal routing step end” on page 57
v “Commitment control during abnormal system or job end” on page 57
v “Updates to the notify object” on page 60
v “Commitment control recovery during initial program load after abnormal end” on page 58
The system automatically closes any files scoped to the activation group when the activation group ends.
This includes any database files scoped to the activation group opened under commitment control. The
close for any such file occurs before any implicit commit operation that may be performed for the
activation-group-level commitment definition. Therefore, any records that reside in an I/O buffer are first
forced to the database before any implicit commit operation is performed.
As part of the implicit commit or rollback operation that may be performed, a call is made to the API
commit and rollback exit program for each API commitment resource associated with the
activation-group-level commitment definition. The exit program must complete its processing within 5
minutes. After the API commit and rollback exit program is called, the system automatically removes the
API commitment resource.
If an implicit rollback operation is performed for a commitment definition that is being ended due to an
activation group being ended, then the notify object, if one is defined for the commitment definition, may
be updated. See “Updates to the notify object” on page 60 for more information regarding the updating
of a notify object by the system.
The following two tables show what the system does when certain events occur related to a commitment
definition that has pending changes. A commitment definition has pending changes if any of the
following is true:
v Any committable resource has been updated.
v A database file opened under commitment control has been read because reading a file changes the file
position.
v The commitment definition has an API resource. Because changes to API resources are done by a user
program, the system must assume that all API resources have pending changes.
The C CM (commit operation) journal entry and C RB (rollback operation) journal entry indicate whether
the operation was explicit or implicit.
The following table shows the actions the system takes when a job ends, either normally or abnormally,
based on the following:
v The state of the transaction.
v The action-if-end job value for the commitment definition.
v Whether an API resource is the last agent.
Commitment control 53
Commit or rollback
State Last agent API Action if Endjob1 option operation
RST N/A N/A If the commitment
definition is not associated
with an X/Open global
transaction, an implicit
rollback is performed.
If the commitment
definition is associated with
an X/Open global
transaction, the following
occurs:
v If the transaction branch
state is not Active (S1),
no action is performed
and the transaction
branch is left in the same
state.
v If the transaction branch
state is Active (S1), an
implicit rollback is
performed.
PIP N/A N/A If the commitment
definition is not associated
with an X/Open global
transaction, an implicit
rollback is performed.
If the commitment
definition is associated with
an X/Open global
transaction, the transaction
branch is in the Idle (S2)
state, and it is left in the
Idle (S2) state.
PRP N/A WAIT If the commitment
definition is not associated
with an X/Open2 global
transaction, the following
occurs:
v Resynchronization is
started to receive the
decision from the
initiator of the commit
operation.
v The returned decision to
commit or rollback is
performed. It is
considered an explicit
operation.
If the commitment
definition is associated with
an X/Open global
transaction, the following
occurs:
v If the job that started the
transaction ends, the
transaction is left in a
prepared state until the
XA TM either commits it
or rolls it back. The XA
transaction branch state
will be left at Prepared
(S3) in this case.
v If the SQL server job that
the transaction’s work is
being routed to is ended,
a forced rollback is
implicitly performed. The
XA transaction branch
state will be changed to
Heuristically Completed
(S5) in this case.
CIP N/A N/A An explicit commit
operation is performed.
LAP NO WAIT 1. Resynchronization to the
last agent is used to
retrieve the decision to
commit or to roll back.
2. The returned decision to
commit or to roll back is
performed. It is considered
an explicit operation.
LAP YES WAIT 1. The last agent API is
called to retrieve the
commit or rollback
decision.
2. The commit or rollback
operation is performed. It is
considered an explicit
operation.
Commitment control 55
Commit or rollback
State Last agent API Action if Endjob1 option operation
LAP N/A C An implicit commit
operation is performed.
R An implicit rollback
operation is performed.
CMT N/A N/A A commit operation has
already completed for this
commitment definition and
any downstream locations.
The commit operation is
complete.
VRO N/A N/A The local and remote
agents voted to read-only.
All downstream agents
must also have voted to
read-only. No action is
required.
RBR N/A N/A A rollback operation is
required. An explicit
rollback operation is
performed.
Note:
1
You can change the Action if Endjob option with the Change Commitment Options (QTNCHGCO) API.
2
If the commitment definition is associated with an X/Open global transaction, the following occurs:
v If the job that started the transaction ends, the transaction is left in a prepared state until the XA TM either
commits it or rolls it back. The XA transaction branch state will be left at Prepared (S3) in this case.
v For transaction-scoped locks only, if the SQL server job that the transaction’s work is being routed to is ended, a
forced rollback is implicitly performed. The XA transaction branch state will be changed to Heuristically
Completed (S5) in this case.
The following table shows the actions the system takes when an activation group ends and applies only
to transactions with job-scoped locks. The system actions are based on the following:
v The state of the transaction. (It is always reset (RST) when an activation group ends).
v How the activation group ends-normally or abnormally.
v Whether an API resource is the last agent.
Commit or rollback
State Last agent API Type of end operation
RST No Normal An implicit commit
operation is performed. If
protected conversations
exist, the commitment
definition will become the
root initiator of the commit
operation.
Any other end of a routing step is considered abnormal and is recognized by a nonzero completion code
in job completion message CPF1164 in the job log.
Before ending a commitment definition during routing step end, the system performs an implicit rollback
operation if the commitment definition has pending changes. This includes calling the API commit and
rollback exit program for each API commitment resource associated with the commitment definition. The
exit program must complete its processing within 5 minutes. After the API commit and rollback exit
program is called, the system automatically removes the API commitment resource.
If a notify object is defined for the commitment definition, it may be updated. See “Updates to the notify
object” on page 60 for more information about the updating of a notify object by the system.
Attention:
The recovery for commitment definitions refers to an abnormal end for the system or a job due to a
power failure, a hardware failure, or a failure in the operating system or licensed internal code. You
must not use the End Job Abnormal (ENDJOBABN) command to force a job to end abnormally. The
abnormal end can result in pending changes for active transactions for the job you are ending to be
partially committed or rolled back. The next IPL might attempt recovery for any partial transactions
for the job ended with the ENDJOBABN command.
Commitment control 57
The outcome of commitment control recovery that the system performs during an IPL for a job that
you end with the ENDJOBABN command is uncertain. This uncertainty is because all locks for
commitment resources are released when the job is ended abnormally. Any pending changes due to
partial transactions are made available to other jobs. These pending changes can then cause other
application programs to make additional erroneous changes to the database. Likewise, any ensuing
IPL recovery that is performed later can adversely affect the changes made by applications after the
job was ended abnormally. For example, an SQL table may be dropped during IPL recovery as the
rollback action for a pending create table. However, other applications may have already inserted
several rows into the table after the job was ended abnormally.
The system performs the following for commitment definitions being ended during an abnormal job end
or during the next IPL after an abnormal system end:
v Before ending a commitment definition, the system performs an implicit rollback operation if the
commitment definition has pending changes, unless processing for the commitment definition was
interrupted in the middle of a commit operation. If ended in the middle of a commit operation, the
transaction may be rolled back, resynchronized, or committed, depending on its state. See “Implicit
commit and rollback operations” on page 53. The processing to perform the implicit rollback operation
or to complete the commit operation includes calling the API commit and rollback exit program for
each API commitment resource associated with the commitment definition. After the API commit and
rollback exit program is called, the system automatically removes the API commitment resource.
Attention:
Ending the job while a transaction is in doubt (transaction state is LAP or PRP) can cause
inconsistencies in the database (changes might be committed on one or more systems and rolled
back on other systems).
– If the Action if Endjob commitment option is COMMIT, changes on this system are committed if
the job is ended, without regard to whether changes on the other systems participating in the
transaction are committed or rolled back.
– If the Action if Endjob commitment option is ROLLBACK, changes on this system are rolled
back if the job is ended, without regard to whether changes on the other systems participating
in the transaction are committed or rolled back.
– If the Action if Endjob commitment option is WAIT, the job will not end until resynchronization
completes to the system that owns the commit or rollback decision. To make the job end before
resynchronization is complete, a heuristic decision must be made and resynchronization must
be canceled.
Ending the job or system abnormally during a long-running rollback is not recommended. This
will cause another rollback to occur as the job ends (or during the next IPL if the system is
ended). The subsequent rollback will repeat the work performed by the original rollback and take
significantly longer to run.
v If a notify object is defined for the commitment definition, it may be updated. See “Updates to the
notify object” on page 60 for more information about the system updating a notify object.
If a process ends before commitment control is ended and protected conversations are still active, the
commitment definition may be required to commit or roll back. The action is based on the State option
and the Action if end job option for the commitment definition.
The database server jobs are named QDBSRVnn, where nn is a two-digit number. The number of database
server jobs depends on the size of your system. Likewise, the name of the database server job for an
independent disk pool or independent disk pool group is QDBSxxxVnn, where xxx is the independent
disk pol number and nn is a two-digit number. For example, QDBS035V02 can be the name of the
database server job for independent disk pool 35.
“States of the transaction for two-phase commitment control” on page 27 shows the actions that the
system takes, depending on the state of the transaction when the failure occurred. For two states, PRP
and LAP, the system action is in doubt.
The system cannot determine what to do until it performs resynchronization with the other locations that
participated in the transaction. This resynchronization is performed after the IPL or vary on operation
completes.
The system uses the database server jobs to perform this resynchronization. The commitment definitions
that need to be recovered are associated with the database server jobs. During the IPL, the system
acquires all record locks and other object locks that were held by the commitment definition before the
system ended. These locks are necessary to protect the local commitment resources until
resynchronization is complete and the resources can be committed or rolled back.
Messages are sent to the job logs of the database server jobs to indicate the status of resynchronization
with the remote locations. If the transaction is in doubt, resynchronization must be completed with the
location that owns the decision for the transaction before local resources can be committed or rolled back.
When the decision for a transaction is made, the following messages may be sent to the job log for the
database server job.
CPI8351
&1 pending changes being rolled back
CPC8355
Post-IPL recovery of commitment definition &8 for job &19/&18/&17 completed.
CPD835F
IPL recovery of commitment definition &8 for job &19/&18/&17 failed.
Other messages related to the recovery may also be sent. These messages are sent to the history (QHST)
log. If errors occur, messages are also sent to the QSYSOPR message queue.
You can determine the progress of the recovery by using iSeries(TM) Navigator, by displaying the job log
for the database server job, or by using the Work with Commitment Definitions (WRKCMTDFN)
command. Although iSeries Navigator and the Work with Commitment Definitions display allow you to
force the system to commit or roll back, you must use this only as a last resort. If you anticipate that all
Commitment control 59
of the locations that participated in the transaction will eventually be returned to operation, you must
allow the systems to resynchronize themselves. This ensures the integrity of your databases.
The system makes updates to the notify object and are based on the following ways that a commitment
definition can end:
v If a job ends normally and no uncommitted changes exist, the system does not place the commit
identification of the last successful commit operation in the notify object.
v If an implicit commit operation is performed for an activation-group-level commitment definition when
the activation group is ended, the system does not place the commit identification of the last successful
commit operation in the notify object.
v If the system, job, or an activation group ends abnormally before the first successful commit operation
for a commitment definition, the system does not update the notify object because there is no last
commit identification. To differentiate between this condition and a normal program completion, your
program must update the notify object with a specific entry prior to completing the first successful
commit operation for the commitment definition.
v If an abnormal job end or an abnormal system end occurs after at least one successful commit
operation, the system places the commit identification of that commit operation in the notify object. If
the last successful commit operation did not specify a commit identification, then the notify object is
not updated. For an abnormal job end, this notify object processing is performed for each commitment
definition that was active for the job. For an abnormal system end, this notify object processing is
performed for each commitment definition that was active for all jobs on the system.
v The system updates the notify object with the commit identification of the last successful commit
operation for that commitment definition if all of the following occur:
– A non-default activation group ends.
– An implicit rollback operation is performed for the activation-group-level commitment definition.
– At least one successful commit operation has been performed for that commitment definition.
If the last successful commit operation did not specify a commit identification, then the notify object is
not updated. An implicit rollback operation is performed for an activation-group-level commitment
Commitment control 61
5. Expand Global Transactions or Database Transactions.
Online help provides information about all the status displays and the fields on each display.
You can also use iSeries Navigator to display the following information:
v “Display locked objects for a transaction”
v “Display jobs associated with a transaction”
v “Display resource status of a transaction”
v “Display transaction properties” on page 63
For database transactions and global transactions with job-scoped locks, a list of the jobs associated with
the transaction is displayed.
For global transactions with transaction-scoped locks, a list of jobs with this transaction object attached or
waiting for this transaction object to be attached is displayed
Opening a file
If you open a file without specifying the commit open option, no additional system resource is used
even if a commitment definition has been started. For more information about specifying the
commit open option, see the appropriate high-level language reference manual.
Journaling
Journaling a file requires system resources. However, in most cases journaling performs better with
commitment control than without commitment control. If you specify only after-images,
commitment control changes this to both before-images and after-images while commitment control
is in effect. Typically this is a space, not a performance, consideration. See the Journal management
topic for more information about journaling.
Commit operation
If any changes were made to journaled resources during the transaction, each commit of a
transaction adds two entries to each journal related to those resources. The number of entries added
can increase significantly for a large volume of small transactions. You may want to place the
journal receivers in a separate disk pool from the journals.
Rollback operation
Because commitment control must rollback the pending changes recorded in the database,
additional system resources are required whenever a rollback occurs. Also, if record changes are
pending, a rollback operation causes additional entries to be added to the journal.
Commitment control 63
Using more than one journal for commitment control transactions
With two-phase commit, files that are opened under commitment control can be journaled to more
than one journal. However, using more than one journal takes additional system resources to
manage the commitment definition. Using more than one journal can also make recovery more
complicated.
Record locking
Record locking can affect other applications. The number of records locked within a particular job
increases the overall system resources used for the job. Applications needing to access the same
record must wait for the transaction to end.
Requesting SEQONLY(*YES)
If you request the SEQONLY(*YES) option (by using the OVRDBF command or the application
program implicitly attempts to use SEQONLY(*YES)) and the file is opened for input only under
commitment control with LCKLVL(*ALL), the option is changed to SEQONLY(*NO). This option can
affect the performance of input files because records will not be blocked.
Requesting a record-level change for a database file when save-while-active processing is active
A request to make a record-level change under commitment control for a database file may be
delayed if the commitment definition is at a commitment boundary and a save-while-active
operation is running in a different job. This can happen when a file is journaled to the same journal
as some of the objects on the save request.
Because the job is held during the commit or rollback request, and because a commit or rollback
request can be performed only for a single commitment definition at a time, jobs with more than
one commitment definition with API commitment resources added can prevent a save-while-active
operation from completing.
Note: If you use the new save with partial transactions feature the object can be saved without
ending a commitment definition.
Note:
1. If the wait time exceeds 60 seconds, inquiry message CPA8351 is sent to ask the user whether to
continue waiting or cancel the operation.
2. This does not apply to API resources that were added using the QTNADDCR API if the Allow
normal save processing field has a value of Y.
The default is that a last agent is permitted to be selected by the system but the user can modify
this value using the QTNCHGCO API.
Commitment control 65
v “Manage transaction size” on page 67
Minimize locks
A typical way to minimize record locks is to release the record lock. (This technique does not work if
LCKLVL(*ALL) has been specified.) For example, a single file maintenance application typically does the
following:
v Displays a prompt for a record identification to be changed.
v Retrieves the requested record.
v Displays the record.
v Allows the workstation user to make the change.
v Updates the record.
In most cases, the record is locked from the access of the requested record through the update. The record
wait time may be exceeded for another job that is waiting for the record. To avoid locking a record while
the workstation user is considering a change, release the record after it is retrieved from the database
(before the record display appears). You then need to access the record again before updating. If the
record was changed between the time it was released and the time it was accessed again, you must
inform the workstation user. The program can determine if the record was changed by saving one or
more fields of the original record and comparing them to the fields in the same record after it is
retrieved, as follows:
v Use an update count field in the record and add 1 to the field just before an update. The program
saves the original value and compares it to the value in the field when the record is retrieved again. If
a change has occurred, the workstation user is informed and the record appears again. The update
count field is changed only if an update occurs. The record is released while the workstation user is
considering a change. If you use this technique, you must use it in every program that updates the file.
v Save the contents of the entire data record and compare it to the record the next time it is retrieved.
In both cases above, the sequence of operations prevents the simple use of externally described data in
RPG where the same field names are used in the master record and in the display file. Using the same
field names (in RPG) does not work because the workstation user’s changes are overlaid when the record
is retrieved again.
You can solve this problem by moving the record data to a data structure or continue to use externally
described data if you use the DDS keyword RTNDTA. The RTNDTA keyword allows your program to
reread data on the display without the operating system having to move data from the display to the
program. This allows the program to do the following:
1. Prompt for the record identification.
2. Retrieve the requested record from the database.
3. Release the record.
4. Save the field or fields used to determine if the record was changed.
5. Display the record and wait for the workstation user to respond.
If the workstation user changes the record on the display, the program uses the following sequence:
1. Retrieves the record from the database again.
2. Compares the saved fields to determine if the database record has been changed. If it has been
changed, the program releases the record and sends a message when the record appears.
3. Retrieves the record from the display by running a read operation with the RTNDTA keyword and
updates the record in the database record.
4. Proceeds to the next logical prompt because there are no additional records to be released if the
workstation user cancels the request.
For more information about locks see “Detect deadlocks” on page 100.
You can lock a maximum of 500 000 000 records during a transaction for each journal associated with the
transaction. You can reduce this limit by using a Query Options File (QAQQINI). Use the QRYOPTLIB
parameter of the Change Query Attributes (CHGQRYA) command to specify a Query Options File for a
job to use. Use the COMMITMENT_CONTROL_LOCK_LEVEL value in the Query Options File as the
lock limit for the job.
When choosing the lock level for your records, consider the size of your transactions. Use size to
determine how long records are locked before a transaction ends. You must decide if a commit or
rollback operation for commitment control is limited to a single use of the Enter key, or if the transaction
consists of many uses of the Enter key.
Note: The shorter the transaction, the earlier the job waiting to
start save-while-active checkpoint processing can continue
and complete.
For example, for an order entry application, a customer might order several items in a single order
requiring an order detail record and an inventory master record update for every item in the order. If the
transaction is defined as the entire order and each use of the Enter key orders an item, all records
involved in the order are locked for the duration of the entire order. Therefore, often used records (such
as inventory master records) might be locked for long periods of time, preventing other work from
progressing. If all items are entered with a single Enter key using a subfile, the duration of the locks for
the entire order is minimized.
In general, the number and duration of locks must be minimized so several workstation users can access
the same data without long waiting periods. You can do this by not holding locks while the user is
entering data on the display. Some applications may not require more than one workstation user
accessing the same data. For example, in a cash posting application with many open item records per
customer, the typical approach is to lock all the records and delay them until a workstation user
completes posting the cash for a given receipt.
If the workstation user presses the Enter key several times for a transaction, it is possible to perform the
transaction in a number of segments. For example:
v The first segment is an inquiry in which the workstation user requests the information.
v The second segment is a confirmation of the workstation user’s intent to complete the entire
transaction.
v The third segment is retrieval and update of the affected records.
This inquiry-first approach is normally used in applications where a decision results from information
displayed. For example, in an airline reservation application, a customer may want to know what flight
times, connecting flights, and seating arrangements are available before making a decision on which
flight to take. Once the customer makes a decision, the transaction is entered. If the transaction fails (the
Commitment control 67
flight is now full), the rollback function can be used and a different request entered. If the records were
locked from the first inquiry until a decision is made, another reservation clerk would be waiting until
the other transaction is complete.
The examples provide sample code for commitment control. The Practice problem is an RPG program
that implements commitment control. It includes a logic flow that shows what is happening each step of
the way.
The three following examples show example uses of commitment control to start applications after an
abnormal system end.
Scenario
v “Scenario: Commitment control”
Examples
v “Practice problem for commitment control” on page 71
v Logic flow for the practice problem for commitment control
v “Example: Use a transaction logging file to start an application” on page 77
v “Example: Use a notify object to start an application” on page 81
v “Example: Use a standard processing program to start an application” on page 87
Note: Read the Code example disclaimer for important legal information.
See Scenario: Journal management for a description of JKL Toy Company’s network environment. The
scenario that follows shows how commitment control works on their production server, JKLPROD.
This scenario illustrates the advantages of using commitment control in two examples. The first example
shows how the company’s inventory program, Program A, might work without commitment control, and
the possible problems that can occur. The second example shows how the program works with
commitment control.
JKL Toy Company uses an inventory application program, Program A, on their server JKLPROD.
Program A uses two records. One record tracks items that are stored in the stock room. Another record
keeps track of items that are removed from the stock room, and used in production.
Assume that the following application program does not use commitment control. The system locks
records read for updating. The following steps describe how the application program tracks a diode as it
is removed from the stock room and transferred to checking account:
v Program A locks and retrieves the stock room record. (This action might require a wait if the record is
locked by another program.)
Without using commitment control, a problem needs to be solved to make this program work properly in
all circumstances. For example, a problem occurs if program A does not update both records because of a
job or system failure. In this case, the two files are not consistent — diodes are removed from the stock
room record, but they are not added to the production record. Using commitment control allows you to
ensure that all changes involved in the transaction are completed or that the files are returned to their
original state if the processing of the transaction is interrupted.
Because the locks on both records are kept by commitment control until the transaction is committed, a
situation cannot arise in which one record is updated and the other is not. If a routing step or system
failure occurs before the transaction is committed, the system removes (rolls back) the changes that have
been made so that the files are updated to the point where the last transaction was committed.
For each routing step in which files are to be under commitment control, the steps shown in the
following figure occur:
Commitment control 69
The operations that are performed under commitment control are journaled to the journal. The start
commitment control journal entry appears after the first file open entry under commitment control. This
is because the first file open entry determines what journal is used for commitment control. The journal
entry from the first open operation is then used to check subsequent open operations to ensure all files
are using the same journal.
When a job failure or system failure occurs, the resources under commitment control are updated to a
commitment boundary. If a transaction is started but is not completed before a routing step ends, that
transaction is rolled back by the system and does not appear in the file after the routing step ends. If the
system abnormally ends before a transaction is completed, that transaction is rolled back by the system
and does not appear in the file after a subsequent successful initial program load (IPL) of licensed
internal code. Anytime a rollback occurs, reversing entries are placed in the journal.
For example, assume JKL company has 100 diodes in stock. Manufacturing takes out 20 from stock, for a
new balance of 80. The database update causes both before-image (100) and after-image (80) journal
entries.
Assume the system abnormally ended after journaling the entries, but before reaching the commitment
point or rollback point. After the IPL, the system reads the journal entry and updates the corresponding
database record. This update produces two journal entries that reverse the update: the first entry is the
before-image (80) and the second entry is the after-image (100).
Note: Read the Code example disclaimer for important legal information.
Item On hand
AA 450
BB 375
CC 4000
6. End the program using F3. This entry provides some data against which the program will operate.
7. Create the CL program Item Process (ITMPCSC) as follows:
PGM
DCL &USER *CHAR LEN(10)
RTVJOBA USER(&USER)
CALL ITMPCS PARM(&USER)
ENDPGM
This is the control program that calls the ITMPCS program. It retrieves the user name and passes it
to the processing program. This application assumes that unique user names are used.
Commitment control 71
8. Create a display file named ITMPCSD from the DDS as follows.
There are two formats, the first for the basic prompt display and the second to allow the operator to
review the last transaction entered. This display file is used by the ITMPCS program.
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ..
1.00 A R PROMPT
2.00 A CA03(93 ’End of program’)
3.00 A CA04(94 ’Review last’)
4.00 A SETOFF(64 ’No rcd to rvw’)
5.00 A 1 2’INVENTORY TRANSACTIONS’
6.00 A 3 2’Quantity’
7.00 A QTY 5 0I +1
8.00 A 61 ERRMSG(’Invalid +
9.00 A quantity’ 61)
10.00 A +5’ITEM’
11.00 A ITEM 2 I +1
12.00 A 62 ERRMSG(’Invalid +
13.00 A Item number’ 62)
14.00 A 63 ERRMSG(’Rollback +
15.00 A occurred’ 63)
16.00 A 64 24 2’CF4 was pressed and +
17.00 A there are no +
18.00 A transactions for +
19.00 A this user’
20.00 A DSPATR(HI)
21.00 A 23 2’CF4 Review last +
22.00 A transaction’
23.00 A R REVW
24.00 A 1 2’INVENTORY TRANSACTIONS’
25.00 A +5’REVIEW LAST TRANSACTION’
26.00 A 3 2’Quantity’
27.00 A QTY 5 0 +1EDTCDE(Z)
28.00 A +5’Item’
29.00 A ITEM 2 +1
9. Study the logic flow provided in Logic flow for the practice program for commitment control.
10. Enter the STRSEU command and type the source as follows:
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ..
Quantity Item
3 AA
4 BB
14. Press F4. The review display shows the BB item last entered. Enter the following data:
Quantity Item
5 FF (Invalid item number message occurs.)
9000 BB (Insufficient quantity error message occurs.)
100 CC (Rollback message occurs.)
102 CC (RPG DSPLY operation must occur. Press the Enter
key.)
Commitment control 73
Quantity Item
101 CC (The program must display an inquiry message
stating that a divide by zero condition has occurred or
end, depending on the setting of job attribute
INQMSGRPY. If the inquiry message appears, enter C to
cancel the RPG program and then C to cancel the CL
program on the subsequent inquiry. This simulates an
unexpected error condition.)
Quantity Item
5 AA
6 BB
Quantity Item
7 AA
8 BB
26. Use System Request and request the option to display the current job. When the Display Job display
appears, select option 16 to request the display of the commitment control status.
Note the values on the display. There must be two commits because two commit statements were
run in the program.
27. Press F9 to see a list of the files under commitment control and the amount of activity for each file.
28. Return to the program and end it by pressing F3.
29. Type DSPJRN CMTLIB/JRNTEST and note the entries for the files and the special journal entries for
commitment control:
The commitment control before-images and after-images (R UB and R UP types) automatically occur
even though you had originally requested IMAGES(*AFTER) for the journal.
30. Type the command CALL ITMPCSC and the following transactions:
Quantity Item
12 AA
100 CC (This is the condition to simulate the need for an
application use of rollback. The CC record in the ITMP
file, which was updated by RPG statement 40.00 is rolled
back.)
Commitment control 75
Note the additional entries that appear in the journal for the use of the rollback entry (C RB entry).
When the ITMP record is rolled back, three entries are placed in the journal. This is because any
change to the database file under commitment control produces a before (R BR) and after (R UR)
entry.
36. Display the entries with journal code R and these entry types: UB, UP, BR, and UR. Use option 5 to
display the full entries. Because the Quantity field is in packed decimal, use F11 to request a hex
display. Note the following:
v The on-hand value of the ITMP record in the UB record
v How the on-hand value is reduced by the UP record
v How the BR record is the same as the UP record
v How the UR record returns the value as originally displayed for the UB record
The last entry is the RB entry for the end of the rollback.
37. Type the command CALL ITMPCSC, press Enter, and press F4. Note the last transaction entered.
38. Type the following transactions:
Quantity Item
13 AA
101 CC (This is the condition to simulate an unexpected error
condition, which causes the program to end. The
simulation occurs by dividing a field by 0. The program
will display an inquiry message or end, depending on the
setting of the job attribute INQMSGRPY. If the inquiry
message appears, enter C to end the program. Because
the CL program was changed to monitor for RPG
program errors, the second inquiry which occurred does
not occur.)
Quantity Item
14 AA
102 CC (The RPG DSPLY operation must occur to the external
message queue. Use the System Request key and select
option 1 on the system request menu to transfer to a
secondary job.)
Note: Read the Code example disclaimer for important legal information.
A transaction logging file is used to start an application again after a system or job failure when a notify
object is not used. A transaction logging file is often used in interactive applications to summarize the
effects of a transaction.
For example, in an order entry application, a record is typically written to a transaction logging file for
each item ordered. The record contains the item ordered, the quantity, and the price. In an accounts
payable application, a record is written to a transaction logging file for each account number that is to
receive a charge. This record normally contains such information as the account number, the amount
charged, and the vendor.
In many of the applications where a transaction logging file already exists, a workstation user can request
information about the last transaction entered. By adding commitment control to the applications in
which a transaction logging file already exists, you can:
v Ensure that the database files are updated to a commitment boundary.
v Simplify the starting of the transaction again.
You must be able to uniquely identify the workstation user if you use a transaction logging file for
starting applications again under commit control. If unique user profile names are used on the system,
that profile name can be placed in a field in the transaction logging record. This field can be used as the
key to the file.
The following examples assume that an order inventory file is being used to perform transactions and
that a transaction logging file already exists. The program does the following:
1. Prompts the workstation user for a quantity and item number.
2. Updates the quantity in the production master file (PRDMSTP).
3. Writes a record to the transaction logging file (ISSLOGL).
If the inventory quantity on hand is insufficient, the program rejects the transaction. The workstation user
can ask the program where the data entry was interrupted, because the item number, description,
quantity, user name, and date are written to the transaction logging file.
Commitment control 77
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7
1.00 A LIFO
2.00 A R ISSLOGR PFILE(ISSLOGP)
3.00 A K USER
1.00 A REF(ISSLOGP)
2.00 A R PROMPT
3.00 A CA03(98 ’End of program’)
4.00 A CA02(97 ’Where am I’)
5.00 A 1 20’ISSUES PROCESSING’
6.00 A 3 2’Quantity’
7.00 A QTY R I +1
8.00 A 62 ERRMSG(’Not enough +
9.00 A Qty’ 62)
10.00 A +6’Product’
11.00 A PRODCT R I +1
12.00 A 61 ERRMSG(’No Product +
13.00 A record found’ 62)
14.00 A 55 15 2’No Previous record exists’
15.00 A 24 2’CF2 Last transaction’
16.00 A R RESTART
17.00 A 1 20’LAST TRANSACTION +
18.00 A INFORMATION’
19.00 A 5 2’Product’
20.00 A PRODCT R +1
21.00 A 7 2’Description’
22.00 A DESCRP R +1
23.00 A 9 2’Qty’
24.00 A QTY R +1REFFLD(QTY)
Program flow
The RPG COMMIT operation code is specified after the PRDMSTP file is updated and the record is
written to the transaction logging file. Since each prompt to the operator represents a boundary for a new
transaction, the transaction is considered a single Enter transaction.
The user name is passed to the program when it is called. The access path for the transaction logging file
is defined in last-in-first-out (LIFO) sequence so the program can easily access the last record entered.
The workstation user can start the program again after a system or job failure by using the same function
that identified where data entry was stopped. No additional code needs to be added to the program. If
Commitment control 79
you are currently using a transaction logging file but are not using it to find out where you are, add the
user name to the transaction logging file (assuming user names are unique) and use this approach in the
program.
The following shows the RPG program used. Statements required for commitment control are marked
with arrows (==>).
RPG Program
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... .. 7 ..
=>1.00 FPRDMSTP UP E K DISK KCOMIT
=>2.00 FISSLOGL IF E K DISK KCOMIT
3.00 PRDISSD CP E WORKSTN
4.00 *ENTRY PLIST
5.00 PARM USER 10
6.00 C*
7.00 C* Initialize fields used in Trans Log Rcd
8.00 C*
9.00 C MOVE UDATE DATE
10.00 C*
11.00 C* Basic processing loop
12.00 C*
13.00 C LOOP TAG
14.00 C EXFMTPROMPT
15.00 C 98 GOTO END End of pgm
16.00 C 97 DO Where am I
17.00 C EXSR WHERE
18.00 C GOTO LOOP
19.00 C END
20.00 C PRODCT CHAINPRDMSTR 61 Not found
21.00 C 61 GOTO LOOP
22.00 C ONHAND SUB QTY TEST 50 62 Less than
23.00 C 62 DO Not enough
24.00 C EXCPTRLSMST Release lock
25.00 C GOTO LOOP
26.00 C END
27.00 C*
28.00 C* Update master record and output the Transaction Log Record
29.00 C*
30.00 C Z-ADDTEST ONHAND
31.00 C UPDATPRDMSTR
32.00 C WRITEISSLOGR
=>33.00 C COMIT
34.00 C GOTO LOOP
35.00 C*
36.00 C* End of program processing
37.00 C*
38.00 C END TAG
39.00 C SETON LR
40.00 C*
41.00 C* WHERE subroutine for "Where am I" requests
42.00 C*
43.00 C WHERE BEGSR
44.00 C USER CHAINISSLOGL 55 Not found
45.00 C N55 EXFMTRESTART
46.00 C ENDSR
47.00 OPRDMSTR E RLSMST
1.00 PGM
2.00 DCL &USER *CHAR LEN(10)
3.00 STRCMTCTL LCKLVL(*CHG)
4.00 RTVJOBA USER(&USER)
To use commitment control in this program, a lock level of *CHG would normally be specified. The
record is locked by the change until a commit operation is run. Note that if there is an insufficient
quantity of inventory, the record is explicitly released. (If the record were not explicitly released in the
program, it would be released when the next record is read for update from the file.)
In this example, there is no additional advantage to using the lock level *ALL. If *ALL were used, a
rollback or commit operation must be used to release the record when an insufficient quantity existed.
The previous code is a CL program that calls the RPG program PRDISS. Note the use of
STRCMTCTL/ENDCMTCTL commands. The unique user name is retrieved (RTVJOBA command) and
passed to the program. The use of the MONMSG command to cause a rollback is described in “Example:
Use a standard processing program to start an application” on page 87.
There are several techniques for starting your applications again depending on your application needs. In
choosing the technique, consider the following:
v When there are multiple users of a program at the same time, a single data area cannot be used as the
notify object because after an abnormal system end, the commit identification for each user would
overlay each other in the data area.
v Your design for deleting information in the notify object must handle the situation when a failure
occurs immediately following use of the information:
– If information is deleted immediately, it would not exist if another failure occurs before processing
the interrupted transaction.
– The information in the notify object must not be deleted until the successful processing of the
interrupted transaction. In this case, more than one entry will exist in the notify object if it is a
database file or message queue.
– The program must access the last record if there is more than one entry.
Commitment control 81
v A notify object cannot be used to provide the work station user with the last transaction committed
because the notify object is updated only if a system or job failure occurs or if uncommitted changes
exist at the normal end of a job.
v If information is displayed to the workstation user, it must be meaningful. To accomplish this may
require that the program translate codes kept in the notify object into information that will help the
user start again.
v Information for starting again must be displayed if the work station user needs it. Additional logic in
the program is required to prevent information from being displayed again when it is no longer
meaningful.
v A single notify object and a standard processing program can provide a starting again function if the
notify object is a database file. This standard processing program is called by the programs that require
the ability to start again to minimize the changes to each individual program.
For example code for using a notify object, see the following:
Note: Read the Code example disclaimer for important legal information.
v “Example: Unique notify object for each program”
v “Example: Single notify object for all programs” on page 87
Using a single, unique notify object for each job allows use of an externally described commit
identification even though there may be multiple users of the same program. In the following examples, a
database file is used as a notify object and it is used only by this program.
The program has two database files (PRDMSTP and PRDLOCP) that must be updated for receipts to
inventory. The display file used by the program is named PRDRCTD. A database file, PRDRCTP, is used
as the notify object. This notify object is defined to the program as a file and is also used as the definition
of a data structure for the notify function.
See DDS for physical file PRDMSTP (page 77) for to see the DDS for physical file PRDMSTP.
Note: Read the Code example disclaimer for important legal information.
1.00 A REF(PRDMSTP)
2.00 A R PROMPT
3.00 A CA03(98 ’End of program’)
4.00 A SETOFF(71 ’RESTART’)
5.00 A 1 20’PRODUCT RECEIPTS’
6.00 A 3 2’Quantity’
7.00 A QTY 3 OI +1
8.00 A +6’Product’
DDS for notify object and externally described data structure (PRDRCTP)
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ..
1.00 A LIFO
2.00 A REF(PRDMSTP)
3.00 A R PRDRCTR
4.00 A USER 10
5.00 A PRODCT R
6.00 A DESCRP R
7.00 A QTY 3 0
8.00 A LOCATN R REFFLD(LOCATN PRDLOCP)
9.00 A K USER
The processing for this program prompts the user for a product number, a location, and a quantity:
v Two files must be updated:
– Product master file (PRDMSTP)
– Product location file (PRDLOCP)
v A record in each file must exist before either is updated.
Commitment control 83
v The program moves the input fields to corresponding last fields after each transaction is successfully
entered. These last fields are displayed to the operator on each prompt as feedback for what was last
entered.
v If information for starting again exists, it is moved to these last fields and a special message appears on
the display.
This process is outlined in the following figure. The user name is passed to the program to provide a
unique record in the notify object.
Program flow
The following is the RPG source code for this example. The notify object (file PRDRCTP) is used as a
normal file at the beginning and end of the program, and is also specified as the notify object in the CL
(STRCMTCTL command) before calling the program.
RPG source
Commitment control 85
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ..
Because the information required to start again may vary from program to program, do not be use an
externally described data structure for the commit identification. If a single notify object is used, the
preceding program can describe the data structure within the program rather than externally. For
example:
1 10 USER
11 20 PGMNAM
21 23 PRODCT
24 29 LOCATN
30 49 DESC
50 51 0 QTY
52 220 DUMMY
In each program that uses this notify object, the information specified for the commit identification would
be unique to the program (the user and program names are not unique). The notify object must be large
enough to contain the maximum information that any program would place in the commit identification.
“Example: Unique notify object for each program” on page 82 provides more examples about using notify
objects.
For this approach, the physical file NFYOBJP is used as the notify object and defined as:
Unique user profile name 10 characters
Program identification 10 characters
Information for
starting again Character field
(This must be large
enough to contain the maximum
amount of information for starting
programs again that require
information for starting again.
This field is required by
the application programs.
In the example, it is
assumed to be a length of 200.)
The file is created with SHARE(*YES). The first two fields in the file are the key to the file. (This file can
also be defined as a data structure in RPG programs.)
Note: Read the Code example disclaimer for important legal information.
Commitment control 87
This the following provide example code for a standard processing program:
v “Example: Code for a standard processing program”
v “Example: Code for a standard commit processing program” on page 89
v “Example: Use a standard processing program to decide whether to restart the application” on page 92
Note: Read the Code example disclaimer for important legal information.
Commitment control 89
The program is written to verify the parameters that were passed and perform the appropriate action as
follows:
O=Open
The calling program requests the notify object file be kept open on return. Because the notify object
is opened implicitly by the RPG program, the program must not close it. Indicator 98 is set so the
program returns with LR off to keep the program’s work areas and leaves the notify object open so
it can be called again without excess overhead.
C=Close
The calling program has determined it no longer needs the notify object and requests a close.
Indicator 98 is set off to allow a full close of the notify object.
R=Read
The calling program requests that a record with matching key fields be read and passed back. The
program uses the passed key fields to attempt to retrieve a record from NFYOBJP. If duplicate
records exist for the same key, the last record is returned. The return code is set accordingly and, if
the record existed, it is passed back in the data structure CMTID.
W=Write
The calling program requests a record to be written to the notify object to allow the calling program
to start again the next time it is called. The program writes the contents of the passed data as a
record in NFYOBJP.
D=Delete
The calling program requests that records for this matching key be deleted. This function is typically
performed at the successful completion of the calling program to remove any information about
starting again. The program attempts to delete any records for passed key fields. If no records exist,
a different return code is passed back.
S=Search
The calling program requests a search for a record for a particular user regardless of which program
wrote it. This function is used in the program for sign-on to indicate that starting again is required.
The program uses only the user name as the key to see if records exist. The return code is set
appropriately, and the contents of the last record for this key (if it exists) are read and passed back.
Note: Read the Code example disclaimer for important legal information.
Commitment control 91
84.00 C*
85.00 C END TAG
86.00 C N98 SETON LR
87.00 C RETRN
88.00 C* BADEND tag is used then fall thru to RPG cycle error return
89.00 C BADEND TAG
The initial program can call the standard commit processing program to determine if it is necessary to
start again. The workstation user can than decide whether to start again.
The initial program passes a request code of S (search) to the standard program, which searches for any
record for the user. If a record exists, the information for starting again is passed to the initial program
and the information is displayed to the workstation user.
The commit identification in the notify object contains information that the initial program can display
identifying what program needs to be started again. For example, the last 50 characters of the commit
identification can be reserved to contain this information. In the application program, this information
can be in a compile time array and moved to the data structure in an initialization step. “Example: Code
for a standard commit processing program” on page 89 shows how to include this in the application
program.
The following is an example of an initial program that determines if a record exists in the notify object.
Note: Read the Code example disclaimer for important legal information.
1.00 PGM
2.00 DCLF CMTINLD
3.00 DCL &RQSCOD *CHAR LEN(1) VALUE(S) /* Search */
4.00 DCL &RTNCOD *CHAR LEN(1)
5.00 DCL &CMTID *CHAR LEN(220)
6.00 DCL &USER *CHAR LEN(10)
7.00 DCL &INFO *CHAR LEN(50)
8.00 RTVJOBA USER(&USER)
9.00 CHGVAR &CMTID (&USER *CAT XX)
10.00 /* The XX is required to prevent a blank Pgm nam */
11.00 CALL STDCMT PARM(&RQSCOD &RTNCOD &CMTID)
12.00 IF (&RTNCOD *EQ ’1’) DO /* RESTART REQD */
13.00 CHGVAR &INFO %SST(&CMTID 171 50)
14.00 SNDRCVF RCDFMT(RESTART)
15.00 ENDDO
16.00 /* */
17.00 /* Enter normal initial program statements */
18.00 /* or -TFRCTL- to first menu program */
19.00 /* */
20.00 ENDPGM
“When to force commits and rollbacks and when to cancel resynchronization” on page 101
This information describes when and how to force a rollback or commit, and when to cancel
resynchronization
If a communications or system failure occurs during a commit operation, resynchronization may need to
be performed to ensure that the transaction managers keep the data consistent on all the systems
involved in the transaction. The behavior of the resynchronization and how it affects the commit
operation depends on these factors :
v The Wait for outcome commitment option. Refer to “Commitment definition for two-phase commit:
Not wait for outcome” on page 32 for details.
v The state of the transaction. Refer to “States of the transaction for two-phase commitment control” on
page 27 for details.
If the failure is catastrophic such that it can never be repaired, or it cannot be repaired in a timely
manner, the system operators for other systems involved in the transaction must make a heuristic
decision. The heuristic decision commits or rolls back the changes made on that system during the
transaction. If the failure is repaired after such a decision, and the resynchronization detects that the
decision caused data integrity problems, message CPD83D9 or CPD83E9 is sent to the QSYSOPR message
queue.
The following information provides more details about working with commitment control errors:
v “Error conditions”
v “Non error conditions” on page 95
v “Error messages to monitor for during commitment control” on page 95
v “Monitor for errors after a CALL command” on page 98
v “Failure of normal commit or rollback processing” on page 99
Error conditions
If an error occurs, an escape message is sent that you can monitor for in a program. The following are
some typical errors related to commitment control:
v Consecutive STRCMTCTL commands are run without an intervening ENDCMTCTL command.
Commitment control 93
v Files are opened under commitment control, but no STRCMTCTL command was run.
This is not an error condition for programs that run within an activation group that are to use the
job-level commitment definition. The job-level commitment definition can be started only by a single
program, but when started by a program, the job-level commitment definition is used by any program
running in any activation group that is not using an activation-group-level commitment definition.
Programs that run within an activation group that are to use the activation-group-level commitment
definition must first start the activation-group-level commitment definition with the STRCMTCTL
command.
v Files that are opened for output under commitment control are not journaled.
v The first open operation of a shared file places the file under commitment control, but subsequent open
operations of the same shared file do not.
v The first open operation of a shared file does not place the file under commitment control, but
subsequent open operations of the same shared file do.
v The record lock limit for the job is reached in a single transaction.
v The program issues a read operation, a commit operation, and a change to the same record. The read
operation must be issued again after the commit operation because the commit operation has freed the
lock on the record.
v For a one-phase location, resources placed under commitment control do not reside at the same
location as resources already under commitment control for the commitment definition.
v Uncommitted changes exist when an ENDCMTCTL command is issued.
This is not an error condition for the ENDCMTCTL command if all files are closed, any remote
database is disconnected, and no API commitment resource is still associated with the commitment
definition to be ended.
v A commit, rollback, or ENDCMTCTL command is run, and a STRCMTCTL command was not run.
This is not an error condition for programs that run within an activation group and the job-level
commitment definition is active. The job-level commitment definition can be started only by a single
program, but when started by a program, the job-level commitment definition is used by any program
running in any activation group that is not using an activation-group-level commitment definition.
Programs that run within an activation group and are to use the activation-group-level commitment
definition must first start the activation-group-level commitment definition with the STRCMTCTL
command.
v An ENDCMTCTL command is run with files still open under commitment control for the commitment
definition.
v A job performing a save operation has one or more commitment definitions that are not at a
commitment boundary.
v A save-while-active operation ended because other jobs with committable resources did not reach a
commitment boundary in the time specified for the SAVACTWAIT parameter.
v A save-while-active process was not able to continue because of API committable resources being
added to more than one commitment definition for a single job.
v More than 1023 commitment definitions exist for a single job.
v The conversation to a remote location is lost due to a resource failure. This may cause the transaction
to be rolled back.
v A one-phase resource that is opened for update is present at a node that did not initiate the commit
operation. You must remove either the resource or the node that initiated the commit request.
v A commit operation is requested while the transaction is in rollback required (RBR) state. A rollback
operation must be done.
v An API exit program issues a commit request or a rollback request.
v A trigger program issues a commit request or a rollback request for the commitment definition under
which the trigger program was called.
You cannot monitor for any of the following messages during activation group end or job process end.
Also, you can only monitor for CPFxxxx messages. CPDxxxx messages are always sent as diagnostic
messages, which cannot be monitored. Any errors encountered when ending an activation-group-level
commitment definition during activation group end or any commitment definition during job end are left
in the job log as diagnostic messages.
Commitment control 95
CPD8351
Changes may not have been committed.
CPD8352
Changes not committed at remote location &3.
CPD8353
Changes to relational database &1 may not have been committed.
CPD8354
Changes to DDM file &1 may not have been committed.
CPD8355
Changes to DDL object &1 may not have been committed.
CPD8356
Rolled back changes may have been committed.
CPD8358
Changes to relational database &1 may not have been rolled back.
CPD8359
Changes to DDM file &1 may not have been rolled back.
CPD835A
Changes to DDL object &3 may not have been rolled back.
CPD835C
Notify object &1 in &2 not updated.
CPD835D
DRDA(R) resource does not allow SQL cursor hold.
CPF835F
Commit or rollback operation failed.
CPD8360
Members or files or both were already deallocated.
CPD8361
API exit program &1 failed during commit.
CPD8362
API exit program &1 failed during roll back.
CPD8363
API exit program &1 ended after &4 minutes during commit.
CPD8364
API exit program &1 ended after &4 minutes during rollback.
CPD836F
Protocol error occurred during commitment control operation.
CPD83D1
API resource &4 cannot be last agent.
CPD83D7
Commit operation changed to rollback.
CPD83D9
A heuristic mixed condition occurred.
CPF83DB
Commit operation resulted in rollback.
CPD83DC
Action If Problems Used to determine commit or rollback operation; reason &2.
CPD83DD
Conversation ended; reason &1.
CPD83DE
Return information not valid.
CPD83EC
API exit program &1 voted rollback.
CPD83EF
Rollback operation started for next logical unit of work.
CPF8350
Commitment definition not found.
CPF8355
ENDCMTCTL not allowed. Pending changes active.
CPF8356
Commitment control ended with &1 local changes not committed.
CPF8358
Notify object &1 in &2 not updated.
CPF8359
Rollback operation failed.
CPF835A
End of commitment definition &1 canceled.
CPF835B
Errors occurred while ending commitment control.
CPF835C
Commitment control ended with remote changes not committed.
CPF8363
Commit operation failed.
CPF8364
Commitment control parameter value is not valid. Reason code &3.
Commitment control 97
CPF8367
Cannot perform commitment control operation.
CPF8369
Cannot place API commitment resource under commitment control; reason code &1.
CPF83D0
Commitment operation not allowed.
CPF83D2
Commit complete == Resynchronization in progress has been returned.
CPF83D3
Commit complete == Heuristic Mixed has been returned.
CPF83D4
Logical unit of work journal entry not sent.
CPF83E1
Commit operation failed due to constraint violation.
CPF83E2
Rollback operation required.
CPF83E3
Requested nesting level is not active.
CPF83E4
Commitment control ended with resources not committed.
CPF83E6
Commitment control operation completed with resynchronization in progress.
CPF83E7
Commit or rollback of X/Open global transaction not allowed.
If another program is called and causes a commit operation, the partially completed transaction from the
previous program is committed.
To prevent partially completed transactions from being committed, monitor for escape messages after the
CALL command. For example, if it is an RPG program, use the following coding:
CALL RPGA
MONMSG MSGID(RPG9001)
EXEC(ROLLBACK) /*Rollback if pgm is canceled*/
If it is a COBOL program:
All of the situations described in the previous table also apply when a job is ending except that one of
the following messages is sent:
v CPF8356 if only local resources are registered
Commitment control 99
v CPF835C if only remote resources are registered
v CPF83E4 if both local and remote resources are registered
In addition, one of two messages may appear specific to job completion if a commit and rollback exit
program for an API committable resource has been called. If the commit and rollback exit program does
not complete within 5 minutes, the program is canceled, a diagnostic message CPD8363 (for commit) or
CPD8364 (for rollback) is sent, and the remainder of the commit or rollback processing continues.
All of the situations described in the previous table also apply during IPL recovery for commitment
definitions except that message CPF835F is sent instead of message CPF8359 or CPF8363. Messages that
get sent for a particular commitment definition may appear in the job log for one of the QDBSRVxx jobs
or the QHST log. In the QHST log, message CPI8356 indicates the beginning of IPL recovery for a
particular commitment definition. Message CPC8351 indicates the end of IPL recovery for a particular
commitment definition and any other messages regarding the recovery of that commitment definition is
found between those two messages.
One of two messages may appear specific to a commitment definition if a commit and rollback exit
program for an API committable resource has been called. If the commit and rollback exit program does
not complete within 5 minutes, the program is canceled, a diagnostic message CPD8363 (for commit) or
CPD8364 (for rollback) is sent, and the remainder of the commit or rollback processing continues.
Detect deadlocks
A deadlock condition can occur when a job holds a lock on an object, object A, and is waiting to obtain a
lock on another object, object B. At the same time, another job or transaction currently holds a lock on
object B and is waiting to obtain a lock on object A.
Do the following steps to find out if a deadlock condition has occurred and fix it if it has:
1. Locate the suspended job in the list of active jobs. Determining the status of a job to determine if a job
is suspended.
2. Look at the objects the job is waiting to lock. For transactions with transaction-scoped locks see
“Display locked objects for a transaction” on page 62 for steps. For transactions with job-scoped locks
see Details: active job properties.
3. For all the objects the job is waiting to lock, look at the list of lock holders (transactions or jobs) and
try to find a conflicting lock corresponding to the level requested by the suspended job.
4. If a transaction is holding a conflicting lock, “Display jobs associated with a transaction” on page 62
and see if one of them is waiting to lock.
5. Determine if this waiting job is trying to lock one of the objects locked by the initial suspended job.
When you find the job that is trying to lock on of the objects locked by the initial suspended job, you
can identify the objects in question as the trouble spots.
6. Investigate the transaction in order to determine the appropriate course of action.
a. Look at the transaction properties to find out what application initiated it and then look at the
application code.
b. Or trace the transaction’s actions up to this point by finding the Commit cycle ID in the
transaction properties and then searching in a journal for entries containing this ID. To do this,
you can use the Retrieve Journal Entry (RTVJRNE) command and specify the CMTCYCID
parameter.
c. After obtaining relevant information the user may choose to “When to force commits and rollbacks
and when to cancel resynchronization” on page 101 operation.
For more information about recovery see “When to force commits and rollbacks and when to cancel
resynchronization.”
Before you make a heuristic decision, gather as much information as you can about the transaction.
Display the jobs that are associated with the commitment definition and make a record of what journals
and files are involved. You can use this information later if you need to display journal entries and apply
or remove journaled changes manually.
The best place to find out information about a transaction is to look at the location that was the initiator
for that transaction. However, the decision to commit or roll back may be owned by an API resource or
by a last agent.
If an API resource was registered as a last agent resource, the final decision of whether to commit or roll
back is owned by the API resource. You need to look at information about the application and how it
uses the API resource to determine whether to commit or to roll back.
If the transaction has a last agent selected, the last agent owns the decision to commit or roll back. Look
at the status of the last agent for information about the transaction.
When you must make heuristic decisions or cancel resynchronization due to a system or communications
failure that cannot be repaired, you can find all transactions in doubt by using the following:
In this display you can see the commitment definition, resynchronization status, the current unit of work
ID, and the current unit of work state for each transaction. Look for transactions with the following:
v Transactions with a Logical Unit of Work State of Prepared or Last Agent Pending.
v Transactions that show Resynchronization in Progress status of yes.
To work with the job that is participating in the transaction on this system right-click the transaction and
select job.
When you right-click the transaction, you can also select Force Commit, Force Rollback, or Cancel
Resynchronization.
Before making a heuristic decision or canceling resynchronization, you might want to check the status of
the jobs on other systems associated with the transaction. Checking the jobs on remote systems might
help you avoid decisions that cause database inconsistencies between systems.
1. Right-click the transaction you want to work with.
2. Select Resource Status
3. In the Resource Status dialog, select the Conversation tab for SNA connections; select Connection for
TCP/IP connections.
Each conversation resource represents a remote system that is participating in the transaction. On the
remote systems, you can use iSeries Navigator to see the transactions associated with the transaction.
The base portion of the unit of work ID is the same on all the systems. When you “Display commitment
control information” on page 61 on the remote system, look for the base portion of the unit of work ID
that is the same on the local system.
For example, if the unit of work ID on the local system starts with: APPN.RCHASL97.X’112233445566, look
for the unit of work ID on the remote system that also starts with APPN.RCHASL97.X’112233445566.
A rollback operation removes all changes made within a transaction since the previous commit operation
or rollback operation. During a rollback operation, the system also releases locks related to the
transaction. If the system contains thousands of transactions, the system can take hours to complete a
rollback operation. These long-running rollbacks can consume critical processor time, lock resources or
take up storage space.
Before you end a long-running rollback, you need to know which commitment definitions are being
rolled back and what state the commitment definitions are in. The State field for commitment definitions
that are rolling back is set to ROLLBACK IN PROGRESS.
Use the Work with Commitment Definitions (WRKCMTDFN) command to check the status of a rollback
by following these steps:
1. Type WRKCMTDFN JOB(*ALL) from the character-based interface.
2. Type F11 to display the State field.
You must have All Object (*ALLOBJ) special authority to end a long-running rollback. To end a
long-running rollback, follow these steps:
1. Type WRKCMTDFN JOB(*ALL) from the character-based interface.
2. Type option 20 (End rollback) on the commitment definition you want to end.
Files with partial transactions have the Partial Transactions Exist, Rollback Ended field set to *YES in the
output from the Display File Description (DSPFD) command. You must remove partial transactions before
the file can be used. You can remove partial transactions by deleting the file and restoring the file from a
prior save. If you do not have a prior save, you can use the Change Journaled Object (CHGJRNOBJ)
command to reset the Partial Transaction Exists state so you can open the file. Using the CHGJRNOBJ
requires you to edit the file to bring the file to a consistent state. You must use the CHGJRNOBJ
command only if no prior save is available.
Users with *ALLOBJ special authority can end rollbacks by default. If you want to restrict users who
have *ALLOBJ special authority from ending rollbacks, you can do this by creating data area
QGPL/QTNNOENDRB.
For more information about data areas see the Create Data Area (CRTDTAARA) command.
Manuals
v See the COBOL/400(R) User’s Guide
Redbooks
v Connecting WebSphere(R) to DB2(R) UDB Server
(5 MB)
v Advanced Functions and Administration on DB2 Universal Database(TM) for iSeries
(4.8 MB)
v Striving for Optimal Journal Performance on DB2 Universal Database for iSeries
(3.1 MB)
Web site
Other information
v Database programming
v SQL programming concepts
v XA APIs
v Journal management
If you need Adobe Acrobat Reader to view or print these PDFs, you can download a copy from the
Adobe Web site (www.adobe.com/products/acrobat/readstep.html)
IBM(R) may not offer the products, services, or features discussed in this document in other countries.
Consult your local IBM representative for information about the products and services currently available
in your area. Any reference to an IBM product, program, or service is not intended to state or imply that
only that IBM product, program, or service may be used. Any functionally equivalent product, program,
or service that does not infringe any IBM intellectual property right may be used instead. However, it is
the user’s responsibility to evaluate and verify the operation of any non-IBM product, program, or
service.
IBM may have patents or pending patent applications covering subject matter described in this
document. The furnishing of this document does not give you any license to these patents. You can send
license inquiries, in writing, to:
IBM Director of Licensing
IBM Corporation
500 Columbus Avenue
Thornwood, NY 10594-1785
U.S.A.
For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property
Department in your country or send inquiries, in writing, to:
IBM World Trade Asia Corporation
Licensing
2-31 Roppongi 3-chome, Minato-ku
Tokyo 106, Japan
The following paragraph does not apply to the United Kingdom or any other country where such
provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION
PROVIDES THIS PUBLICATION “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some
states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this
statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically
made to the information herein; these changes will be incorporated in new editions of the publication.
IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this
publication at any time without notice.
Any references in this information to non-IBM Web sites are provided for convenience only and do not in
any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of
the materials for this IBM product and use of those Web sites is at your own risk.
IBM may use or distribute any of the information you supply in any way it believes appropriate without
incurring any obligation to you.
Licensees of this program who wish to have information about it for the purpose of enabling: (i) the
exchange of information between independently created programs and other programs (including this
one) and (ii) the mutual use of the information which has been exchanged, should contact:
Such information may be available, subject to appropriate terms and conditions, including in some cases,
payment of a fee.
The licensed program described in this information and all licensed material available for it are provided
by IBM under terms of the IBM Customer Agreement, IBM International Program License Agreement, or
any equivalent agreement between us.
Any performance data contained herein was determined in a controlled environment. Therefore, the
results obtained in other operating environments may vary significantly. Some measurements may have
been made on development-level systems and there is no guarantee that these measurements will be the
same on generally available systems. Furthermore, some measurements may have been estimated through
extrapolation. Actual results may vary. Users of this document should verify the applicable data for their
specific environment.
Information concerning non-IBM products was obtained from the suppliers of those products, their
published announcements or other publicly available sources. IBM has not tested those products and
cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM
products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of
those products.
All statements regarding IBM’s future direction or intent are subject to change or withdrawal without
notice, and represent goals and objectives only.
All IBM prices shown are IBM’s suggested retail prices, are current and are subject to change without
notice. Dealer prices may vary.
This information is for planning purposes only. The information herein is subject to change before the
products described become available.
This information contains examples of data and reports used in daily business operations. To illustrate
them as completely as possible, the examples include the names of individuals, companies, brands, and
products. All of these names are fictitious and any similarity to the names and addresses used by an
actual business enterprise is entirely coincidental.
COPYRIGHT LICENSE:
This information contains sample application programs in source language, which illustrate programming
techniques on various operating platforms. You may copy, modify, and distribute these sample programs
in any form without payment to IBM, for the purposes of developing, using, marketing or distributing
application programs conforming to the application programming interface for the operating platform for
which the sample programs are written. These examples have not been thoroughly tested under all
conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these
programs. You may copy, modify, and distribute these sample programs in any form without payment to
IBM for the purposes of developing, using, marketing, or distributing application programs conforming
to IBM’s application programming interfaces.
Each copy or any portion of these sample programs or any derivative work, must include a copyright
notice as follows:
(C) (your company name) (year). Portions of this code are derived from IBM Corp. Sample Programs. (C)
Copyright IBM Corp. _enter the year or years_. All rights reserved.
Trademarks
The following terms are trademarks of International Business Machines Corporation in the United States,
other countries, or both:
Application System/400
AS/400
e (logo)
IBM
iSeries
Operating System/400
OS/400
400
Websphere
RPG/400
Redbooks
Integrated Language Environment
DRDA
Distributed Relational Database Architecture
DB2 Universal Database
DB2
COBOL/400
Other company, product, and service names may be trademarks or service marks of others.
Personal Use: You may reproduce these Publications for your personal, noncommercial use provided that
all proprietary notices are preserved. You may not distribute, display or make derivative works of these
Publications, or any portion thereof, without the express consent of IBM.
Commercial Use: You may reproduce, distribute and display these Publications solely within your
enterprise provided that all proprietary notices are preserved. You may not make derivative works of
these Publications, or reproduce, distribute or display these Publications or any portion thereof outside
your enterprise, without the express consent of IBM.
Except as expressly granted in this permission, no other permissions, licenses or rights are granted, either
express or implied, to the Publications or any information, data, software or other intellectual property
contained therein.
IBM reserves the right to withdraw the permissions granted herein whenever, in its discretion, the use of
the Publications is detrimental to its interest or, as determined by IBM, the above instructions are not
being properly followed.
You may not download, export or re-export this information except in full compliance with all applicable
laws and regulations, including all United States export laws and regulations. IBM MAKES NO
GUARANTEE ABOUT THE CONTENT OF THESE PUBLICATIONS. THE PUBLICATIONS ARE
By downloading or printing a publication from this site, you have indicated your agreement with these
terms and conditions.
All sample code is provided by IBM for illustrative purposes only. These examples have not been
thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability,
or function of these programs.
All programs contained herein are provided to you ″AS IS″ without any warranties of any kind. The
implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly
disclaimed.
Printed in USA