Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 20
Example of Updating State Information
Performance Versus Recoverability
In placing update points, you need to consider the tradeoff between performance and
the degree of recoverability desired. For example, an application that reads and
produces a summary of a file that contains hundreds of thousands of records may not
require a continuation point during the read stage, because all the reads are retryable.
But it might be desirable to include some degree of recovery so that, in the event of
failure, it would not be necessary to repeat all the reads. On the other hand, placing an
update point after every read would not be practical. A reasonable compromise might
be to place an update point after every hundred, or every thousand, reads.
You should keep to a minimum the number of times you update state information in a
processing loop and the amount of data in each update. But you must be sure that any
update point that also defines a continuation point yields a valid program state. For
example, you might update the data stack before entering a loop to ensure that the
calling chain is saved, then, within the loop, update only the data that is changed within
the loop.
Example of Updating State Information
The following example illustrates the placement of state information update points.
The example is a simple transaction that reads data from a terminal and uses it to
update a database record.
Records have the form:
account_no current_balance credit_limit
They are defined by the following structure:
struct{
long account_no;
long current_balance;
long credit_limit;
}buf2;
Data read from the terminal is defined as follows:
struct{
long acct_no;
long amount;
}buf1;
The transaction cycle is as follows:
err = WRITEREAD (terminal, buf1,...); /*returns acct_no
and amount */
err = POSITION (account_file, buf1.acct_no);
err = READUPDATE (account_file, buf2,...);
x = buf2.current_balance + buf1.amount;
if (x > buf2.credit_limit)
Credit limit exceeded...
else {