Changeset 25022 for branches/eam_branches/20090715/ippTools/src/magictool.c
- Timestamp:
- Aug 7, 2009, 12:45:24 PM (17 years ago)
- Location:
- branches/eam_branches/20090715
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippTools/src/magictool.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090715
- Property svn:mergeinfo changed
/trunk (added) merged: 24801-24824,24827-24834,24836-24859,24861-24901,24903-24912,24914-24950,24953-24971,24973-24977,24986-24989,24993-25017
- Property svn:mergeinfo changed
-
branches/eam_branches/20090715/ippTools/src/magictool.c
r24551 r25022 47 47 static bool revertmaskMode(pxConfig *config); 48 48 static bool maskMode(pxConfig *config); 49 static bool censorrunMode(pxConfig *config); 49 50 50 51 static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state); … … 85 86 MODECASE(MAGICTOOL_MODE_REVERTMASK, revertmaskMode); 86 87 MODECASE(MAGICTOOL_MODE_MASK, maskMode); 88 MODECASE(MAGICTOOL_MODE_CENSORRUN, censorrunMode); 87 89 default: 88 90 psAbort("invalid option (this should not happen)"); … … 580 582 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 581 583 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 584 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 582 585 583 586 psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'new' WHERE fault != 0"); … … 801 804 // treat limit == 0 as "no limit" 802 805 if (limit) { 803 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); 804 809 psStringAppend(&query, " %s", limitString); 805 810 psFree(limitString); … … 847 852 848 853 // look for tree nodes that need to be processed 849 // XXX: This gets all nodes from all magicRuns that are in 'new'state 850 // That doens't seem particularly efficient 851 query = pxDataGet("magictool_toprocess_tree.sql"); 854 query = pxDataGet("magictool_toprocess_runs.sql"); 852 855 if (!query) { 853 856 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 855 858 } 856 859 860 { 861 psString limitString = psDBGenerateLimitSQL( 100 ); 862 psStringAppend(&query, " %s", limitString); 863 psFree(limitString); 864 } 857 865 858 866 if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString : "")) { … … 865 873 psFree(query); 866 874 867 psArray *magic Tree= p_psDBFetchResult(config->dbh);868 if (!magic Tree) {875 psArray *magicRuns = p_psDBFetchResult(config->dbh); 876 if (!magicRuns) { 869 877 psErrorCode err = psErrorCodeLast(); 870 878 switch (err) { … … 879 887 return false; 880 888 } 881 if (!psArrayLength(magic Tree)) {889 if (!psArrayLength(magicRuns)) { 882 890 psTrace("magictool", PS_LOG_INFO, "no rows found"); 883 psFree(magic Tree);891 psFree(magicRuns); 884 892 return true; 885 893 } 886 894 887 // entries are ordered by magic_id 888 long index = 0; 889 while (index < psArrayLength(magicTree)) { 890 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++) { 891 902 if (limit && (psArrayLength(output) >= limit)) { 892 903 break; 893 904 } 894 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"); 895 907 if (!status) { 896 908 psAbort("failed to lookup value for magic_id column"); 897 909 } 898 899 // find the end of this block 900 long first = index; 901 long last = index; 902 for (long i = index + 1; i < psArrayLength(magicTree); i++) { 903 psS64 magic_id = psMetadataLookupS64(&status, magicTree->data[i], "magic_id"); 904 if (!status) { 905 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"); 906 930 } 907 if (magic_id != current_magic_id) { 908 break; 909 } 910 last = i; 911 } 912 913 index = last + 1; 914 915 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); 916 942 917 943 // convert the array of metadata into a pxTree structure 918 for (long i = first; i <= last; i++) {944 for (long i = 0; i < length; i++) { 919 945 bool status; 920 946 psString node = psMetadataLookupStr(&status, magicTree->data[i], "node"); … … 941 967 pxTreeCrawl(root, findReadyNodes, output); 942 968 psFree(root); 943 944 } 945 psFree(magicTree); 969 psFree(magicTree); 970 } 946 971 947 972 if (psArrayLength(output)) { … … 1367 1392 return true; 1368 1393 } 1394 1395 static bool censorStage(pxConfig *config, psString stage, psString whereClause) 1396 { 1397 psString queryFile = NULL; 1398 psStringAppend(&queryFile, "magictool_censor_%s.sql", stage); 1399 psString query = pxDataGet(queryFile); 1400 if (!query) { 1401 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", queryFile); 1402 psFree(queryFile); 1403 if (!psDBRollback(config->dbh)) { 1404 psError(PS_ERR_UNKNOWN, false, "database error"); 1405 } 1406 return false; 1407 } 1408 psFree(queryFile); 1409 1410 psStringAppend(&query, " WHERE %s", whereClause); 1411 1412 if (!p_psDBRunQuery(config->dbh, query)) { 1413 psError(PS_ERR_UNKNOWN, false, "database error"); 1414 psFree(query); 1415 if (!psDBRollback(config->dbh)) { 1416 psError(PS_ERR_UNKNOWN, false, "database error"); 1417 } 1418 return false; 1419 } 1420 psFree(query); 1421 1422 return true; 1423 } 1424 1425 static bool censorrunMode(pxConfig *config) 1426 { 1427 PS_ASSERT_PTR_NON_NULL(config, false); 1428 1429 psError(PS_ERR_PROGRAMMING, true, "-censorrun mode not ready yet"); 1430 return false; 1431 1432 psMetadata *where = psMetadataAlloc(); 1433 1434 // at least one of these required 1435 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1436 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 1437 1438 if (!psListLength(where->list)) { 1439 psError(PS_ERR_UNKNOWN, true, "either -exp_id or -magic_id is required"); 1440 psFree(where); 1441 return false; 1442 } 1443 1444 psString query = psStringCopy("UPDATE magicRun SET state = 'censored'"); 1445 1446 psString whereClause = psDBGenerateWhereConditionSQL(where, "magicRun"); 1447 psFree(where); 1448 psStringAppend(&query, " WHERE %s", whereClause); 1449 1450 if (!psDBTransaction(config->dbh)) { 1451 psError(PS_ERR_UNKNOWN, false, "database error"); 1452 return false; 1453 } 1454 1455 if (!p_psDBRunQuery(config->dbh, query)) { 1456 psError(PS_ERR_UNKNOWN, false, "database error"); 1457 psFree(whereClause); 1458 psFree(query); 1459 return false; 1460 } 1461 psFree(query); 1462 1463 psS32 numUpdated = psDBAffectedRows(config->dbh); 1464 if (numUpdated == 0) { 1465 psError(PS_ERR_UNKNOWN, false, "failed to censor magicRun"); 1466 psFree(whereClause); 1467 return false; 1468 } 1469 1470 // Now queue any destreaked files to be re-verted 1471 1472 // note: on failure censorStage issues the rollback 1473 if (!censorStage(config, "raw", whereClause)) { 1474 psFree(whereClause); 1475 return false; 1476 } 1477 if (!censorStage(config, "chip", whereClause)) { 1478 psFree(whereClause); 1479 return false; 1480 } 1481 if (!censorStage(config, "camera", whereClause)) { 1482 psFree(whereClause); 1483 return false; 1484 } 1485 if (!censorStage(config, "warp", whereClause)) { 1486 psFree(whereClause); 1487 return false; 1488 } 1489 if (!censorStage(config, "diff", whereClause)) { 1490 psFree(whereClause); 1491 return false; 1492 } 1493 1494 psFree(whereClause); 1495 1496 if (!psDBCommit(config->dbh)) { 1497 psError(PS_ERR_UNKNOWN, false, "database error"); 1498 return false; 1499 } 1500 1501 return true; 1502 }
Note:
See TracChangeset
for help on using the changeset viewer.
