Protecting FOCUS Database Server Transactions

In this section:

The following facilities are available to protect transactions in case a system failure brings down the FOCUS Database Server:

Under SU, when FOCUS writes transactions for a single user on a FOCUS Database Server, it automatically writes pending transactions of all users on that server, even those users who did not request a checkpoint action. It then records this as a SAV action in the HLIPRINT file. FOCUS also writes the transactions of all users on the same server when a MODIFY or Maintain request submitted by one user finishes execution. This is recorded as a CLO action in the HLIPRINT file.

If the system fails while MODIFY or Maintain requests are executing, all transactions entered before FOCUS last wrote to the database (because of the Checkpoint facility or because a MODIFY or Maintain request finished execution) are saved in the database. All transactions entered after that may be lost and must be reentered. In MODIFY, you can use CHECK 1 to avoid this situation.

It is sometimes a good idea to log all transactions in a sequential file so that they may be re-entered if any are lost. To do this, add LOG or TYPE commands to the MODIFY or Maintain request. LOG commands are satisfactory for simple requests, while TYPE commands are better for complex Case Logic requests. For more information, see the Maintaining Databases manual.

You can also protect the integrity of the centrally controlled database itself with the Absolute File Integrity feature described in your FOCUS documentation. Absolute File Integrity is not needed for Maintain.


Top of page

x
The Checkpoint Facility (MODIFY Only)

When FOCUS accepts transactions, it does not write the transactions to the database immediately. Rather, it collects them in a buffer. When the buffer is full, FOCUS writes them all to the database at the same time. This reduces the number of input/output operations that FOCUS must perform. However, if your z/OS system fails and brings down the server, the transactions collected in the buffer may be lost. You can instruct FOCUS to write more frequently to the database by using the Checkpoint facility, described in the Maintaining Databases manual.

The Checkpoint facility is activated with the MODIFY CHECK command that specifies how many transactions to accumulate in the buffer before writing them to the database. The following request writes transactions to the database in groups of 10:

MODIFY FILE EMPLOYEE
PROMPT EMP_ID CURR_SAL
MATCH EMP_ID
   ON NOMATCH REJECT
   ON MATCH UPDATE CURR_SAL
CHECK 10
DATA

Top of page

x
Managing MODIFY and Maintain Transactions: COMMIT and ROLLBACK

In this section:

COMMIT and ROLLBACK are two MODIFY and Maintain subcommands. COMMIT gives you control over the content of database changes and ROLLBACK enables you to undo changes before they become permanent.

The COMMIT subcommand safeguards transactions in case of a system failure and provides greater control than the Checkpoint facility over which transactions are written to the database.

The MODIFY CHECK command only enables you to control the number of transactions that must occur before changes are written to the database. When using CHECK, you cannot change the Checkpoint setting once the request begins execution. Similarly, changes cannot be cancelled. For information on the CHECK command, see The Checkpoint Facility (MODIFY Only).

COMMIT enables you to make changes based on the content of the transactions as well as the number. Changes you do not want to make can be cancelled with ROLLBACK, unless a COMMIT has been issued for those changes. Should the system fail, either all or none of your transactions will be processed.

Maintain uses FOCURRENT to report the result of the latest COMMIT action. Maintain does not support the Checkpoint facility. Therefore, the only way to control a unit of work in Maintain is with the COMMIT and ROLLBACK subcommands.

Absolute File Integrity is required in order to use COMMIT and ROLLBACK in MODIFY. Absolute File Integrity for databases in SU is provided solely by the FOCUS Shadow Writing Facility. See your FOCUS documentation for information on Absolute File Integrity and the SET SHADOW command.



x
COMMIT and ROLLBACK Subcommands

COMMIT and ROLLBACK each process a logical transaction. A logical transaction is a group of database changes in the MODIFY or Maintain environment that you want to treat as one. For example, you can handle multiple records displayed on a CRTFORM and then processed using the REPEAT command as a single transaction. A logical transaction is terminated by either COMMIT or ROLLBACK. COMMIT and ROLLBACK also can be used for single record processing.

When COMMIT ends a logical transaction, it writes all changes to the database. Once changes have been committed, they cannot be rolled back. COMMIT can be coded as a global subcommand or as part of MATCH or NEXT logic. The possible MATCH and NEXT commands are:

COMMIT
ON MATCH COMMIT
ON NOMATCH COMMIT
ON MATCH/NOMATCH COMMIT
ON NEXT COMMIT
ON NONEXT COMMIT

When ROLLBACK terminates a logical transaction, it does not write changes to the database. The ROLLBACK subcommand cancels changes made since the last COMMIT. ROLLBACK cannot cancel changes once a COMMIT has been issued for them.

ROLLBACK can be coded as a global subcommand or as part of MATCH or NEXT logic. Possible MATCH and NEXT commands are:

ROLLBACK
ON MATCH ROLLBACK
ON NOMATCH ROLLBACK
ON MATCH/NOMATCH ROLLBACK
ON NEXT ROLLBACK
ON NONEXT ROLLBACK

If the COMMIT fails for any reason (for example, system failure or lack of disk space), no changes are made to the database. In this way, COMMIT is an all or nothing feature that ensures database integrity.



x
Using COMMIT and ROLLBACK With the FOCUS Database Server

The SU change/verify protocol operates on a logical transaction basis that may encompass a block of records. It relies on the optimistic assumption that two users rarely change the same records at the same time. In SU processing with COMMIT, the server keeps a table of soft locks that tracks which records have been requested by which users.

When a COMMIT is issued, the server checks this table for each record that you want to change to determine if another user changed a record between the time you retrieved it and the time you issued the COMMIT. If another user has issued a COMMIT against a record you intend to change, your changes are automatically rolled back.

For example, User A and User B execute a MODIFY or Maintain procedure against the EMPLOYEE database on a FOCUS Database Server. Each user matches on the same employee ID and performs a MATCH action as follows:

User A

User B

  1. Matches on employee ID 123.
  2. Updates current salary to $50,000.
  3. Issues a COMMIT command.
  1. Matches on employee ID 123.
  2. Deletes employee 123.
  3. Issues a COMMIT command.

If User A issues a COMMIT before User B, User B's changes will be rolled back. If User B issues a COMMIT before User A, User A's changes will be rolled back.

Many applications contain transactions that are interdependent. For these applications, processing is successful only when several physical transactions are complete. The following application transfers funds from one bank account to another. Two components make up each logical transaction:

  • The subtraction of an amount of money from one account.
  • The addition of the same amount to another account.

If either part of the logical transaction is not complete, no changes should be made to the database. Because the application has multiple users, it is essential that each account be involved in only one transfer transaction at a time.

The BANK file in this application is a FOCUS database on a FOCUS Database Server with the following Master File:

FILE = BANK, SUFFIX = FOC,$
SEGNAME = TOPSEG, SEGTYPE = S1,$
   FIELD = ACCOUNT_NUM      , ACCT   , A8     ,$
   FIELD = BALANCE          , BAL    , D12.2  ,$
   FIELD = CUSTOMER         , NAME   , A40    ,$ 

The following MODIFY procedure shows how COMMIT and ROLLBACK can be used to ensure that a logical transaction is complete before it is written to the database. It also shows the use of FOCURRENT in SU COMMIT processing. Numbers to the left of the command lines refer to annotations following the example:

    MODIFY FILE BANK
    COMPUTE AMOUNT = ;
            FROM_ACCOUNT/A8  = ;
            TO_ACCOUNT/A8 = ; 
  1.  CRTFORM
    "FUND TRANSFER. ENTER ACCOUNT NUMBERS:"
    "   TO TRANSFER FROM == > <FROM_ACCOUNT"
    "   TO TRANSFER TO   == > <TO_ACCOUNT"
    "   ENTER AMOUNT     == > <AMOUNT" 
  2.  PERFORM SUBTRACT 
  5.  PERFORM ADD 
  7.  COMMIT 
  8.  IF FOCURRENT EQ 0 GOTO TOP;
    TYPE "ACCOUNTS WERE IN USE. PLEASE TRY AGAIN."
    GOTO TOP 
  2.  CASE SUBTRACT 
    COMPUTE ACCOUNT_NUM = FROM_ACCOUNT; 
    MATCH ACCOUNT_NUM 
  3.     ON NOMATCH ROLLBACK
       ON NOMATCH REJECT
       ON MATCH COMPUTE BALANCE = D.BALANCE - AMOUNT; 
  4.     ON MATCH IF BALANCE LT 0 PERFORM REDO; 
       ON MATCH UPDATE BALANCE
    ENDCASE 
  5.  CASE ADD
    COMPUTE ACCOUNT NUM = TO_ACCOUNT; 
    MATCH ACCOUNT NUM 
  6.     ON NOMATCH ROLLBACK
       ON NOMATCH REJECT
       ON MATCH COMPUTE BALANCE = D.BALANCE + AMOUNT;
       ON MATCH UPDATE BALANCE
    ENDCASE 
  4.  CASE REDO
    TYPE "BALANCE WILL BE LESS THAN ZERO. TRY ANOTHER AMOUNT." 
    GOTO TOP
    ENDCASE
    DATA
    END
  1. The CRTFORM requests the account from which to take funds, the account to which funds will be transferred, and the amount to be transferred.
  2. CASE SUBTRACT subtracts the amount from the first account.
  3. If the account is not in the database, any pending changes that may have already been made are rolled back.
  4. The new balance is checked before an update takes place. If the balance is less than zero, the user goes to the top case. No UPDATE or COMMIT occurs at this point.
  5. CASE ADD adds the amount to the second account.
  6. If the account is not in the database, any pending changes that may have already been made are rolled back. This is particularly important in CASE ADD, because funds may have already been subtracted (the UPDATE in CASE SUBTRACT).
  7. The COMMIT is executed if both updates are successful.
  8. A test for a zero value in FOCURRENT is placed after the COMMIT command. If the COMMIT fails (FOCURRENT has a non zero value) the transaction will be automatically rolled back.

Note:

  • COMMIT and ROLLBACK are available only for FOCUS and XFOCUS files; they will be ignored in MODIFY and Maintain procedures against non-FOCUS data sources.
  • All files referenced by a MODIFY or Maintain procedure that uses COMMIT and ROLLBACK processing must be specified in a USE command. This includes cross-referenced files and joined files.
  • After a COMMIT or ROLLBACK command against a central database, the procedure has no current position in the file. You must reestablish position with a MATCH or NEXT command.
  • COMMIT and ROLLBACK functionality are not available for HLI.
  • COMMIT and ROLLBACK do not support use of an alternate view. For example, MODIFY filename.field is not supported.
  • COMMIT and ROLLBACK cannot be used to process S0 segments.
  • Text fields cannot be used in a MODIFY or Maintain that uses COMMIT and ROLLBACK.
  • The maximum size of the buffer used for COMMIT transactions to be sent to the server is 32K bytes.

Information Builders