IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 16, 2012, 4:20:32 PM (14 years ago)
Author:
eugene
Message:

add failsafes to dvomerge (write size & date/time of input catalog into output and do not merge if it already exists; make backup files (move target to new name) and delete backups only on success

Location:
branches/eam_branches/ipp-20120405/Ohana/src/dvomerge
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120405/Ohana/src/dvomerge/include/dvomerge.h

    r33834 r33875  
    1717# include <glob.h>
    1818
    19 # define MAX_PATH_LENGTH 1024
     19# define DVO_MAX_PATH 1024
    2020
    2121int    PARALLEL;
  • branches/eam_branches/ipp-20120405/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r33834 r33875  
    3636      found = (found || HostTableTestHost(outlist[0].regions[j], HOST_ID));
    3737    }
     38
    3839    // skip this input table for if no output files are on this machine
    3940    if (!found) {
     
    4243    }
    4344
    44     // load / create output catalog (if catalog does not exist, it will be created)
     45    // get the stats on this input file (for comparison with the output headers)
     46    struct stat instats;
     47    int stat_result = stat (inlist[0].filename[i], &instats);
     48    if (stat_result) {
     49      if (errno == ENOENT) continue;
     50      fprintf (stderr, "cannot read stats on input file %s\n", inlist[0].filename[i]);
     51      perror ("stats error message:");
     52      exit (2);
     53    }
     54
     55    // instats.st_size & instats.st_mtime
     56
     57    // check if any of the output files have NOT yet received data from this input file
     58
     59    int missed = FALSE;
     60    for (j = 0; !missed && (j < outlist[0].Nregions); j++) {
     61      if (!HostTableTestHost(outlist[0].regions[j], HOST_ID)) continue;
     62
     63      // set the parameters which guide catalog open/load/create
     64      char hostfile[DVO_MAX_PATH];
     65      snprintf (hostfile, DVO_MAX_PATH, "%s/%s.cpt", HOSTDIR, outlist[0].regions[j]->name);
     66      char *filename = HOST_ID ? hostfile : outlist[0].filename[j];
     67
     68      // get the stats on this input file (for comparison with the output headers)
     69      struct stat outstats;
     70      stat_result = stat (filename, &outstats);
     71      if (stat_result) {
     72        if (errno == ENOENT) {
     73          missed = TRUE;
     74          break;
     75        }
     76        fprintf (stderr, "cannot read stats on output file %s\n", filename);
     77        perror ("stats error message:");
     78        exit (2);
     79      }
     80
     81      FILE *fout = fopen (filename, "r");
     82      if (!fout) {
     83        fprintf (stderr, "problem opening output file to read header %s\n", filename);
     84        perror ("stats error message:");
     85        exit (2);
     86      }
     87
     88      Header outheader;
     89      if (!gfits_fread_header (fout, &outheader)) {
     90        fprintf (stderr, "problem reading header for output file %s\n", filename);
     91        exit (2);
     92      }
     93     
     94      // update header of output catalog
     95      long long last_size;
     96      char last_moddate[80];
     97      gfits_scan (&outheader, "LMRG_SZ", "%lld", 1, &last_size);     
     98      gfits_scan (&outheader, "LMRG_DT", "%s", 1, last_moddate);     
     99
     100      time_t last_mod = ohana_date_to_sec (last_moddate);
     101
     102      if (last_size != instats.st_size) {
     103        missed = TRUE;
     104        break;
     105      }
     106     
     107      if (last_mod != instats.st_mtime) {
     108        missed = TRUE;
     109        break;
     110      }
     111    }
     112    if (!missed) {
     113      fprintf (stderr, "skipping %s, already merged\n", inlist[0].filename[i]);
     114      continue;
     115    }
     116
     117    // read the input catalog
    45118    LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r", NsecfiltInput);
     119
    46120    // skip empty input catalogs
    47121    if (!incatalog.Naves_disk) {
     
    52126    }
    53127
     128    char *moddate = ohana_sec_to_date (instats.st_mtime);
     129
    54130    // merge input into the appropriate output tables
    55131    for (j = 0; j < outlist[0].Nregions; j++) {
     
    60136
    61137      // set the parameters which guide catalog open/load/create
    62       char hostfile[MAX_PATH_LENGTH];
    63       snprintf (hostfile, MAX_PATH_LENGTH, "%s/%s.cpt", HOSTDIR, outlist[0].regions[j]->name);
     138      char hostfile[DVO_MAX_PATH];
     139      snprintf (hostfile, DVO_MAX_PATH, "%s/%s.cpt", HOSTDIR, outlist[0].regions[j]->name);
    64140      outcatalog.filename  = HOST_ID ? hostfile : outlist[0].filename[j];
    65141
     
    71147
    72148      outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     149
     150      // update header of output catalog
     151      gfits_modify (&outcatalog.header, "LMRG_SZ", "%lld", 1, (long long) instats.st_size);     
     152      gfits_modify (&outcatalog.header, "LMRG_DT", "%s", 1, moddate);     
     153
     154      if (!dvo_catalog_backup (&outcatalog, TRUE)) {
     155        fprintf (stderr, "ERROR: failed to make backup for catalog %s\n", outlist[0].filename[j]);
     156        exit (1);
     157      }
    73158
    74159      // if we receive a signal which would cause us to exit, wait until the full catalog is written
     
    80165      SetProtect (FALSE);
    81166
     167      if (!dvo_catalog_unlink_backup (&outcatalog, TRUE)) {
     168        fprintf (stderr, "WARNING: failed to remove backup for catalog %s\n", outlist[0].filename[j]);
     169      }
     170
    82171      dvo_catalog_unlock (&outcatalog);
    83172      dvo_catalog_free (&outcatalog);
     
    86175    }
    87176    SkyListFree (outlist);
     177    free (moddate);
    88178
    89179    dvo_catalog_unlock (&incatalog);
     
    108198
    109199    // ensure that the paths are absolute path names
    110     char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH);
     200    char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
    111201    free (table->hosts[i].pathname);
    112202    table->hosts[i].pathname = tmppath;
    113203
    114204    // ensure that the paths are absolute path names
    115     char *absinput  = abspath (input,  MAX_PATH_LENGTH);
    116     char *absoutput = abspath (output, MAX_PATH_LENGTH);
     205    char *absinput  = abspath (input,  DVO_MAX_PATH);
     206    char *absoutput = abspath (output, DVO_MAX_PATH);
    117207
    118208    // options / arguments that can affect relastro_client -update-objects:
    119     char command[MAX_PATH_LENGTH];
    120     snprintf (command, MAX_PATH_LENGTH, "dvomerge_client %s into %s -hostID %d -hostdir %s -region %f %f %f %f -D ADDSTAR_RADIUS %f",
     209    char command[DVO_MAX_PATH];
     210    snprintf (command, DVO_MAX_PATH, "dvomerge_client %s into %s -hostID %d -hostdir %s -region %f %f %f %f -D ADDSTAR_RADIUS %f",
    121211              absinput, absoutput, table->hosts[i].hostID, table->hosts[i].pathname,
    122212              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, RADIUS
    123213      );
    124214
    125     char tmpline[MAX_PATH_LENGTH];
    126     if (VERBOSE)            { snprintf (tmpline, MAX_PATH_LENGTH, "%s -v",                command);            strcpy (command, tmpline); }
     215    char tmpline[DVO_MAX_PATH];
     216    if (VERBOSE)            { snprintf (tmpline, DVO_MAX_PATH, "%s -v",                command);            strcpy (command, tmpline); }
    127217
    128218    // XXX these do not make sense for dvomerge client, where the output is required to exist
    129     // if (CATFORMAT)          { snprintf (tmpline, MAX_PATH_LENGTH, "%s -D CATFORMAT %s",   command, CATFORMAT); strcpy (command, tmpline); }
    130     // if (CATMODE)            { snprintf (tmpline, MAX_PATH_LENGTH, "%s -D CATMODE %s",     command, CATMODE);   strcpy (command, tmpline); }
    131     // if (SKY_DEPTH)          { snprintf (tmpline, MAX_PATH_LENGTH, "%s -D SKY_DEPTH %d",   command, SKY_DEPTH); strcpy (command, tmpline); }
     219    // if (CATFORMAT)          { snprintf (tmpline, DVO_MAX_PATH, "%s -D CATFORMAT %s",   command, CATFORMAT); strcpy (command, tmpline); }
     220    // if (CATMODE)            { snprintf (tmpline, DVO_MAX_PATH, "%s -D CATMODE %s",     command, CATMODE);   strcpy (command, tmpline); }
     221    // if (SKY_DEPTH)          { snprintf (tmpline, DVO_MAX_PATH, "%s -D SKY_DEPTH %d",   command, SKY_DEPTH); strcpy (command, tmpline); }
    132222
    133223    fprintf (stderr, "command: %s\n", command);
Note: See TracChangeset for help on using the changeset viewer.