Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 18
Updating Application State Information
For an output stream, a call to a write function may leave a partially filled, unflushed
buffer. The __ns_fget_file_state function does not cause a flush; it is your
responsibility to ensure that unflushed buffers are handled appropriately. Three
approaches are:
Perform a flush operation (for example, by a call to the fflush function) before
getting file state information.
Ignore the effects of unflushed buffers (for situations where unflushed buffer
contents are not critical to the application).
Specify unbuffered file operations by calling the setvbuf or setbuf function.
Note that whether buffering is enabled or disabled, and whether a user-specified or
system-specified buffer is used, are each specified independently and can be different
in the primary and backup processes.
Updating Application State Information
Application state information is the data values needed by the backup process to take
over execution from a failed primary process. This may include local variables, all or
part of the data stack, and data buffers. What constitutes necessary and sufficient
application state information is highly application-dependent.
Typically, file buffer state updating occurs just before writing to a disk file; the data
about to be written is sent to the backup process. Careful selection of which data
buffers (and corresponding file synchronization information) to send can increase the
efficiency of an active backup program. An example of file buffer state updating is an
entry received from a terminal: the data buffer state is updated immediately after the
read to minimize the possibility that the operator would have to reenter data.
Various performance tradeoffs can be made when determining what constitutes the
application state. For example, suppose an item of information can be either updated
in the backup process (by the primary process sending the information to the backup
process) or recomputed in the backup process on takeover. If the primary process
sends the information to the backup process, the performance of the primary process
is lower (because it is sending state update messages), but the time required for the
backup process to take over is relatively fast. Conversely, if the backup process
recomputes the state, the performance of the primary process is relatively high
(because it is not sending update messages), but the performance of the backup
process is relatively low (because it must recompute the state information).
Guidelines for Updating State Information
When devising a strategy for updating state information, there are two major
considerations:
The type of I/O done by the program. In general, when the backup process takes
over for the primary process, repeating I/O operations ensures that they completed