IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33206


Ignore:
Timestamp:
Feb 6, 2012, 9:13:29 PM (14 years ago)
Author:
eugene
Message:

adding open license md5 implementation; working on dvodist

Location:
branches/eam_branches/ipp-20111122/Ohana/src/photdbc
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/AssignSkyToHost.c

    r33204 r33206  
    1616    // assign or re-assign? if a region is already assigned, do we keep it?
    1717
    18     // XXX for the moment, do not reassign tables
    19     // XXX we may want to run this program multiple times
     18    // XXX some options;
     19# if (0)
     20    if (CLEAR_ERRORS && (skylist->regions[i]->hostID & DATA_COPY_FAILURE)) {
     21      skylist->regions[i]->hostID = 0;
     22    }
     23# endif
     24
     25    // do not reassign tables; this lets us run this program multiple times for different regions
     26    // tables already assigned are left where they are
    2027    if (skylist->regions[i]->hostID) {
    2128      continue;
    2229    }
     30
     31
    2332
    2433    // assign all regions to one of the Nhost hosts
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c

    r33205 r33206  
    1 # include <openssl/md5.h>
    2 # include <unistd.h>
    31# include "photdbc.h"
     2# include <md5.h>
     3# include <unistd.h> // needed?
     4
    45# define DEBUG 1
     6# define NBUFFER 512
     7# define NDIGEST  16
     8
     9# define DATA_ON_TGT       0x4000
     10# define DATA_COPY_FAILURE 0x8000
     11# define DATA_HOST_ID      0x3fff
    512
    613int CostToHostLocation (SkyList *skylist, HostTable *table) {
    714
    815  int i;
    9   uid_t uid;
    10   gid_t gid;
    1116  struct stat filestat;
    1217  char srcname[1024];
    1318  char tgtname[1024];
    1419   
    15   uid = getuid();
    16   gid = getgid();
     20  uid_t uid = getuid();
     21  gid_t gid = getgid();
    1722
     23  int Nfailure = 0;
    1824  for (i = 0; i < skylist->Nregions; i++) {
     25    if (VERBOSE) fprintf (stderr, "%s\n", skylist[0].regions[i][0].name);
    1926   
    2027    // move each table from CATDIR/name to table->hosts[].pathname/name
    21 
    22     // XXX assign or re-assign? if a region is already assigned, do we keep it?
    2328
    2429    // skip unassigned tables
    2530    if (!skylist->regions[i]->hostID) continue;
    2631
     32    // skip catalogs which have already been copied
     33    if (skylist->regions[i]->hostID & DATA_ON_TGT) continue;
     34
     35    // skip catalogs which have an uncleared error
     36    if (skylist->regions[i]->hostID & DATA_COPY_FAILURE) continue;
     37
    2738    // find the host for the table
    28     short index = table->index[skylist->regions[i]->hostID];
     39    int realID = (skylist->regions[i]->hostID & DATA_HOST_ID)
     40    short index = table->index[realID];
    2941    HostInfo *host = &table->hosts[index];
    3042
     43    // have to succeed on all 4 tables; if we fail on any one,
     44    int success = TRUE;
     45
    3146    char extname[4][16] = {"cpm", "cpt", "cps", "cpn"};
    32     for (j = 0; j < 4; j++) {
     47    for (j = 0; success && (j < 4); j++) {
    3348
    34         // set the in and out table names
    35         sprintf (srcname, "%s/%s.%s", CATDIR, skylist->regions[i]->name, extname);
    36         sprintf (tgtname, "%s/%s.%s", host->pathname, skylist->regions[i]->name, extname);
     49      // set the in and out table names
     50      sprintf (srcname, "%s/%s.%s", CATDIR, skylist->regions[i]->name, extname[j]);
     51      sprintf (tgtname, "%s/%s.%s", host->pathname, skylist->regions[i]->name, extname[j]);
    3752
    38         // does srcname exist & can it be read?
     53      // does srcname exist & can it be read?
    3954
    40         // check permission to read file
    41         int status = stat (srcname, &filestat);
    42         if (!status) continue;  // file does not exist (check error stats for other issues?)
     55      // check permission to read file
     56      int status = stat (srcname, &filestat);
     57      if (!status) {
     58        if (errno == ENOEND) continue;  // file does not exist (handle broken table with cpt + cpm but no cpn,cps?)
     59        perror ("stat:");
     60        fprintf (stderr, "failure to access file %s\n", srcname);
     61        success = FALSE;
     62        continue;
     63      }
    4364   
    44         // can we read the file
    45         if (uid == filestat.st_uid) {
    46             if (filestat.st_mode & S_IRUSR) goto valid;
    47         }
    48         if (gid == filestat.st_gid) {
    49             if (filestat.st_mode & S_IRGRP) goto valid;
    50         }
    51         if (filestat.st_mode & S_IROTH) goto valid;
     65      // can we read the file?
     66      if (uid == filestat.st_uid) {
     67        if (filestat.st_mode & S_IRUSR) goto valid;
     68      }
     69      if (gid == filestat.st_gid) {
     70        if (filestat.st_mode & S_IRGRP) goto valid;
     71      }
     72      if (filestat.st_mode & S_IROTH) goto valid;
    5273   
    53         fprintf (stderr, "cannot read file %s, skipping\n", srcname);
    54         continue;
     74      fprintf (stderr, "cannot read file %s, skipping\n", srcname);
     75      success = FALSE;
     76      continue;
    5577
    5678    valid:
    57         // XXX since we have to open and read the whole file anyway,
    58         // XXX perhaps we should just write the output file?
     79      // XXX since we have to open and read the whole file anyway,
     80      // XXX perhaps we should just write the output file?
    5981       
    60         // read srcname, write to tgtname, get MD5 sum for srcname as we go:
     82      // read srcname, write to tgtname, get MD5 sum for srcname as we go:
     83      md5_byte_t srcDigest[NDIGEST];
     84      get_md5_with_copy (srcname, tgtname, srcDigest);
    6185       
    62         // open the src file
    63         FILE *fInput = fopen (srcname, "r");
    64         int fdInput = fileno (fInput);
    65        
    66         // open the tgt file
    67         FILE *fOutput = fopen (tgtname, "w");
    68         int fdOutput = fileno (fOutput);
     86      // need to re-open and re-read tgtname to check md5sum
     87      get_md5_with_copy (tgtname, NULL, tgtDigest);
    6988
    70         int n;
    71         MD5_CTX c;
    72         char buf[512];
    73         ssize_t nbytes;
     89      // compare the two digest values
     90      int match = true;
     91      for (k = 0; match && (k < NDIGEST); k++) {
     92        match &= (tgtDigest[k] == srcDigest[k]);
     93      }
    7494
    75         MD5_Init(&c);
    76         while ((nbytes = read (fd, buf, 512)) > 0) {
    77             MD5_Update(&c, buf, nbytes);
    78             nbytes = write (fd, buf, 512);
     95      if (!match) {
     96        if (DEBUG) {
     97          fprintf (stderr, "failed to copy %s to %s\n", srcname, tgtname);
    7998        }
    80         MD5_Final(out, &c);
     99        success = FALSE;
     100      }
     101    }   
    81102
    82         for (n = 0; n < MD5_DIGEST_LENGTH; n++) {
    83             fprintf (stderr, "%02x", out[n]);
    84         }
    85         fclose (f);
    86         flush (f);
     103    if (!success) {
     104      // let's use the upper 2 bits of the hostID for informational purposes. this
     105      // leaves us with up to 16383 hosts.
    87106
    88     // need to re-open and re-read tgtname to check md5sum
    89 
    90 }
    91    
    92 
    93 
    94     // assign all regions to one of the Nhost hosts
    95     int N = MAX(table->Nhosts - 1, table->Nhosts * drand48());
    96     skylist->regions[i]->hostID = table->hosts[N].hostID;
    97   }   
     107      // data on src  = (hostID & 0x8000) >> 15
     108      // copy failed  = (hostID & 0x4000) >> 14
     109      // if we failed to make a copy,
     110         
     111      skylist->regions[i]->hostID |= DATA_COPY_FAILURE;
     112      for (j = 0; success && (j < 4); j++) {
     113        sprintf (tgtname, "%s/%s.%s", host->pathname, skylist->regions[i]->name, extname[j]);
     114        if (!DEBUG) unlink (tgtname);
     115      }
     116      Nfailure ++;
     117    } else {
     118      skylist->regions[i]->hostID |= DATA_ON_TGT;
     119      for (j = 0; success && (j < 4); j++) {
     120        sprintf (srcname, "%s/%s.%s", CATDIR, skylist->regions[i]->name, extname[j]);
     121        if (!DEBUG && DELETE_ORIGINAL) unlink (srcname);
     122      }
     123    }
     124  }
     125 
     126  if (!Nfailure) {
     127    fprintf (stderr, "all tables successfully moved\n");
     128  } else {
     129    fprintf (stderr, "%d tables were not moved\n", Nfailure);
     130  }
    98131
    99132  return (TRUE);
    100133}
     134
     135/* state table for copy to/from location
     136
     137   data on src (local catdir)  : 00.hostID
     138   data on tgt (remote catdir) : 10.hostID
     139   failure to copy to tgt      : 01.hostID
     140   failure to copy to src      : 11.hostID
     141*/
     142
     143// read a file, get the md5 sum, optionally write to 'output'
     144int get_md5_with_copy (char *input, char *output, md5_byte_t *digest) {
     145
     146  // open the src file
     147  FILE *fInput = fopen (input, "r");
     148  int fdInput = fileno (fInput);
     149       
     150  // open the tgt file
     151  FILE *fOutput = NULL;
     152  int fdOutput = 0;
     153  if (output) {
     154    fOutput = fopen (tgtname, "w");
     155    fdOutput = fileno (fOutput);
     156  }
     157
     158  int nbytes;
     159  md5_state_t state;
     160  md5_byte_t buffer[NBUFFER];
     161
     162  md5_init (&state);
     163  while ((nbytes = read (fdInput, buffer, NBUFFER)) > 0) {
     164    md5_append (&state, buffer, nbytes);
     165    if (output) {
     166      nbytes = write (fdOutput, buffer, NBUFFER);
     167      // XXX check that we actually write out all nbytes...
     168    }
     169  }
     170  md5_finish(&state, digest);
     171       
     172  fclose (fInput);
     173  flush (fInput);
     174
     175  if (output) {
     176    fclose (fOutput);
     177    flush (fOutput);
     178  }
     179  return TRUE;
     180}
     181
     182/* need to think a bit about behavior in the context of SPLIT vs MEF:
     183
     184 * SPLIT : all 4 tables either exist or none do
     185 * MEF only cpt table exists
     186
     187 * read the SPLIT headers to see if MEASURE, MISSING, SECFILT fields exist?
     188 */
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/dvodist.c

    r33203 r33206  
    44
    55  int i;
    6   char *skyfile;
    7   Catalog incatalog;
    8   Catalog outcatalog;
    96  SkyTable *sky;
    107  SkyList *skylist;
    118
    129  /* get configuration info, args, lockfile */
    13   initialize (argc, argv);
     10  initialize_dvodist (argc, argv);
    1411
    1512  // dvodist (-out | -in)
     
    2522  AssignSkyToHost (skylist, hosts);
    2623
    27   CopyToHostLocation ();
     24  CopyToHostLocation (skylist, hosts);
    2825
    29   SkyTableSave (sky, skyfile);
     26  char *skyfile;
     27  ALLOCATE (skyfile, char, strlen(catdir) + strlen("/SkyTable.fits") + 1);
     28  sprintf (skyfile, "%s/SkyTable.fits", catdir);
     29  SkyTableSave (sky, filename);
    3030
    31 }
    32 
    33 void stuff () {
    34 
    35   for (i = 0; i < skylist[0].Nregions; i++) {
    36     if (VERBOSE) fprintf (stderr, "%s\n", skylist[0].regions[i][0].name);
    37 
    38     // set the parameters which guide catalog open/load/create
    39     incatalog.filename = skylist[0].filename[i];
    40     incatalog.Nsecfilt = GetPhotcodeNsecfilt ();
    41     incatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
    42 
    43     // an error exit status here is a significant error
    44     if (!dvo_catalog_open (&incatalog, skylist[0].regions[i], VERBOSE, "r")) {
    45       fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", incatalog.filename);
    46       exit (2);
    47     }
    48     // skip empty input catalogs
    49     if (!incatalog.Naves_disk) {
    50       dvo_catalog_unlock (&incatalog);
    51       dvo_catalog_free (&incatalog);
    52       continue;
    53     }
    54 
    55     // create output catalog filename
    56     outcatalog.filename = strsubs (incatalog.filename, CATDIR, argv[1]);
    57     if (outcatalog.filename == NULL) Shutdown ("error with input catalog name");
    58 
    59     // define outcatalog open parameters
    60     outcatalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    61     outcatalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    62     outcatalog.Nsecfilt  = incatalog.Nsecfilt;                 // inherit from the incatalog
    63     outcatalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    64 
    65     // output catalogs always represent the same skyregions as the input catalogs
    66     if (!dvo_catalog_open (&outcatalog, skylist[0].regions[i], VERBOSE, "w")) {
    67       fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", outcatalog.filename);
    68       exit (2);
    69     }
    70 
    71     // the output catalog needs to have the same values for 'objID' and 'sorted' as the input
    72     outcatalog.objID = incatalog.objID;
    73     outcatalog.sorted = incatalog.sorted;
    74     if (!incatalog.sorted) {
    75       fprintf (stderr, "ERROR: input db must be sorted: %s\n", incatalog.filename);
    76       exit (2);
    77     }
    78 
    79     /* limit number of measures based on selections */
    80     make_subcatalog (&outcatalog, &incatalog, skylist[0].regions[i]);
    81        
    82     // XXX add other filters here:
    83     // join_stars (&outcatalog);
    84     // unique_measures (catalog);
    85     // flag_measures (&db, catalog);
    86     // get_mags (catalog);
    87 
    88     dvo_catalog_save (&outcatalog, VERBOSE);
    89     dvo_catalog_unlock (&outcatalog);
    90     dvo_catalog_free (&outcatalog);
    91 
    92     dvo_catalog_unlock (&incatalog);
    93     dvo_catalog_free (&incatalog);
    94   }
    95 
    96   ALLOCATE (skyfile, char, strlen(argv[1]) + strlen("/SkyTable.fits") + 1);
    97   sprintf (skyfile, "%s/SkyTable.fits", argv[1]);
    98   SkyTableSave (sky, skyfile);
    9931  exit (0);
    10032}
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/initialize.c

    r30616 r33206  
    8383  }
    8484}
    85 
Note: See TracChangeset for help on using the changeset viewer.