• Antelope Release 5.10 Linux CentOS release 7.6.1810 (Core) 3.10.0 2020-05-12

 

NAME

map_waitfile, remap_waitfile - file used to signal programs writing to a database

SYNOPSIS

int *map_waitfile (Dbptr db, char **fp, int quiet)

int *remap_waitfile (Dbptr db, int *lock, char **fp)

DESCRIPTION

map_waitfile creates (if necessary) and maps into memory a file named db.MSGFILE. This file is used by orb2db_msg(1) and programs like orb2db(1) and orb2wf(1). orb2db_msg is used by rtdbclean(1) to signal that a database is about to be modified wholesale, probably removing old records from the wfdisc table. Actually, only the first 8 bytes of the file are used. The first 4 bytes are a flag to signal that a cleanup is in progress; the second 4 bytes are an integer count, so that a process can detect a cleanup which happened while it was suspended and close and reopen the database.

The interaction between orb2db_msg and the program writing to the database should be the following:

If the

FILES

The file created by map_waitfile (if it doesn't already exist) is database_name.MSGFILE.

EXAMPLE


int
check_for_pause (int pktid, Save_params *params)
{
    char *s, *t ;
    int lost_waitfile = 0 ;
    static int last_count = 0 ;
    static int *lock=0 ;
    static char *waitfile ;
    int retcode = 0 ;

    if ( lock == 0 ) {
        lock = map_waitfile ( Params.db, &waitfile, 0 ) ;
        if ( lock == 0 ) {
            elog_die (0, "failed to open waitfile" ) ;
        }
        last_count = lock[1] ;
    }
    if ( *lock || last_count != lock[1]) {
        struct stat statbuf ;
        dbclose ( params->db ) ;
        restat ( waitfile, &statbuf ) ;
        elog_notify ( 0, "paused at pktid #%ld after %s, waiting for continue\n",
                     pktid, s=strtdelta(now() - statbuf.st_mtime) ) ;
        free(s) ;
        while ( *lock ) {
            if ( restat ( waitfile, &statbuf ) ) {
                complain ( 1, "waitfile %s disappeared!\n", waitfile ) ;
                lost_waitfile = 1 ;
                break ;
            }
            if ( now() - statbuf.st_mtime > params->pause_timeout ) {
                complain ( 1, "waitfile is %s old > %s -- clearing pause and continuing\n",
                     s=strtdelta(now() - statbuf.st_mtime),
                     t=strtdelta((double) params->pause_timeout) ) ;
                free(s) ;
                free(t) ;
                *lock = 0 ;
                break;
            }
            snooze(1.0) ;
        }
        last_count = lock[1] ;
        elog_notify ( 0, "continuing after pause\n" ) ;
        if (lost_waitfile) {
            lock = remap_waitfile ( params->db, lock, &waitfile ) ;
            if ( lock == 0 ) {
                elog_die (0, "failed to re-open waitfile" ) ;
            } else {
                lost_waitfile = 0 ;
            }
        }
        retcode = 1 ;
    }
    return retcode ;
}

RETURN VALUES

map_waitfile returns a pointer to the memory mapped file, and a pointer to the name of the file.

remap_waitfile is given the original pointer to the memory mapped file, and returns a pointer to the new memory mapped file.

If either map_waitfile or remap_waitfile returns zero, some error has occurred and a message is left on the elog(3) error log.

LIBRARY

$(DBLIBS)

ATTRIBUTES

MT-Safe

SEE ALSO

orb2db_msg(1)
orb2db(1)

AUTHOR

Daniel Quinlan
Printer icon