COBOL Manual for TNS and TNS/R Programs

Fault-Tolerant Processes
HP COBOL Manual for TNS and TNS/R Programs522555-006
32-13
Designing Programs for the Fault-Tolerant Facility
After the program is compiled and debugged, it must be run as a named process (see
Process Names).
Designing Programs for the Fault-Tolerant Facility
You must design a program to use the fault-tolerant facility. It is very difficult, if not
impossible, to retrofit the use of the fault-tolerant facility to an existing program.
A checkpoint is a location in the program at which processing resumes when a
takeover occurs. All data from the primary process that is part of the program state
must be checkpointed to the backup process if the takeover is to succeed.
You must checkpoint before any nonretryable operation, such as a write to disk. You
can (for operator convenience) checkpoint after a read from a terminal. You can (for
programming convenience) checkpoint after a read from tape.
PROCEDURE DIVISION.
CENTRAL SECTION.
...
OPEN I-O TEST-FILE SHARED SYNCDEPTH 1.
PERFORM GET-CPUNUM.
STARTBACKUP BCPU, 1.
IF PROGRAM-STATUS NOT = "0000"
DISPLAY "STARTBACKUP UNSUCCESSFUL, STATUS = ",
PROGRAM-STATUS.
STOP RUN.
PERFORM UPDATE-RECS
UNTIL UPDATES-DONE.
...
GET-CPUNUM.
ENTER "GETBACKUPCPU" IN COBOLLIB GIVING BCPU.
IF BCPU < 0 OR BCPU > 15
DISPLAY "BACKUP CPU INVALID, RUNNING WITHOUT BACKUP".
UPDATE-RECS.
...
READ TEST-FILE WITH LOCK.
...
CHECKPOINT TEST-FILE,
TEST-REC,
CKPT-DATA.
IF PROGRAM-STATUS > "0000"
AND PROGRAM-STATUS < "1000"
DISPLAY "Backup took over".
REWRITE TEST-REC WITH UNLOCK.
...
Example 32-1. Key Parts of Fault-Tolerant HP COBOL Program (page 2 of 2)