IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 11, 2009, 3:54:00 PM (17 years ago)
Author:
watersc1
Message:

Bringing branch up-to-date at revision 25049

Location:
branches/czw_branch/cleanup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/cleanup

  • branches/czw_branch/cleanup/ippTools/src/magictool.c

    r24951 r25051  
    582582    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    583583    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
     584    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    584585
    585586    psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'new' WHERE fault != 0");
     
    803804    // treat limit == 0 as "no limit"
    804805    if (limit) {
    805         psString limitString = psDBGenerateLimitSQL(limit);
     806        // cut limit in half
     807        // hack to prevent pending leaf nodes from blocking branch nodes
     808        psString limitString = psDBGenerateLimitSQL((limit + 1) / 2);
    806809        psStringAppend(&query, " %s", limitString);
    807810        psFree(limitString);
     
    849852
    850853    // look for tree nodes that need to be processed
    851     // XXX: This gets all nodes from all magicRuns that are in 'new'state
    852     // That doens't seem particularly efficient
    853     query = pxDataGet("magictool_toprocess_tree.sql");
     854    query = pxDataGet("magictool_toprocess_runs.sql");
    854855    if (!query) {
    855856        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    857858    }
    858859
     860    {
     861        psString limitString = psDBGenerateLimitSQL( 100 );
     862        psStringAppend(&query, " %s", limitString);
     863        psFree(limitString);
     864    }
    859865
    860866    if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString :  "")) {
     
    867873    psFree(query);
    868874
    869     psArray *magicTree = p_psDBFetchResult(config->dbh);
    870     if (!magicTree) {
     875    psArray *magicRuns = p_psDBFetchResult(config->dbh);
     876    if (!magicRuns) {
    871877        psErrorCode err = psErrorCodeLast();
    872878        switch (err) {
     
    881887        return false;
    882888    }
    883     if (!psArrayLength(magicTree)) {
     889    if (!psArrayLength(magicRuns)) {
    884890        psTrace("magictool", PS_LOG_INFO, "no rows found");
    885         psFree(magicTree);
     891        psFree(magicRuns);
    886892        return true;
    887893    }
    888894
    889     // entries are ordered by magic_id
    890     long index = 0;
    891     while (index <  psArrayLength(magicTree)) {
    892         bool status;
     895    query = pxDataGet("magictool_toprocess_tree.sql");
     896    if (!query) {
     897        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     898        return false;
     899    }
     900
     901    for (psS64 index = 0; index < psArrayLength(magicRuns); index++) {
    893902        if (limit && (psArrayLength(output) >= limit)) {
    894903            break;
    895904        }
    896         psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id");
     905        bool status;
     906        psS64 magic_id = psMetadataLookupS64(&status, magicRuns->data[index], "magic_id");
    897907        if (!status) {
    898908            psAbort("failed to lookup value for magic_id column");
    899909        }
    900 
    901         // find the end of this block
    902         long first = index;
    903         long last = index;
    904         for (long i = index + 1; i < psArrayLength(magicTree); i++) {
    905             psS64 magic_id = psMetadataLookupS64(&status, magicTree->data[i], "magic_id");
    906             if (!status) {
    907                 psAbort("failed to lookup value for magic_id column");
     910       
     911        whereString = NULL;
     912        psStringAppend(&whereString, "\nAND (magic_id = %" PRId64 ")", magic_id);
     913        if (!p_psDBRunQueryF(config->dbh, query, whereString )) {
     914            psError(PS_ERR_UNKNOWN, false, "database error");
     915            psFree(whereString);
     916            psFree(query);
     917            return false;
     918        }
     919        psFree(whereString);
     920        psArray *magicTree = p_psDBFetchResult(config->dbh);
     921        if (!magicTree) {
     922            psErrorCode err = psErrorCodeLast();
     923            switch (err) {
     924                case PS_ERR_DB_CLIENT:
     925                    psError(PXTOOLS_ERR_SYS, false, "database error");
     926                case PS_ERR_DB_SERVER:
     927                    psError(PXTOOLS_ERR_PROG, false, "database error");
     928                default:
     929                    psError(PXTOOLS_ERR_PROG, false, "unknown error");
    908930            }
    909             if (magic_id != current_magic_id) {
    910                 break;
    911             }
    912             last = i;
    913         }
    914 
    915         index = last + 1;
    916 
    917         psHash *forest = psHashAlloc(last - first + 1);
     931
     932            return false;
     933        }
     934        psS64 length = psArrayLength(magicTree);
     935        if (!length) {
     936            psTrace("magictool", PS_LOG_INFO, "no rows found for magic_id %" PRId64, magic_id);
     937            psFree(magicTree);
     938            continue;
     939        }
     940
     941        psHash *forest = psHashAlloc(length);
    918942
    919943        // convert the array of metadata into a pxTree structure
    920         for (long i = first; i <= last; i++) {
     944        for (long i = 0; i < length; i++) {
    921945            bool status;
    922946            psString node = psMetadataLookupStr(&status, magicTree->data[i], "node");
     
    943967        pxTreeCrawl(root, findReadyNodes, output);
    944968        psFree(root);
    945 
    946     }
    947     psFree(magicTree);
     969        psFree(magicTree);
     970    }
    948971
    949972    if (psArrayLength(output)) {
Note: See TracChangeset for help on using the changeset viewer.