Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 16
Updating File State Information
points. Basic file sync data can be obtained using the _ns_fget_file_state
function. For key-sequenced files FILE_GETSYNCINFO_ is required.
The need to prevent duplicate file operations is illustrated in the following example. A
primary process completes the following write operation successfully but fails before
updating state information for the backup process.
Execution -> ...Update state information...
resumes here
err = POSITION (F1, -1D); /*position to
eof*/
err = WRITE (F1, buff);
***Primary fails here***
Upon taking over from the primary process, the backup process reexecutes the
operations just completed by the primary process. If the WRITE were performed as
requested, the record would be duplicated at the new end-of-file location.
To prevent a write operation already performed by the primary process from being
duplicated by the backup process, the sync-depth parameter of the
__ns_fopen_special function must be specified as a value greater than zero when
opening the file. For a file opened in this manner, a sync ID in the sync block is used
to identify the operation about to be performed by the backup process in the event of a
primary process failure. If the backup process requests an operation already
completed by the primary process, the server, through use of the sync ID, can
recognize this condition. Then, instead of performing the requested operation again,
the server returns just the completion status of the original operation to the backup
process. (The completion status was saved by the system when the primary process
performed the operation.) However, if the requested operation has not been
performed, it is performed and the completion status is returned to the backup process.
The action taken by the server is invisible to the backup process.
The server can save the completion status and reply data of the latest operations
against a file and relate those completions to operations requested by a backup
process upon takeover from a failed primary process. The maximum number of
completion statuses that the system is to save is specified in the sync-depth
parameter in the __ns_fopen_special function call. The sync-depth value is
typically equal to the number of write operations to a file without an intervening save of
the file’s sync block. In most cases, the sync-depth value is 1; that is, the sync block
state should be updated after each WRITE. The sync-depth value cannot exceed
15.
If the primary process fails, the backup process is notified by the operating system.
The sync information received in the most recent state update message synchronizes
the retry operations that the backup process is about to perform with any writes that
the primary was able to complete before it failed. The backup process then retries
each write in the series (in the same order as the primary process). If any operation
was completed successfully by the primary process, the server does not perform the
operation; instead, it just returns the completion status and data to the backup process.