- Timestamp:
- Oct 21, 2010, 2:45:13 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100823/ippTools/src/pstamptool.c
r28937 r29515 46 46 static bool pendingjobMode(pxConfig *config); 47 47 static bool updatejobMode(pxConfig *config); 48 static bool stopdependentjobMode(pxConfig *config); 48 49 static bool revertjobMode(pxConfig *config); 49 50 static bool addprojectMode(pxConfig *config); … … 63 64 break; 64 65 66 // XXX make this a configurable parameter 67 #define PSTAMP_MAX_JOB_FAULTS 5 68 #define PSTAMP_MAX_DEP_FAULTS 5 65 69 66 70 int main(int argc, char **argv) … … 89 93 MODECASE(PSTAMPTOOL_MODE_PENDINGJOB, pendingjobMode); 90 94 MODECASE(PSTAMPTOOL_MODE_UPDATEJOB, updatejobMode); 95 MODECASE(PSTAMPTOOL_MODE_STOPDEPENDENTJOB, stopdependentjobMode); 91 96 MODECASE(PSTAMPTOOL_MODE_REVERTJOB, revertjobMode); 92 97 MODECASE(PSTAMPTOOL_MODE_ADDPROJECT, addprojectMode); … … 715 720 outputBase, 716 721 options, 717 dep_id 722 dep_id, 723 0 // fault_count 718 724 )) { 719 725 psError(PS_ERR_UNKNOWN, false, "database error"); … … 877 883 PXOPT_LOOKUP_S64(req_id, config->args, "-req_id", false, false); 878 884 PXOPT_LOOKUP_S64(dep_id, config->args, "-dep_id", false, false); 879 880 if (!job_id && !req_id && !dep_id) { 881 psError(PS_ERR_UNKNOWN, true, "at least one of -job_id -req_id or -dep_id is required"); 885 PXOPT_LOOKUP_S32(fault_count, config->args, "-fault_count", false, false); 886 887 if (!job_id && !req_id && !dep_id && !fault_count) { 888 psError(PS_ERR_UNKNOWN, true, "at least one of -job_id -req_id -dep_id or -fault_count is required"); 882 889 return false; 883 890 } … … 898 905 PXOPT_COPY_S32(config->args, where, "-fault", "pstampJob.fault", "=="); 899 906 PXOPT_COPY_STR(config->args, where, "-state", "pstampJob.state", "=="); 907 PXOPT_COPY_S32(config->args, where, "-fault_count", "pstampJob.fault_count", ">="); 908 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE"); 900 909 901 910 psString query = pxDataGet("pstamptool_updatejob.sql"); … … 909 918 psStringAppend(&query, "\n %c pstampJob.fault = %d", c, fault); 910 919 c = ','; 920 psStringAppend(&query, ", pstampJob.fault_count = pstampJob.fault_count+ 1"); 911 921 } 912 922 … … 925 935 psU64 affected = psDBAffectedRows(config->dbh); 926 936 psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampJobs", affected); 937 938 return true; 939 } 940 // Terminate jobs which have dependents setting both the pstampDependent and pstampJob.fault 941 static bool stopdependentjobMode(pxConfig *config) 942 { 943 PS_ASSERT_PTR_NON_NULL(config, false); 944 945 PXOPT_LOOKUP_S32(fault, config->args, "-set_fault", true, false); 946 947 psMetadata *where = psMetadataAlloc(); 948 949 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 950 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 951 PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "=="); 952 PXOPT_COPY_S32(config->args, where, "-fault", "pstampDependent.fault", "=="); 953 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE"); 954 // if (fault_count) { 955 PXOPT_COPY_S32(config->args, where, "-fault_count", "pstampDependent.fault_count", ">="); 956 // } 957 958 // XXX: How about selecting by pstampRequest.label? No. That is too dangerous by itself. 959 960 psString query = pxDataGet("pstamptool_stopdependentjob.sql"); 961 962 if (psListLength(where->list)) { 963 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 964 psStringAppend(&query, " AND %s", whereClause); 965 psFree(whereClause); 966 } else { 967 psFree(where); 968 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 969 return false; 970 } 971 psFree(where); 972 973 if (!p_psDBRunQueryF(config->dbh, query, fault, fault)) { 974 psError(PS_ERR_UNKNOWN, false, "database error"); 975 psFree(query); 976 return false; 977 } 978 psFree(query); 979 980 psU64 affected = psDBAffectedRows(config->dbh); 981 psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampJobs and pstampDependents", affected); 927 982 928 983 return true; … … 941 996 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE"); 942 997 998 PXOPT_LOOKUP_BOOL(clear_fault_count, config->args, "-clear_fault_count", false); 999 943 1000 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 1001 1002 // XXX: we don't actually use -limit. It doesn't work for UPDATE 1003 // it's an allowed arg because add_poll_args adds it 944 1004 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 945 1005 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); … … 947 1007 // By default only revert faults < PSTAMP_FIRST_ERROR_CODE which are our "ipp exit codes" 948 1008 // codes larger than that are the pstamp request interface. 949 // Don't fault those unless -fault wa aprovided1009 // Don't fault those unless -fault was explicitly provided 950 1010 psString faultClause = psStringCopy(""); 951 1011 if (!fault) { … … 966 1026 psFree(where); 967 1027 968 if (!p_psDBRunQueryF(config->dbh, query, faultClause)) { 1028 // don't keep reverting once the number of faults reaches some value unless 1029 // a parameter asking us to clear that count is provided 1030 psString faultCountClause = NULL; 1031 if (clear_fault_count) { 1032 psStringAppend(&faultCountClause, "\n, pstampJob.fault_count = 0"); 1033 } else { 1034 psStringAppend(&query, " AND pstampJob.fault_count < %d", PSTAMP_MAX_JOB_FAULTS); 1035 } 1036 1037 if (!p_psDBRunQueryF(config->dbh, query, faultCountClause, faultClause)) { 1038 psFree(faultCountClause); 969 1039 psFree(faultClause); 970 1040 psFree(query); … … 974 1044 975 1045 psFree(faultClause); 1046 psFree(faultCountClause); 1047 psFree(query); 976 1048 977 1049 return true; … … 1178 1250 need_magic, 1179 1251 outdir, 1180 0 // fault 1252 0, // fault 1253 0 // fault_count 1181 1254 )) { 1182 1255 if (!psDBRollback(config->dbh)) { … … 1300 1373 psStringAppend(&query, "%s fault = %d", needComma ? ", " : "", fault); 1301 1374 needComma = true; 1375 psStringAppend(&query, ", pstampDependent.fault_count = pstampDependent.fault_count + 1"); 1302 1376 } 1303 1377 psStringAppend(&query, " WHERE dep_id = %" PRId64, dep_id); … … 1325 1399 PXOPT_COPY_S64(config->args, where, "-fault", "pstampDependent.fault", "=="); 1326 1400 PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "=="); 1401 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 1402 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 1327 1403 pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "=="); 1404 PXOPT_LOOKUP_BOOL(clear_fault_count, config->args, "-clear_fault_count", false); 1405 1406 // XXX: we don't actually use -limit. It doesn't work for UPDATE 1407 // it's an allowed arg because add_poll_args adds it 1408 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1328 1409 1329 1410 if (!psListLength(where->list)) { … … 1352 1433 } 1353 1434 1354 if (!p_psDBRunQuery(config->dbh, query)) { 1435 // don't keep reverting once the number of faults reaches some value unless 1436 // a parameter asking us to clear that count is provided 1437 psString faultCountClause = NULL; 1438 if (clear_fault_count) { 1439 psStringAppend(&faultCountClause, "\n, pstampDependent.fault_count = 0"); 1440 } else { 1441 psStringAppend(&faultCountClause, " "); 1442 psStringAppend(&query, " AND pstampDependent.fault_count < %d", PSTAMP_MAX_DEP_FAULTS); 1443 } 1444 1445 if (!p_psDBRunQueryF(config->dbh, query, faultCountClause)) { 1355 1446 psError(PS_ERR_UNKNOWN, false, "database error"); 1356 1447 psFree(query);
Note:
See TracChangeset
for help on using the changeset viewer.
