IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

add pztool -copydone -row_lock option

File:
1 edited

Legend:

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

    r18561 r20172  
    4646static bool advanceMode(pxConfig *config);
    4747
    48 static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope);
     48static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, bool rowLock);
    4949static psArray *pzGetPendingCameras(pxConfig *config);
    5050static psArray *pzArrayZip(psArray *arraySet, psS64 limit);
     
    397397    PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
    398398    PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false);
     399    PXOPT_LOOKUP_BOOL(row_lock, config->args, "-row_lock", false);
    399400
    400401    // default values
     
    423424    }
    424425
    425     if (!copydoneCompleteExp(config, exp_name, camera, telescope)) {
     426    if (!copydoneCompleteExp(config, exp_name, camera, telescope, row_lock)) {
    426427        // rollback
    427428        if (!psDBRollback(config->dbh)) {
     
    445446}
    446447
    447 static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope)
     448static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, bool row_lock)
    448449{
    449450    // THIS FUNCTION MUST BE INVOKED FROM INSIDE A TRANSACTION!!!
     
    463464    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    464465
     466
    465467    // find all exposures that have had all of their imfiles downloaded but do
    466468    // not appear in newExp
     
    498500    }
    499501
     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    }
     508
    500509    if (psListLength(where->list)) {
    501510        psString whereClause = psDBGenerateWhereSQL(where, NULL);
    502511        psStringAppend(&query, " %s", whereClause);
     512        if (row_lock) {
     513            psStringAppend(&lock_query, " %s FOR UPDATE", whereClause);
     514        }
    503515        psFree(whereClause);
    504516    }
    505517    psFree(where);
    506518
     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    }
     530
     531    // find completed exps
    507532    if (!p_psDBRunQuery(config->dbh, query)) {
    508533        psError(PS_ERR_UNKNOWN, false, "database error");
     
    855880    }
    856881
    857     if (!copydoneCompleteExp(config, NULL, NULL, NULL)) {
     882    if (!copydoneCompleteExp(config, NULL, NULL, NULL, true)) {
    858883        // rollback
    859884        if (!psDBRollback(config->dbh)) {
Note: See TracChangeset for help on using the changeset viewer.