Commitment control is an extension of the journal management function on the iSeries™ server. The server can identify and process a group of relational database changes as a single unit of work (transaction).
An SQL COMMIT statement guarantees that the group of operations is completed. An SQL ROLLBACK statement guarantees that the group of operations is backed out. The only SQL statements that cannot be committed or rolled back are:
Under commitment control, tables and rows used during a transaction are locked from other jobs. This ensures that other jobs do not use the data until the transaction is complete. At the end of the transaction, the program issues an SQL COMMIT or ROLLBACK statement, freeing the rows. If the server or job ends abnormally before the commit operation is performed, all changes for that job since the last time a commit or rollback operation occurred are rolled back. Any affected rows that are still locked are then unlocked. The lock levels are as follows:
Table 1 shows the record lock duration for each of these lock level values.
If a remote relational database is accessing data on the server and requesting commit level repeatable read (*RR), the tables will be locked until the query is closed. If the cursor is read only, the table will be locked (*SHRNUP). If the cursor is in update mode, the table will be locked (*EXCLRD).
The journal created in the SQL collection is normally the journal used for logging all changes to SQL tables. You can, however, use the server journal functions to journal SQL tables to a different journal.
Commitment control can handle up to 131 072 distinct row changes in a unit of work. If COMMIT(*ALL) is specified, all rows read are also included in the 131 072 limit. (If a row is changed or read more than once in a unit of work, it is only counted once toward the 131 072 limit.) Maintaining a large number of locks adversely affects server performance and does not allow concurrent users to access rows locked in the unit of work until the unit of work is completed. It is, therefore, more efficient to keep the number of rows processed in a unit of work small. Commitment control allows up to 512 tables either open under commitment control or closed with pending changes in a unit of work.
The HOLD value on COMMIT and ROLLBACK statements allows you to keep the cursor open and start another unit of work without issuing an OPEN again. The HOLD value is not available when there are non-iSeries connections that are not released for a program and SQL is still in the call stack. If ALWBLK(*ALLREAD) and either COMMIT(*CHG) or COMMIT(*CS) are specified when the program is precompiled, all read-only cursors will allow blocking of rows and a ROLLBACK HOLD statement will not roll the cursor position back.
If there are locked rows (records) pending from running a SQL precompiled program or an Interactive SQL session, a COMMIT or ROLLBACK statement can be issued from the server Command Entry display. Otherwise, an implicit ROLLBACK operation occurs when the job is ended.
You can use the Work with Commitment Definitions (WRKCMTDFN) command to monitor the status of commitment definitions and free up locks and held resources involved with commitment control activities across servers.
SQL statement | COMMIT parameter | Duration of record locks | Lock type |
---|---|---|---|
SELECT INTO | *NONE |
No locks |
|
FETCH (read-only cursor) | *NONE |
No locks |
|
FETCH (update or delete capable cursor) See note 1 | *NONE |
When record not updated or deleted |
UPDATE |
INSERT (target table) | *NONE |
No locks |
|
INSERT (tables in subselect) | *NONE |
No locks |
|
UPDATE (non-cursor) | *NONE |
Each record locked while being updated |
UPDATE |
DELETE (non-cursor) | *NONE |
Each record locked while being deleted |
UPDATE |
UPDATE (with cursor) | *NONE |
Lock released when record updated |
UPDATE |
DELETE (with cursor) | *NONE |
Lock released when record deleted |
UPDATE |
Subqueries (update or delete capable cursor or UPDATE or DELETE non-cursor) | *NONE |
From read until next FETCH |
READ |
Subqueries (read-only cursor or SELECT INTO) | *NONE |
No locks |
|
Notes:
|