IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26565


Ignore:
Timestamp:
Jan 12, 2010, 2:04:28 PM (16 years ago)
Author:
bills
Message:

run getdependent mode in a transaction

File:
1 edited

Legend:

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

    r26213 r26565  
    925925    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
    926926
     927    psMetadata *where = psMetadataAlloc();
     928    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     929    PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "==");
     930    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     931
     932    // start a transaction eraly so it will contain any row level locks
     933    if (!psDBTransaction(config->dbh)) {
     934        psError(PS_ERR_UNKNOWN, false, "database error");
     935        return false;
     936    }
     937
    927938    psString query = pxDataGet("pstamptool_pendingdependent.sql");
    928939    if (!query) {
     
    930941        return false;
    931942    }
     943    psString whereClause = psDBGenerateWhereSQL(where, "WHERE");
     944    if (!no_create) {
     945        // This will lock the row until the transaction is committed
     946        psStringAppend(&query, " %s FOR UPDATE", whereClause);
     947    } else {
     948        psStringAppend(&query, " %s", whereClause);
     949    }
     950    psFree(whereClause);
     951    psFree(where);
     952
    932953    if (!p_psDBRunQuery(config->dbh, query)) {
    933954        psError(PS_ERR_UNKNOWN, false, "database error");
     
    947968        if (!dep_id) {
    948969            psError(PS_ERR_UNKNOWN, false, "database error");
     970            psFree(output);
    949971            return false;
    950972        }
    951973        printf("%" PRId64 "\n", dep_id);
     974        psFree(output);
     975        if (!psDBRollback(config->dbh)) {
     976            psError(PS_ERR_UNKNOWN, false, "database error");
     977        }
    952978        return true;
    953979    }
    954980    if (no_create) {
     981        if (!psDBRollback(config->dbh)) {
     982            psError(PS_ERR_UNKNOWN, false, "database error");
     983            return false;
     984        }
    955985        return true;
    956986    }
    957987    // no existing dependent that matches, insert one
     988    // Since we have multiple processes running jobs we have a
     989    // race condition here so that's why we need to lock the table
    958990
    959991    if (!pstampDependentInsert(
     
    967999        no_magic
    9681000        )) {
     1001        if (!psDBRollback(config->dbh)) {
     1002            psError(PS_ERR_UNKNOWN, false, "database error");
     1003        }
    9691004        psError(PS_ERR_UNKNOWN, false, "failed to insert pstampDependent");
    9701005        return false;
    9711006    }
    9721007
     1008    if (!psDBCommit(config->dbh)) {
     1009        // rollback
     1010        if (!psDBRollback(config->dbh)) {
     1011            psError(PS_ERR_UNKNOWN, false, "database error");
     1012        }
     1013        psError(PS_ERR_UNKNOWN, false, "database error");
     1014        return false;
     1015    }
     1016
    9731017    psS64 dep_id = psDBLastInsertID(config->dbh);
    974 
    9751018    printf("%" PRId64 "\n", dep_id);
    9761019
Note: See TracChangeset for help on using the changeset viewer.