2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2003-09-27 23:20:40 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2003-09-27 23:20:40 +00:00
|
|
|
|
2003-10-07 04:47:00 +00:00
|
|
|
// wu_check [-repair]
|
|
|
|
// look for results with missing input files
|
|
|
|
// -repair change them to server_state OVER, outcome COULDNT_SEND
|
2009-08-31 19:35:46 +00:00
|
|
|
//
|
|
|
|
// NOTE 1: this assumes that jobs have a single input file.
|
|
|
|
// NOTE 2: should rewrite to enumerate WUs, not results
|
2003-10-07 04:47:00 +00:00
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
2003-09-27 23:20:40 +00:00
|
|
|
|
2005-01-08 07:44:22 +00:00
|
|
|
#include "boinc_db.h"
|
2009-09-17 17:56:59 +00:00
|
|
|
#include "svn_version.h"
|
2005-01-08 07:44:22 +00:00
|
|
|
|
2003-09-27 23:20:40 +00:00
|
|
|
#include "parse.h"
|
2004-08-06 11:42:41 +00:00
|
|
|
#include "util.h"
|
2003-10-21 05:49:00 +00:00
|
|
|
#include "error_numbers.h"
|
2005-01-08 07:44:22 +00:00
|
|
|
|
2003-09-27 23:20:40 +00:00
|
|
|
#include "sched_config.h"
|
2005-01-08 07:44:22 +00:00
|
|
|
#include "sched_util.h"
|
2003-09-27 23:20:40 +00:00
|
|
|
|
2003-10-07 04:47:00 +00:00
|
|
|
bool repair = false;
|
|
|
|
|
2009-08-31 19:35:46 +00:00
|
|
|
// wu_check
|
2003-09-27 23:20:40 +00:00
|
|
|
// See whether input files that should be present, are
|
|
|
|
|
|
|
|
// get the path a WU's input file
|
|
|
|
//
|
|
|
|
int get_file_path(WORKUNIT& wu, char* path) {
|
|
|
|
char buf[256];
|
|
|
|
bool flag;
|
|
|
|
flag = parse_str(wu.xml_doc, "<name>", buf, sizeof(buf));
|
2003-10-21 04:06:55 +00:00
|
|
|
if (!flag) return ERR_XML_PARSE;
|
2005-09-23 21:09:00 +00:00
|
|
|
dir_hier_path(buf, config.download_dir, config.uldl_dir_fanout, path);
|
2003-09-27 23:20:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-10 22:55:29 +00:00
|
|
|
int handle_result(DB_RESULT& result) {
|
2003-09-27 23:20:40 +00:00
|
|
|
DB_WORKUNIT wu;
|
|
|
|
int retval;
|
|
|
|
char path[256];
|
2004-10-04 23:59:51 +00:00
|
|
|
char buf[256];
|
2003-09-27 23:20:40 +00:00
|
|
|
FILE* f;
|
|
|
|
|
|
|
|
retval = wu.lookup_id(result.workunitid);
|
|
|
|
if (retval) {
|
|
|
|
printf(
|
|
|
|
"ERROR: can't find WU %d for result %d\n",
|
|
|
|
result.workunitid, result.id
|
|
|
|
);
|
2003-10-10 22:55:29 +00:00
|
|
|
return 1;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
|
|
|
get_file_path(wu, path);
|
|
|
|
f = fopen(path, "r");
|
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
} else {
|
2003-10-10 22:55:29 +00:00
|
|
|
printf("no file %s for result %d\n",
|
2003-09-27 23:20:40 +00:00
|
|
|
path, result.id
|
|
|
|
);
|
2003-10-07 04:47:00 +00:00
|
|
|
if (repair) {
|
|
|
|
if (result.server_state == RESULT_SERVER_STATE_UNSENT) {
|
|
|
|
result.server_state = RESULT_SERVER_STATE_OVER;
|
|
|
|
result.outcome = RESULT_OUTCOME_COULDNT_SEND;
|
2004-10-04 23:59:51 +00:00
|
|
|
sprintf(
|
|
|
|
buf,"server_state=%d, outcome=%d",
|
|
|
|
result.server_state, result.outcome
|
|
|
|
);
|
|
|
|
retval = result.update_field(buf);
|
|
|
|
if (retval) {
|
|
|
|
printf(
|
|
|
|
"ERROR: can't update result %d\n",
|
|
|
|
result.id
|
|
|
|
);
|
|
|
|
return 1;
|
|
|
|
}
|
2003-10-07 04:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-10 22:55:29 +00:00
|
|
|
return 1;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
2003-10-10 22:55:29 +00:00
|
|
|
return 0;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 17:56:59 +00:00
|
|
|
void usage(char *name) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Looks for results with missing input files\n\n"
|
|
|
|
"Usage: %s [OPTION]\n\n"
|
|
|
|
"Options:\n"
|
|
|
|
" [ -repair ] change them to server_state OVER,\n"
|
|
|
|
" outcome COULDNT_SEND\n"
|
|
|
|
" [ -h | -help | --help ] Shows this help text\n"
|
|
|
|
" [ -v | -version | --version ] Shows version information\n",
|
|
|
|
name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2003-10-07 04:47:00 +00:00
|
|
|
int main(int argc, char** argv) {
|
2003-09-27 23:20:40 +00:00
|
|
|
DB_RESULT result;
|
|
|
|
char clause[256];
|
2003-10-10 22:55:29 +00:00
|
|
|
int retval, n, nerr;
|
2003-10-07 04:47:00 +00:00
|
|
|
|
2009-09-17 17:56:59 +00:00
|
|
|
for(int c = 1; c < argc; c++) {
|
|
|
|
std::string option(argv[c]);
|
|
|
|
if(option == "-h" || option == "-help" || option == "--help") {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(0);
|
|
|
|
} else if(option == "-v" || option == "-version" || option == "--version") {
|
|
|
|
printf("%s\n", SVN_VERSION);
|
|
|
|
exit(0);
|
|
|
|
} else if (option == "-repair") {
|
|
|
|
repair = true;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "unknown command line argument: %s\n\n", argv[c]);
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-07 04:47:00 +00:00
|
|
|
retval = config.parse_file();
|
|
|
|
if (retval) exit(1);
|
2003-09-27 23:20:40 +00:00
|
|
|
|
2004-01-15 23:53:13 +00:00
|
|
|
retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd);
|
2003-10-10 22:55:29 +00:00
|
|
|
if (retval) {
|
|
|
|
printf("boinc_db.open: %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-09-27 23:20:40 +00:00
|
|
|
|
2003-10-10 22:55:29 +00:00
|
|
|
n = nerr = 0;
|
|
|
|
printf("Unsent results:\n");
|
2003-09-27 23:20:40 +00:00
|
|
|
sprintf(clause, "where server_state=%d", RESULT_SERVER_STATE_UNSENT);
|
|
|
|
while (!result.enumerate(clause)) {
|
2003-10-10 22:55:29 +00:00
|
|
|
retval = handle_result(result);
|
|
|
|
n++;
|
|
|
|
if (retval) nerr++;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
2003-10-10 22:55:29 +00:00
|
|
|
printf("%d out of %d errors\n", nerr, n);
|
|
|
|
n = nerr = 0;
|
|
|
|
printf("In progress results:\n");
|
2003-09-27 23:20:40 +00:00
|
|
|
sprintf(clause, "where server_state=%d", RESULT_SERVER_STATE_IN_PROGRESS);
|
|
|
|
while (!result.enumerate(clause)) {
|
2003-10-10 22:55:29 +00:00
|
|
|
retval = handle_result(result);
|
|
|
|
n++;
|
|
|
|
if (retval) nerr++;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
2003-10-10 22:55:29 +00:00
|
|
|
printf("%d out of %d errors\n", nerr, n);
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_8f4e399992 = "$Id$";
|