Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 22
Example of Updating State Information
err = POSITION (account_file, 12345D);
err = READUPDATE (account_file, buf2,...); returns the following:
account_no current_balance credit_limit
12345 $485 $500
x = $485 + $10;
if (x > $500) ...
current_balance = x;
err = WRITEUPDATE (account_file, buf2, ...); writes the following:
account_no current_balance credit_limit
12345 $495 $500
*********** FAILURE OCCURS HERE**********
The backup process resumes with the latest application state information:
account_no = 12345 and amount = $10.
case (cnt = 2):
err = POSITION (account_file, 12345D);
err = READ (account_file, buf2,...); reads the following:
account_no current_balance credit_limit
12345 $495 $500
x = $495 + 10;
IF (x > $500)...
Here, the test fails because the update to disk completed successfully and
current_balance has already been updated. The user is given an indication that
account number 12345 has exceeded its credit limit; therefore, the purchase is
refused. However, the balance in account 12345 reflects that a purchase was made.
An additional update point is now added to the transaction cycle:
/*First update point*/
cnt = 1;
...Update cnt (idle state)...
err = WRITEREAD (terminal,buf1,...); /*returns account_no
and amount */
/*Second update point. Include control state and*/
/*terminal data */
cnt = 2;
...Update cnt, buf1...
err = POSITION (account_file, account_no);
err = READUPDATE (account_file, buf2,...);
x = buf2.current_balance + buf1.amount;
if (x > credit_limit)
credit limit exceeded...
else
buf2.current_balance = x;