IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20173


Ignore:
Timestamp:
Oct 15, 2008, 10:16:29 AM (18 years ago)
Author:
jhoblitt
Message:

refactor copydoneCompleteExp()
change -copydone to use a row lock in pzDownloadExp instead of pzDownloadImfile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/pztool.c

    r20172 r20173  
    4646static bool advanceMode(pxConfig *config);
    4747
    48 static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, bool rowLock);
     48static bool copydoneCompleteExp(pxConfig *config);
    4949static psArray *pzGetPendingCameras(pxConfig *config);
    5050static psArray *pzArrayZip(psArray *arraySet, psS64 limit);
     
    404404    // NOTE : the rest of the command-line args are parsed in copydoneCompleteExp
    405405
     406    // start a transaction early so it will contain any row level locks
     407    if (!psDBTransaction(config->dbh)) {
     408        psError(PS_ERR_UNKNOWN, false, "database error");
     409        return false;
     410    }
     411   
     412    // query to get an excluse lock on this exposure in
     413    // pzDownloadExp
     414    psString lock_query = NULL;
     415    if (row_lock) {
     416        lock_query = psStringCopy("SELECT * FROM pzDownloadExp");
     417
     418        psMetadata *where = psMetadataAlloc();
     419        PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
     420        PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
     421        PXOPT_COPY_STR(config->args, where,  "-telescope", "telescope", "==");
     422       
     423        if (psListLength(where->list)) {
     424            psString whereClause = psDBGenerateWhereSQL(where, NULL);
     425            psStringAppend(&lock_query, " %s FOR UPDATE", whereClause);
     426            psFree(whereClause);
     427        }
     428        psFree(where);
     429
     430        // aquire a lock on the pzDownloadExp record
     431        // lock persists until the transaction is committed
     432        if (!p_psDBRunQuery(config->dbh, lock_query)) {
     433            psError(PS_ERR_UNKNOWN, false, "database error");
     434            psFree(lock_query);
     435            return false;
     436        }
     437        psFree(lock_query);
     438    }
     439
    406440    if (!pzDownloadImfileInsert(config->dbh,
    407441            exp_name,
     
    418452    }
    419453
    420     // start a transaction so it's all rows or nothing
    421     if (!psDBTransaction(config->dbh)) {
    422         psError(PS_ERR_UNKNOWN, false, "database error");
    423         return false;
    424     }
    425 
    426     if (!copydoneCompleteExp(config, exp_name, camera, telescope, row_lock)) {
     454    if (!copydoneCompleteExp(config)) {
    427455        // rollback
    428456        if (!psDBRollback(config->dbh)) {
     
    446474}
    447475
    448 static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, bool row_lock)
     476static bool copydoneCompleteExp(pxConfig *config)
    449477{
    450478    // THIS FUNCTION MUST BE INVOKED FROM INSIDE A TRANSACTION!!!
     
    464492    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    465493
    466 
    467494    // find all exposures that have had all of their imfiles downloaded but do
    468495    // not appear in newExp
     
    473500    }
    474501
    475     // XXX this is a bit ugly : could just use the PXOPT_COPY_* methods
    476     // and not pass exp_name, camera, or telescope as additional args
    477502    psMetadata *where = psMetadataAlloc();
    478     if (exp_name) {
    479         if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_name", 0, "==", exp_name)) {
    480             psError(PS_ERR_UNKNOWN, false, "failed to add item exp_name");
    481             psFree(where);
    482             return false;
    483         }
    484     }
    485 
    486     if (camera) {
    487         if (!psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, "==", camera)) {
    488             psError(PS_ERR_UNKNOWN, false, "failed to add item camera");
    489             psFree(where);
    490             return false;
    491         }
    492     }
    493 
    494     if (telescope) {
    495         if (!psMetadataAddStr(where, PS_LIST_TAIL, "telescope", 0, "==", telescope)) {
    496             psError(PS_ERR_UNKNOWN, false, "failed to add item telescope");
    497             psFree(where);
    498             return false;
    499         }
    500     }
    501 
    502     // query to get an excluse lock on all rows for this exposure in
    503     // pzDownloadImfile
    504     psString lock_query = NULL;
    505     if (row_lock) {
    506         lock_query = psStringCopy("SELECT * FROM pzDownloadImfile");
    507     }
     503    PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
     504    PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
     505    PXOPT_COPY_STR(config->args, where,  "-telescope", "telescope", "==");
    508506
    509507    if (psListLength(where->list)) {
    510508        psString whereClause = psDBGenerateWhereSQL(where, NULL);
    511509        psStringAppend(&query, " %s", whereClause);
    512         if (row_lock) {
    513             psStringAppend(&lock_query, " %s FOR UPDATE", whereClause);
    514         }
    515510        psFree(whereClause);
    516511    }
    517512    psFree(where);
    518 
    519     // aquire lock on pzDownloadImfile rows
    520     // lock persists until a transaction is committed
    521     if (row_lock) {
    522         if (!p_psDBRunQuery(config->dbh, lock_query)) {
    523             psError(PS_ERR_UNKNOWN, false, "database error");
    524             psFree(lock_query);
    525             psFree(query);
    526             return false;
    527         }
    528         psFree(lock_query);
    529     }
    530513
    531514    // find completed exps
     
    880863    }
    881864
    882     if (!copydoneCompleteExp(config, NULL, NULL, NULL, true)) {
     865    if (!copydoneCompleteExp(config)) {
    883866        // rollback
    884867        if (!psDBRollback(config->dbh)) {
Note: See TracChangeset for help on using the changeset viewer.