IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16872


Ignore:
Timestamp:
Mar 7, 2008, 12:06:52 PM (18 years ago)
Author:
bills
Message:

better error handling, simplified the tables slightly

Location:
trunk/DataStoreServer/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStoreServer/scripts/dsreg

    r16867 r16872  
    161161
    162162    if (!$fs_row) {
    163         print "Fileset '$fileset' not found under $product.\n";
     163        print STDERR "Fileset '$fileset' not found under $product.\n";
    164164        exit 1;
    165165    }
     
    201201    #
    202202
    203     # make a string out of the product specifc column values provided
    204     my $prodcolstr = make_prodcol_str($ps0, $ps1, $ps2, $ps3, $ps4, $ps5, $ps6, $ps7);
    205203
    206204    my $stmt = $dbh->prepare("SELECT prod_id FROM dsProduct WHERE prod_name = \'$product\'");
     
    220218    }
    221219
     220    # Note: There is a race condition here. Somebody could sneak in now and add a fileset with
     221    # fileset_name = $fileset. So later we'll check again that only one fileset with the name exists
     222
    222223    # Read file data from STDIN
     224    # XXX: Perhaps allow this to come from a file
    223225
    224226    my $lineno = 0;
     
    318320    # create the cgi script index.txt by making a copy of its parent's
    319321    if (!copy("$ds_dir/$product/index.txt", $index_script_name)) {
     322        cleanup();
    320323        die("failed to copy index script to file set");
    321324    }
     
    326329        $dbh->{AutoCommit} = 0;
    327330
     331        # note the resulting prodcolstr begins with a comma
     332        my $prodcolstr = make_prodcol_str($ps0, $ps1, $ps2, $ps3, $ps4, $ps5, $ps6, $ps7);
     333
    328334        my $qstring = "INSERT into dsFileset" .
    329335                " (prod_id, fileset_name, reg_time, type," .
    330336                " prod_col_0, prod_col_1, prod_col_2, prod_col_3, prod_col_4, prod_col_5, " .
    331337                " prod_col_6, prod_col_7)" .
    332                 # note prodcolstr begins with a comma
    333338                " VALUES($prod_id, \'$fileset\', UTC_TIMESTAMP(), \'$fstype\' $prodcolstr)";
     339
    334340        $count = $dbh->do($qstring);
    335341        if ($count == 0E0) {
     
    339345        my $fileset_id = $dbh->last_insert_id(undef, undef, undef, undef);
    340346
    341         # print STDERR "Inserted fileset_id $fileset_id\n";
     347        # make sure that no-one got in and created a fileset with this name while we were busy
     348        $count = $dbh->do("SELECT fileset_id FROM dsFileset WHERE fileset_name = '$fileset'" .
     349                        " AND prod_id = $prod_id");
     350        if ($count > 1) {
     351            die("Fileset '$fileset' already exists under $product.");
     352        }
    342353
    343354        foreach my $ref (@files) {
     
    371382        print STDERR "transactionfailed, rolling back error was:\n$@\n";
    372383        eval {$dbh->rollback();};
    373         unlink($index_script_name);
     384        cleanup();
    374385        exit 1;
    375386    }
    376 
    377     # print "Added $fileset to $product.\n";
    378387
    379388    exit 0;
     
    431440    return $string;
    432441}
     442
     443sub cleanup {
     444
     445    if ($linkfiles or $copyfiles) {
     446        if (system "rm -r $fileset_dir") {
     447            print STDERR "failed to remove $fileset_dir";
     448        }
     449    } else {
     450        unlink($index_script_name);
     451    }
     452}
  • trunk/DataStoreServer/scripts/tabledefs.sql

    r16762 r16872  
    55
    66#
    7 # TODO: arguably we should put prod_col_n in another table, but since the
    8 # number of products will be small, it is simpler to just keep them here
    9 #
     7#
    108
    119CREATE TABLE dsProduct (
     
    1614    type        VARCHAR(64),
    1715    description VARCHAR(255),
    18     path_name   VARCHAR(255),
    19     prod_col_0  VARCHAR(64),        # names of product specific columns
    20     prod_col_1  VARCHAR(64),        # shows up in the header list
     16    prod_col_0  VARCHAR(64),        # labels for product specific columns
     17    prod_col_1  VARCHAR(64),        # these appear in the header list
    2118    prod_col_2  VARCHAR(64),
    2219    prod_col_3  VARCHAR(64),
     
    3128    prod_id     BIGINT(20),
    3229    fileset_id  BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    33     fileset_name VARCHAR(64) NOT NULL UNIQUE,
     30    fileset_name VARCHAR(64) NOT NULL,
    3431    reg_time    datetime NOT NULL,
    3532    type        VARCHAR(64),
     
    6562
    6663#
    67 # names of the type specific columns for a data store file type
    68 #
    69 # if not null, the cols will show up in the indexes
     64# labels for the type specific columns for each Data Store file type
    7065#
    7166
     
    7873) Engine=InnoDB DEFAULT CHARSET=latin1;
    7974
    80 # type specific columns for type chip
     75# type specific column for type chip
    8176INSERT INTO dsFileType (type, type_col_0) VALUES('chip', 'chipname');
     77
     78# none of these types have any type specific columns
    8279INSERT INTO dsFileType (type) VALUES('psrequest');
    8380INSERT INTO dsFileType (type) VALUES('psresults');
    8481INSERT INTO dsFileType (type) VALUES('pstamp');
    85 
    86 INSERT INTO dsProduct (prod_id, prod_name, last_update, last_fs, type, description, path_name)
    87         VALUES (0, 'pstamprequest', UTC_TIMESTAMP(), NULL, 'psrequest', 'Postage Stamp Request',
    88         '/var/www/html/ds/dsroot');
    89 
    90 INSERT INTO dsProduct (prod_id, prod_name, last_update, last_fs, type, description, path_name)
    91         VALUES (0, 'sample', UTC_TIMESTAMP(), NULL, 'psresult', 'Postage Stamp Request', '/var/www/html/ds/dsroot');
    92 
    93 #
    94 # the width of the product specific column header strings should match the usual width of the columns
    95 # to make the fileset lists look neat (note 'telescope pointing')
    96 #
    97 
    98 INSERT INTO dsProduct VALUES (0, 'gpc1', UTC_TIMESTAMP(), NULL, 'image',
    99         'Gigapixel Camera 1', '/var/www/html/ds/dsroot', 'telescope pointing        ', 'etime', 'f',
    100         'airm', 'comments', NULL, NULL, NULL);
    101 
    102 INSERT INTO dsFileset VALUES(1, 0, 'fileset1', UTC_TIMESTAMP(), 'PSTAMP');
    103 INSERT INTO dsFileset VALUES(1, 0, 'fileset2', UTC_TIMESTAMP(), 'PSTAMP');
    104 INSERT INTO dsFileset VALUES(1, 0, 'fileset13', UTC_TIMESTAMP(), 'PSTAMP');
    105 
    106 INSERT INTO dsFile VALUES(LAST_INSERT_ID(), 0, 'fileset13.fits', 8640, 'b8217dcb393de3af02d915d77025021d',
    107     'psrequest');
    108 
    109    
    110 
    111 
    112 
Note: See TracChangeset for help on using the changeset viewer.