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
|
2003-06-11 23:12:57 +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.
|
2003-06-11 23:12:57 +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.
|
2002-12-03 18:57: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/>.
|
2002-12-03 18:57:40 +00:00
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// transitioner - handle transitions in the state of a WU
|
|
|
|
// - a result has become DONE (via timeout or client reply)
|
|
|
|
// - the WU error mask is set (e.g. by validater)
|
|
|
|
// - assimilation is finished
|
2002-10-24 08:25:42 +00:00
|
|
|
//
|
2003-08-15 20:35:44 +00:00
|
|
|
// cmdline:
|
|
|
|
// [ -one_pass ] do one pass, then exit
|
|
|
|
// [ -d x ] debug level x
|
2004-06-27 23:26:52 +00:00
|
|
|
// [ -mod n i ] process only WUs with (id mod n) == i
|
2008-11-26 19:09:27 +00:00
|
|
|
// [ -sleep_interval x ] sleep x seconds if nothing to do
|
2002-10-24 08:25:42 +00:00
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2002-11-05 18:36:09 +00:00
|
|
|
#include <vector>
|
2002-11-07 19:31:34 +00:00
|
|
|
#include <unistd.h>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstring>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <climits>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
2008-06-01 03:43:47 +00:00
|
|
|
#include <signal.h>
|
2002-11-05 18:36:09 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2003-02-10 19:51:32 +00:00
|
|
|
#include "util.h"
|
2002-11-07 19:31:34 +00:00
|
|
|
#include "backend_lib.h"
|
2008-02-26 17:24:29 +00:00
|
|
|
#include "common_defs.h"
|
2008-10-27 21:23:07 +00:00
|
|
|
#include "error_numbers.h"
|
2009-05-07 13:54:51 +00:00
|
|
|
#include "str_util.h"
|
2009-09-17 17:56:59 +00:00
|
|
|
#include "svn_version.h"
|
2008-02-26 17:24:29 +00:00
|
|
|
|
2003-08-15 00:45:25 +00:00
|
|
|
#include "sched_config.h"
|
2003-03-08 00:09:40 +00:00
|
|
|
#include "sched_util.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "sched_msgs.h"
|
2008-09-22 17:52:41 +00:00
|
|
|
#ifdef GCL_SIMULATOR
|
|
|
|
#include "gcl_simulator.h"
|
|
|
|
#endif
|
2002-11-05 18:36:09 +00:00
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
#define LOCKFILE "transitioner.out"
|
|
|
|
#define PIDFILE "transitioner.pid"
|
2002-12-12 23:01:26 +00:00
|
|
|
|
2004-07-22 17:43:11 +00:00
|
|
|
#define SELECT_LIMIT 1000
|
2008-11-26 19:09:27 +00:00
|
|
|
|
|
|
|
#define DEFAULT_SLEEP_INTERVAL 5
|
2004-07-21 21:50:25 +00:00
|
|
|
|
2002-11-05 18:36:09 +00:00
|
|
|
int startup_time;
|
2002-11-07 19:31:34 +00:00
|
|
|
R_RSA_PRIVATE_KEY key;
|
2004-06-27 23:26:52 +00:00
|
|
|
int mod_n, mod_i;
|
|
|
|
bool do_mod = false;
|
2005-07-17 19:52:44 +00:00
|
|
|
bool one_pass = false;
|
2008-11-26 20:37:11 +00:00
|
|
|
int sleep_interval = DEFAULT_SLEEP_INTERVAL;
|
2008-06-01 03:43:47 +00:00
|
|
|
|
2008-06-26 21:20:07 +00:00
|
|
|
void signal_handler(int) {
|
2008-06-01 03:43:47 +00:00
|
|
|
log_messages.printf(MSG_NORMAL, "Signaled by simulator\n");
|
|
|
|
return;
|
|
|
|
}
|
2002-11-05 18:36:09 +00:00
|
|
|
|
2004-07-16 21:23:43 +00:00
|
|
|
int result_suffix(char* name) {
|
|
|
|
char* p = strrchr(name, '_');
|
|
|
|
if (p) return atoi(p+1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-12 06:20:28 +00:00
|
|
|
// A result just timed out.
|
2005-02-26 00:24:37 +00:00
|
|
|
// Update the host's avg_turnaround and max_results_day.
|
2004-12-16 22:10:51 +00:00
|
|
|
//
|
|
|
|
int penalize_host(int hostid, double delay_bound) {
|
|
|
|
DB_HOST host;
|
2004-12-17 19:15:22 +00:00
|
|
|
char buf[256];
|
2004-12-16 22:10:51 +00:00
|
|
|
int retval = host.lookup_id(hostid);
|
|
|
|
if (retval) return retval;
|
2005-02-23 00:11:59 +00:00
|
|
|
compute_avg_turnaround(host, delay_bound);
|
2007-07-06 16:37:00 +00:00
|
|
|
if (host.max_results_day == 0 || host.max_results_day > config.daily_result_quota) {
|
2005-03-19 18:24:24 +00:00
|
|
|
host.max_results_day = config.daily_result_quota;
|
|
|
|
}
|
2005-02-26 00:24:37 +00:00
|
|
|
host.max_results_day -= 1;
|
|
|
|
if (host.max_results_day < 1) {
|
|
|
|
host.max_results_day = 1;
|
|
|
|
}
|
|
|
|
sprintf(buf,
|
|
|
|
"avg_turnaround=%f, max_results_day=%d",
|
|
|
|
host.avg_turnaround, host.max_results_day
|
|
|
|
);
|
2004-12-17 19:15:22 +00:00
|
|
|
return host.update_field(buf);
|
2004-12-16 22:10:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-21 21:50:25 +00:00
|
|
|
int handle_wu(
|
2004-07-10 00:11:20 +00:00
|
|
|
DB_TRANSITIONER_ITEM_SET& transitioner,
|
2004-07-03 23:35:23 +00:00
|
|
|
std::vector<TRANSITIONER_ITEM>& items
|
|
|
|
) {
|
2004-07-02 23:27:15 +00:00
|
|
|
int ntotal, nerrors, retval, ninprogress, nsuccess;
|
2004-12-02 23:00:30 +00:00
|
|
|
int nunsent, ncouldnt_send, nover, ndidnt_need, nno_reply;
|
2004-08-13 15:52:55 +00:00
|
|
|
int canonical_result_index, j;
|
2004-07-02 17:53:31 +00:00
|
|
|
char suffix[256];
|
2003-08-15 20:35:44 +00:00
|
|
|
time_t now = time(0), x;
|
2004-12-14 00:57:03 +00:00
|
|
|
bool all_over_and_validated, have_new_result_to_validate, do_delete;
|
2004-08-13 15:52:55 +00:00
|
|
|
unsigned int i;
|
2002-10-24 08:25:42 +00:00
|
|
|
|
2008-02-21 00:47:50 +00:00
|
|
|
TRANSITIONER_ITEM& wu_item = items[0];
|
|
|
|
TRANSITIONER_ITEM wu_item_original = wu_item;
|
|
|
|
|
2008-03-03 19:33:32 +00:00
|
|
|
// "assigned" WUs aren't supposed to pass through the transitioner.
|
|
|
|
// If we get one, it's an error
|
|
|
|
//
|
2008-02-26 17:24:29 +00:00
|
|
|
if (config.enable_assignment && strstr(wu_item.name, ASSIGNED_WU_STR)) {
|
2008-03-03 19:33:32 +00:00
|
|
|
DB_WORKUNIT wu;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
wu.id = wu_item.id;
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"Assigned WU %d unexpectedly found by transitioner\n", wu.id
|
|
|
|
);
|
|
|
|
sprintf(buf, "transition_time=%d", INT_MAX);
|
|
|
|
retval = wu.update_field(buf);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"update_field failed %d\n", retval
|
|
|
|
);
|
|
|
|
}
|
2008-02-21 00:47:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// count up the number of results in various states,
|
|
|
|
// and check for timed-out results
|
|
|
|
//
|
2004-07-02 23:27:15 +00:00
|
|
|
ntotal = 0;
|
2003-08-15 20:35:44 +00:00
|
|
|
nunsent = 0;
|
|
|
|
ninprogress = 0;
|
2003-10-10 20:10:18 +00:00
|
|
|
nover = 0;
|
2003-01-23 08:07:48 +00:00
|
|
|
nerrors = 0;
|
2003-08-15 20:35:44 +00:00
|
|
|
nsuccess = 0;
|
|
|
|
ncouldnt_send = 0;
|
2004-12-02 23:00:30 +00:00
|
|
|
nno_reply = 0;
|
|
|
|
ndidnt_need = 0;
|
2004-12-14 00:57:03 +00:00
|
|
|
have_new_result_to_validate = false;
|
2004-07-16 21:23:43 +00:00
|
|
|
int rs, max_result_suffix = -1;
|
|
|
|
|
2005-02-08 00:39:05 +00:00
|
|
|
// Scan the WU's results, and find the canonical result if there is one
|
|
|
|
//
|
|
|
|
canonical_result_index = -1;
|
|
|
|
if (wu_item.canonical_resultid) {
|
|
|
|
for (i=0; i<items.size(); i++) {
|
|
|
|
TRANSITIONER_ITEM& res_item = items[i];
|
|
|
|
if (!res_item.res_id) continue;
|
|
|
|
if (res_item.res_id == wu_item.canonical_resultid) {
|
|
|
|
canonical_result_index = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wu_item.canonical_resultid && (canonical_result_index == -1)) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2005-02-08 00:39:05 +00:00
|
|
|
"[WU#%d %s] can't find canonical result\n",
|
|
|
|
wu_item.id, wu_item.name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is a canonical result, see if its file are deleted
|
|
|
|
//
|
|
|
|
bool canonical_result_files_deleted = false;
|
|
|
|
if (canonical_result_index >= 0) {
|
|
|
|
TRANSITIONER_ITEM& cr = items[canonical_result_index];
|
|
|
|
if (cr.res_file_delete_state == FILE_DELETE_DONE) {
|
|
|
|
canonical_result_files_deleted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan this WU's results, and
|
|
|
|
// 1) count those in various server states;
|
|
|
|
// 2) identify time-out results and update their server state and outcome
|
|
|
|
// 3) find the max result suffix (in case need to generate new ones)
|
|
|
|
// 4) see if we have a new result to validate
|
|
|
|
// (outcome SUCCESS and validate_state INIT)
|
|
|
|
//
|
2004-08-13 15:52:55 +00:00
|
|
|
for (i=0; i<items.size(); i++) {
|
|
|
|
TRANSITIONER_ITEM& res_item = items[i];
|
|
|
|
|
|
|
|
if (!res_item.res_id) continue;
|
2004-07-16 21:23:43 +00:00
|
|
|
ntotal++;
|
2005-02-08 00:39:05 +00:00
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
rs = result_suffix(res_item.res_name);
|
2004-07-16 21:23:43 +00:00
|
|
|
if (rs > max_result_suffix) max_result_suffix = rs;
|
2005-02-08 00:39:05 +00:00
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
switch (res_item.res_server_state) {
|
2004-07-16 21:23:43 +00:00
|
|
|
case RESULT_SERVER_STATE_UNSENT:
|
|
|
|
nunsent++;
|
|
|
|
break;
|
|
|
|
case RESULT_SERVER_STATE_IN_PROGRESS:
|
2004-08-13 15:52:55 +00:00
|
|
|
if (res_item.res_report_deadline < now) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2004-07-16 21:23:43 +00:00
|
|
|
"[WU#%d %s] [RESULT#%d %s] result timed out (%d < %d) server_state:IN_PROGRESS=>OVER; outcome:NO_REPLY\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, res_item.res_id, res_item.res_name,
|
|
|
|
res_item.res_report_deadline, (int)now
|
2004-07-16 21:23:43 +00:00
|
|
|
);
|
2004-08-13 15:52:55 +00:00
|
|
|
res_item.res_server_state = RESULT_SERVER_STATE_OVER;
|
|
|
|
res_item.res_outcome = RESULT_OUTCOME_NO_REPLY;
|
|
|
|
retval = transitioner.update_result(res_item);
|
2004-07-16 21:23:43 +00:00
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2004-08-13 15:52:55 +00:00
|
|
|
"[WU#%d %s] [RESULT#%d %s] update_result(): %d\n",
|
|
|
|
wu_item.id, wu_item.name, res_item.res_id,
|
|
|
|
res_item.res_name, retval
|
|
|
|
);
|
2003-10-06 23:42:43 +00:00
|
|
|
}
|
2004-12-17 19:15:22 +00:00
|
|
|
penalize_host(res_item.res_hostid, (double)wu_item.delay_bound);
|
2004-07-02 23:27:15 +00:00
|
|
|
nover++;
|
2005-09-11 10:33:47 +00:00
|
|
|
nno_reply++;
|
2004-07-16 21:23:43 +00:00
|
|
|
} else {
|
|
|
|
ninprogress++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESULT_SERVER_STATE_OVER:
|
|
|
|
nover++;
|
2004-08-13 15:52:55 +00:00
|
|
|
switch (res_item.res_outcome) {
|
2004-07-16 21:23:43 +00:00
|
|
|
case RESULT_OUTCOME_COULDNT_SEND:
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2004-07-16 21:23:43 +00:00
|
|
|
"[WU#%d %s] [RESULT#%d %s] result couldn't be sent\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, res_item.res_id, res_item.res_name
|
2004-07-16 21:23:43 +00:00
|
|
|
);
|
|
|
|
ncouldnt_send++;
|
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_SUCCESS:
|
2004-08-13 15:52:55 +00:00
|
|
|
if (res_item.res_validate_state == VALIDATE_STATE_INIT) {
|
2005-02-08 00:39:05 +00:00
|
|
|
if (canonical_result_files_deleted) {
|
|
|
|
res_item.res_validate_state = VALIDATE_STATE_TOO_LATE;
|
|
|
|
retval = transitioner.update_result(res_item);
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2005-02-08 00:39:05 +00:00
|
|
|
"[WU#%d %s] [RESULT#%d %s] validate_state:INIT=>TOO_LATE retval %d\n",
|
2006-06-03 14:59:22 +00:00
|
|
|
wu_item.id, wu_item.name, res_item.res_id,
|
|
|
|
res_item.res_name, retval
|
2005-02-08 00:39:05 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
have_new_result_to_validate = true;
|
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
2004-07-16 21:23:43 +00:00
|
|
|
nsuccess++;
|
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_CLIENT_ERROR:
|
2004-09-10 00:41:48 +00:00
|
|
|
case RESULT_OUTCOME_VALIDATE_ERROR:
|
2004-07-16 21:23:43 +00:00
|
|
|
nerrors++;
|
2003-01-23 08:07:48 +00:00
|
|
|
break;
|
2006-07-06 17:30:03 +00:00
|
|
|
case RESULT_OUTCOME_CLIENT_DETACHED:
|
|
|
|
case RESULT_OUTCOME_NO_REPLY:
|
2004-12-02 23:00:30 +00:00
|
|
|
nno_reply++;
|
|
|
|
break;
|
2006-07-06 17:30:03 +00:00
|
|
|
case RESULT_OUTCOME_DIDNT_NEED:
|
2004-12-02 23:00:30 +00:00
|
|
|
ndidnt_need++;
|
|
|
|
break;
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2004-07-16 21:23:43 +00:00
|
|
|
break;
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2004-12-02 23:12:04 +00:00
|
|
|
"[WU#%d %s] %d results: unsent %d, in_progress %d, over %d (success %d, error %d, couldnt_send %d, no_reply %d, didnt_need %d)\n",
|
2005-02-08 00:39:05 +00:00
|
|
|
wu_item.id, wu_item.name, ntotal, nunsent, ninprogress, nover,
|
|
|
|
nsuccess, nerrors, ncouldnt_send, nno_reply, ndidnt_need
|
2003-10-10 20:10:18 +00:00
|
|
|
);
|
|
|
|
|
2005-02-08 00:39:05 +00:00
|
|
|
// if there's a new result to validate, trigger validation
|
2003-01-23 08:07:48 +00:00
|
|
|
//
|
2005-02-08 00:39:05 +00:00
|
|
|
if (have_new_result_to_validate && (nsuccess >= wu_item.min_quorum)) {
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.need_validate = true;
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2005-02-08 00:39:05 +00:00
|
|
|
"[WU#%d %s] need_validate:=>true\n", wu_item.id, wu_item.name
|
2003-10-10 05:36:09 +00:00
|
|
|
);
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for WU error conditions
|
|
|
|
// NOTE: check on max # of success results is done in validater
|
|
|
|
//
|
|
|
|
if (ncouldnt_send > 0) {
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.error_mask |= WU_ERROR_COULDNT_SEND_RESULT;
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 23:41:31 +00:00
|
|
|
// if WU has results with errors and no success yet,
|
|
|
|
// reset homogeneous redundancy class to give other platforms a try
|
|
|
|
//
|
2010-01-22 23:55:50 +00:00
|
|
|
if (nerrors && !(nsuccess || ninprogress)) {
|
2007-05-29 23:41:31 +00:00
|
|
|
wu_item.hr_class = 0;
|
|
|
|
}
|
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
if (nerrors > wu_item.max_error_results) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2003-06-14 20:15:53 +00:00
|
|
|
"[WU#%d %s] WU has too many errors (%d errors for %d results)\n",
|
2009-09-18 15:59:40 +00:00
|
|
|
wu_item.id, wu_item.name, nerrors, ntotal
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.error_mask |= WU_ERROR_TOO_MANY_ERROR_RESULTS;
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2009-09-16 04:35:42 +00:00
|
|
|
|
|
|
|
// see how many new results we need to make
|
|
|
|
//
|
|
|
|
int n_new_results_needed = wu_item.target_nresults - nunsent - ninprogress - nsuccess;
|
|
|
|
if (n_new_results_needed < 0) n_new_results_needed = 0;
|
2009-09-18 15:59:40 +00:00
|
|
|
int n_new_results_allowed = wu_item.max_total_results - ntotal;
|
2009-09-16 04:35:42 +00:00
|
|
|
|
|
|
|
// if we're already at the limit and need more, error out the WU
|
|
|
|
//
|
|
|
|
bool too_many = false;
|
|
|
|
if (n_new_results_allowed < 0) {
|
|
|
|
too_many = true;
|
|
|
|
} else if (n_new_results_allowed == 0) {
|
|
|
|
if (n_new_results_needed > 0) {
|
|
|
|
too_many = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (n_new_results_needed > n_new_results_allowed) {
|
|
|
|
n_new_results_needed = n_new_results_allowed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (too_many) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2003-08-15 20:35:44 +00:00
|
|
|
"[WU#%d %s] WU has too many total results (%d)\n",
|
2009-09-18 15:59:40 +00:00
|
|
|
wu_item.id, wu_item.name, ntotal
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.error_mask |= WU_ERROR_TOO_MANY_TOTAL_RESULTS;
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-11-03 23:05:12 +00:00
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// if this WU had an error, don't send any unsent results,
|
|
|
|
// and trigger assimilation if needed
|
2003-01-23 08:07:48 +00:00
|
|
|
//
|
2004-08-13 15:52:55 +00:00
|
|
|
if (wu_item.error_mask) {
|
|
|
|
for (i=0; i<items.size(); i++) {
|
|
|
|
TRANSITIONER_ITEM& res_item = items[i];
|
2009-09-18 15:59:40 +00:00
|
|
|
if (!res_item.res_id) continue;
|
|
|
|
bool update_result = false;
|
|
|
|
switch(res_item.res_server_state) {
|
|
|
|
case RESULT_SERVER_STATE_UNSENT:
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] server_state:UNSENT=>OVER; outcome:=>DIDNT_NEED\n",
|
|
|
|
wu_item.id, wu_item.name, res_item.res_id, res_item.res_name
|
|
|
|
);
|
|
|
|
res_item.res_server_state = RESULT_SERVER_STATE_OVER;
|
|
|
|
res_item.res_outcome = RESULT_OUTCOME_DIDNT_NEED;
|
|
|
|
update_result = true;
|
|
|
|
break;
|
|
|
|
case RESULT_SERVER_STATE_OVER:
|
|
|
|
switch (res_item.res_outcome) {
|
|
|
|
case RESULT_OUTCOME_SUCCESS:
|
|
|
|
switch(res_item.res_validate_state) {
|
|
|
|
case VALIDATE_STATE_INIT:
|
|
|
|
case VALIDATE_STATE_INCONCLUSIVE:
|
|
|
|
res_item.res_validate_state = VALIDATE_STATE_NO_CHECK;
|
|
|
|
update_result = true;
|
|
|
|
break;
|
2004-12-15 23:50:00 +00:00
|
|
|
}
|
2004-07-02 23:27:15 +00:00
|
|
|
}
|
2009-09-18 15:59:40 +00:00
|
|
|
}
|
|
|
|
if (update_result) {
|
|
|
|
retval = transitioner.update_result(res_item);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] result.update() == %d\n",
|
|
|
|
wu_item.id, wu_item.name, res_item.res_id, res_item.res_name, retval
|
|
|
|
);
|
2003-10-06 23:42:43 +00:00
|
|
|
}
|
2002-11-03 23:05:12 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-13 15:52:55 +00:00
|
|
|
if (wu_item.assimilate_state == ASSIMILATE_INIT) {
|
|
|
|
wu_item.assimilate_state = ASSIMILATE_READY;
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2003-10-10 05:36:09 +00:00
|
|
|
"[WU#%d %s] error_mask:%d assimilate_state:INIT=>READY\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, wu_item.error_mask
|
|
|
|
);
|
2002-11-03 23:05:12 +00:00
|
|
|
}
|
2008-03-13 23:35:13 +00:00
|
|
|
} else if (wu_item.canonical_resultid == 0) {
|
2005-02-08 00:39:05 +00:00
|
|
|
// Here if no WU-level error.
|
|
|
|
// Generate new results if needed.
|
2004-07-21 21:50:25 +00:00
|
|
|
//
|
2009-02-26 00:23:23 +00:00
|
|
|
std::string values;
|
2004-07-21 21:50:25 +00:00
|
|
|
char value_buf[MAX_QUERY_LEN];
|
2009-09-16 04:35:42 +00:00
|
|
|
if (n_new_results_needed > 0) {
|
2008-03-07 21:13:01 +00:00
|
|
|
log_messages.printf(
|
|
|
|
MSG_NORMAL,
|
2003-08-18 22:34:53 +00:00
|
|
|
"[WU#%d %s] Generating %d more results (%d target - %d unsent - %d in progress - %d success)\n",
|
2009-09-16 04:35:42 +00:00
|
|
|
wu_item.id, wu_item.name, n_new_results_needed,
|
|
|
|
wu_item.target_nresults, nunsent, ninprogress, nsuccess
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2009-09-16 04:35:42 +00:00
|
|
|
for (j=0; j<n_new_results_needed; j++) {
|
2004-08-13 15:52:55 +00:00
|
|
|
sprintf(suffix, "%d", max_result_suffix+j+1);
|
2009-05-07 13:54:51 +00:00
|
|
|
const char *rtfpath = config.project_path("%s", wu_item.result_template_file);
|
2007-04-05 17:02:01 +00:00
|
|
|
int priority_increase = 0;
|
2008-02-21 00:47:50 +00:00
|
|
|
if (nover && config.reliable_priority_on_over) {
|
|
|
|
priority_increase += config.reliable_priority_on_over;
|
2007-04-05 17:02:01 +00:00
|
|
|
} else if (nover && !nerrors && config.reliable_priority_on_over_except_error) {
|
2008-02-21 00:47:50 +00:00
|
|
|
priority_increase += config.reliable_priority_on_over_except_error;
|
2007-04-05 17:02:01 +00:00
|
|
|
}
|
2008-02-21 00:47:50 +00:00
|
|
|
retval = create_result_ti(
|
2009-05-07 13:54:51 +00:00
|
|
|
wu_item, (char *)rtfpath, suffix, key, config, value_buf, priority_increase
|
2004-07-02 19:45:33 +00:00
|
|
|
);
|
2003-08-15 23:44:28 +00:00
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2008-02-21 00:47:50 +00:00
|
|
|
"[WU#%d %s] create_result_ti() %d\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, retval
|
2003-08-15 23:44:28 +00:00
|
|
|
);
|
2004-07-21 21:50:25 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2004-08-13 15:52:55 +00:00
|
|
|
if (j==0) {
|
2004-07-21 21:50:25 +00:00
|
|
|
values = value_buf;
|
|
|
|
} else {
|
|
|
|
values += ",";
|
|
|
|
values += value_buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DB_RESULT r;
|
2005-01-10 00:00:42 +00:00
|
|
|
retval = r.insert_batch(values);
|
2004-07-21 21:50:25 +00:00
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2004-07-21 21:50:25 +00:00
|
|
|
"[WU#%d %s] insert_batch() %d\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, retval
|
2004-07-21 21:50:25 +00:00
|
|
|
);
|
|
|
|
return retval;
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
|
2004-04-09 06:01:25 +00:00
|
|
|
// scan results:
|
|
|
|
// - see if all over and validated
|
2003-08-15 20:35:44 +00:00
|
|
|
//
|
2004-04-09 06:01:25 +00:00
|
|
|
all_over_and_validated = true;
|
2010-01-22 23:55:50 +00:00
|
|
|
bool all_over_and_ready_to_assimilate = true;
|
2010-01-23 00:36:12 +00:00
|
|
|
// used for the defer assimilation
|
|
|
|
double most_recently_returned = 0;
|
2004-08-13 15:52:55 +00:00
|
|
|
for (i=0; i<items.size(); i++) {
|
|
|
|
TRANSITIONER_ITEM& res_item = items[i];
|
2009-09-18 15:59:40 +00:00
|
|
|
if (!res_item.res_id) continue;
|
|
|
|
if (res_item.res_server_state == RESULT_SERVER_STATE_OVER) {
|
2010-01-22 23:55:50 +00:00
|
|
|
if (res_item.res_received_time > most_recently_returned) {
|
2009-09-18 15:59:40 +00:00
|
|
|
most_recently_returned = res_item.res_received_time;
|
|
|
|
}
|
|
|
|
if (res_item.res_outcome == RESULT_OUTCOME_SUCCESS) {
|
|
|
|
if (res_item.res_validate_state == VALIDATE_STATE_INIT) {
|
|
|
|
all_over_and_validated = false;
|
|
|
|
all_over_and_ready_to_assimilate = false;
|
2009-09-17 17:56:59 +00:00
|
|
|
}
|
2010-01-22 23:55:50 +00:00
|
|
|
} else if (res_item.res_outcome == RESULT_OUTCOME_NO_REPLY) {
|
2010-01-23 00:36:12 +00:00
|
|
|
if ((res_item.res_report_deadline + config.grace_period_hours*3600) > now) {
|
2009-09-18 15:59:40 +00:00
|
|
|
all_over_and_validated = false;
|
2004-04-09 06:01:25 +00:00
|
|
|
}
|
2004-07-02 23:04:16 +00:00
|
|
|
}
|
2009-09-18 15:59:40 +00:00
|
|
|
} else {
|
|
|
|
all_over_and_validated = false;
|
|
|
|
all_over_and_ready_to_assimilate = false;
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-23 00:36:12 +00:00
|
|
|
// If we are deferring assimilation until all results are over
|
2008-03-07 21:13:01 +00:00
|
|
|
// and validated then when that happens we need to make sure
|
|
|
|
// that it gets advanced to assimilate ready
|
|
|
|
// the items.size is a kludge
|
|
|
|
//
|
2010-01-22 23:55:50 +00:00
|
|
|
if (all_over_and_ready_to_assimilate
|
|
|
|
&& wu_item.assimilate_state == ASSIMILATE_INIT
|
|
|
|
&& items.size() > 0
|
|
|
|
&& wu_item.canonical_resultid > 0
|
2008-03-07 21:13:01 +00:00
|
|
|
) {
|
2009-09-17 17:56:59 +00:00
|
|
|
wu_item.assimilate_state = ASSIMILATE_READY;
|
2008-03-07 21:13:01 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"[WU#%d %s] Deferred assimililation now set to ASSIMILATE_STATE_READY\n",
|
|
|
|
wu_item.id, wu_item.name
|
|
|
|
);
|
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
// if WU is assimilated, trigger file deletion
|
|
|
|
//
|
2010-01-22 23:55:50 +00:00
|
|
|
if (wu_item.assimilate_state == ASSIMILATE_DONE
|
2010-01-23 00:36:12 +00:00
|
|
|
&& ((most_recently_returned + config.delete_delay_hours*3600) < now)
|
2010-01-22 23:55:50 +00:00
|
|
|
) {
|
2003-08-15 20:35:44 +00:00
|
|
|
// can delete input files if all results OVER
|
|
|
|
//
|
2004-08-13 15:52:55 +00:00
|
|
|
if (all_over_and_validated && wu_item.file_delete_state == FILE_DELETE_INIT) {
|
|
|
|
wu_item.file_delete_state = FILE_DELETE_READY;
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2003-10-06 23:42:43 +00:00
|
|
|
"[WU#%d %s] ASSIMILATE_DONE: file_delete_state:=>READY\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name
|
2003-08-15 20:35:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// output of error results can be deleted immediately;
|
|
|
|
// output of success results can be deleted if validated
|
2003-08-08 08:57:16 +00:00
|
|
|
//
|
2004-08-13 15:52:55 +00:00
|
|
|
for (i=0; i<items.size(); i++) {
|
|
|
|
TRANSITIONER_ITEM& res_item = items[i];
|
2003-09-20 17:38:13 +00:00
|
|
|
|
2003-09-11 09:25:26 +00:00
|
|
|
// can delete canonical result outputs only if all successful
|
|
|
|
// results have been validated
|
2003-09-20 17:38:13 +00:00
|
|
|
//
|
2004-07-02 19:45:33 +00:00
|
|
|
if (((int)i == canonical_result_index) && !all_over_and_validated) {
|
2004-04-09 06:01:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-09-11 09:35:19 +00:00
|
|
|
|
2010-01-22 23:55:50 +00:00
|
|
|
if (!res_item.res_id) continue;
|
|
|
|
do_delete = false;
|
|
|
|
switch(res_item.res_outcome) {
|
|
|
|
case RESULT_OUTCOME_CLIENT_ERROR:
|
|
|
|
do_delete = true;
|
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_SUCCESS:
|
|
|
|
do_delete = (res_item.res_validate_state != VALIDATE_STATE_INIT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (do_delete && res_item.res_file_delete_state == FILE_DELETE_INIT) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] file_delete_state:=>READY\n",
|
|
|
|
wu_item.id, wu_item.name, res_item.res_id, res_item.res_name
|
|
|
|
);
|
|
|
|
res_item.res_file_delete_state = FILE_DELETE_READY;
|
2004-07-02 23:27:15 +00:00
|
|
|
|
2010-01-22 23:55:50 +00:00
|
|
|
retval = transitioner.update_result(res_item);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] result.update() == %d\n",
|
|
|
|
wu_item.id, wu_item.name, res_item.res_id, res_item.res_name, retval
|
|
|
|
);
|
2003-10-06 23:42:43 +00:00
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
2002-11-03 23:05:12 +00:00
|
|
|
}
|
2010-01-22 23:55:50 +00:00
|
|
|
} else if (wu_item.assimilate_state == ASSIMILATE_DONE) {
|
2009-09-17 17:56:59 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2010-01-23 00:36:12 +00:00
|
|
|
"[WU#%d %s] not checking for results ready for delete because deferred delete time has not expired. That will occur in %d seconds\n",
|
2007-06-20 22:34:06 +00:00
|
|
|
wu_item.id,
|
|
|
|
wu_item.name,
|
2010-01-23 00:36:12 +00:00
|
|
|
most_recently_returned + config.delete_delay_hours*3600-now
|
2007-06-20 22:34:06 +00:00
|
|
|
);
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2005-02-08 00:39:05 +00:00
|
|
|
// compute next transition time = minimum timeout of in-progress results
|
|
|
|
//
|
2010-01-25 23:35:16 +00:00
|
|
|
if (wu_item.canonical_resultid || wu_item.error_mask) {
|
2006-05-23 06:08:55 +00:00
|
|
|
wu_item.transition_time = INT_MAX;
|
|
|
|
} else {
|
2010-01-25 23:35:16 +00:00
|
|
|
// If there is no canonical result and no WU-level error,
|
|
|
|
// make sure that the transitioner will process this WU again.
|
|
|
|
// In principle this is not needed, but it makes
|
2006-05-23 06:08:55 +00:00
|
|
|
// the BOINC back-end more robust.
|
|
|
|
//
|
|
|
|
const int ten_days = 10*86400;
|
2006-06-07 18:47:37 +00:00
|
|
|
int long_delay = (int)(1.5*wu_item.delay_bound);
|
2006-05-23 06:08:55 +00:00
|
|
|
wu_item.transition_time = (long_delay > ten_days) ? long_delay : ten_days;
|
|
|
|
wu_item.transition_time += time(0);
|
2007-01-30 18:19:30 +00:00
|
|
|
}
|
2007-04-05 17:02:01 +00:00
|
|
|
int max_grace_or_delay_time = 0;
|
2004-08-13 15:52:55 +00:00
|
|
|
for (i=0; i<items.size(); i++) {
|
|
|
|
TRANSITIONER_ITEM& res_item = items[i];
|
2010-01-22 23:55:50 +00:00
|
|
|
if (!res_item.res_id) continue;
|
|
|
|
if (res_item.res_server_state == RESULT_SERVER_STATE_IN_PROGRESS) {
|
|
|
|
// In cases where a result has been RESENT to a host, the
|
|
|
|
// report deadline time may be EARLIER than
|
|
|
|
// sent_time + delay_bound
|
|
|
|
// because the sent_time has been updated with the later
|
|
|
|
// "resend" time.
|
|
|
|
//
|
|
|
|
// x = res_item.res_sent_time + wu_item.delay_bound;
|
|
|
|
x = res_item.res_report_deadline;
|
|
|
|
if (x < wu_item.transition_time) {
|
|
|
|
wu_item.transition_time = x;
|
|
|
|
}
|
|
|
|
} else if (res_item.res_server_state == RESULT_SERVER_STATE_OVER) {
|
|
|
|
if (res_item.res_outcome == RESULT_OUTCOME_NO_REPLY) {
|
|
|
|
// Transition again after the grace period has expired
|
2007-01-30 18:19:30 +00:00
|
|
|
//
|
2010-01-23 00:36:12 +00:00
|
|
|
x = res_item.res_report_deadline + config.grace_period_hours*3600;
|
|
|
|
if (x > now) {
|
2010-01-22 23:55:50 +00:00
|
|
|
if (x > max_grace_or_delay_time) {
|
|
|
|
max_grace_or_delay_time = x;
|
2009-09-17 17:56:59 +00:00
|
|
|
}
|
2010-01-22 23:55:50 +00:00
|
|
|
}
|
|
|
|
} else if (res_item.res_outcome == RESULT_OUTCOME_SUCCESS
|
|
|
|
|| res_item.res_outcome == RESULT_OUTCOME_CLIENT_ERROR
|
|
|
|
|| res_item.res_outcome == RESULT_OUTCOME_VALIDATE_ERROR
|
|
|
|
) {
|
2010-01-23 00:36:12 +00:00
|
|
|
// Transition again after deferred delete period has expired
|
2010-01-22 23:55:50 +00:00
|
|
|
//
|
2010-01-23 00:36:12 +00:00
|
|
|
x = res_item.res_received_time + config.delete_delay_hours*3600;
|
|
|
|
if (x > now) {
|
2010-01-22 23:55:50 +00:00
|
|
|
if (x > max_grace_or_delay_time && res_item.res_received_time > 0) {
|
|
|
|
max_grace_or_delay_time = x;
|
2009-09-17 17:56:59 +00:00
|
|
|
}
|
2007-04-05 17:02:01 +00:00
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2009-09-17 17:56:59 +00:00
|
|
|
|
2008-03-03 19:33:32 +00:00
|
|
|
// If either of the grace period or delete delay is less than
|
|
|
|
// the next transition time then use that value
|
|
|
|
//
|
2010-01-23 00:36:12 +00:00
|
|
|
if (max_grace_or_delay_time < wu_item.transition_time
|
|
|
|
&& max_grace_or_delay_time > now
|
|
|
|
&& ninprogress == 0
|
|
|
|
) {
|
2007-04-05 17:02:01 +00:00
|
|
|
wu_item.transition_time = max_grace_or_delay_time;
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2010-01-23 00:36:12 +00:00
|
|
|
"[WU#%d %s] Delaying transition due to grace period or delete delay. New transition time: %d\n",
|
2008-02-21 21:00:58 +00:00
|
|
|
wu_item.id, wu_item.name, wu_item.transition_time
|
|
|
|
);
|
2007-04-05 17:02:01 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
// If transition time is in the past,
|
|
|
|
// the system is bogged down and behind schedule.
|
2008-03-03 19:33:32 +00:00
|
|
|
// Delay processing of the WU by an amount DOUBLE the amount we are behind,
|
|
|
|
// but not less than 60 secs or more than one day.
|
|
|
|
//
|
2005-07-14 20:22:53 +00:00
|
|
|
if (wu_item.transition_time < now) {
|
|
|
|
int extra_delay = 2*(now - wu_item.transition_time);
|
|
|
|
if (extra_delay < 60) extra_delay = 60;
|
|
|
|
if (extra_delay > 86400) extra_delay = 86400;
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2005-07-14 20:22:53 +00:00
|
|
|
"[WU#%d %s] transition time in past: adding extra delay %d sec\n",
|
|
|
|
wu_item.id, wu_item.name, extra_delay
|
|
|
|
);
|
|
|
|
wu_item.transition_time = now + extra_delay;
|
2004-08-13 15:52:55 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2004-08-13 15:52:55 +00:00
|
|
|
"[WU#%d %s] setting transition_time to %d\n",
|
|
|
|
wu_item.id, wu_item.name, wu_item.transition_time
|
|
|
|
);
|
|
|
|
|
2005-03-30 06:36:11 +00:00
|
|
|
retval = transitioner.update_workunit(wu_item, wu_item_original);
|
2003-01-23 08:07:48 +00:00
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2004-08-13 15:52:55 +00:00
|
|
|
"[WU#%d %s] workunit.update() == %d\n",
|
|
|
|
wu_item.id, wu_item.name, retval
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2004-07-21 21:50:25 +00:00
|
|
|
return retval;
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2004-07-21 21:50:25 +00:00
|
|
|
return 0;
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
bool do_pass() {
|
2004-07-03 23:41:59 +00:00
|
|
|
int retval;
|
2004-07-02 17:53:31 +00:00
|
|
|
DB_TRANSITIONER_ITEM_SET transitioner;
|
2004-07-02 19:45:33 +00:00
|
|
|
std::vector<TRANSITIONER_ITEM> items;
|
2003-01-23 08:07:48 +00:00
|
|
|
bool did_something = false;
|
|
|
|
|
2005-07-17 19:52:44 +00:00
|
|
|
if (!one_pass) check_stop_daemons();
|
2004-06-29 06:21:05 +00:00
|
|
|
|
2004-07-02 17:53:31 +00:00
|
|
|
// loop over entries that are due to be checked
|
2003-01-23 08:07:48 +00:00
|
|
|
//
|
2008-10-27 21:23:07 +00:00
|
|
|
while (1) {
|
|
|
|
retval = transitioner.enumerate(
|
|
|
|
(int)time(0), SELECT_LIMIT, mod_n, mod_i, items
|
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
if (retval != ERR_DB_NOT_FOUND) {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"WU enum error%d; exiting\n", retval
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
did_something = true;
|
2004-08-13 15:52:55 +00:00
|
|
|
TRANSITIONER_ITEM& wu_item = items[0];
|
2005-08-11 23:53:24 +00:00
|
|
|
retval = handle_wu(transitioner, items);
|
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2005-08-11 23:53:24 +00:00
|
|
|
"[WU#%d %s] handle_wu: %d; quitting\n",
|
|
|
|
wu_item.id, wu_item.name, retval
|
|
|
|
);
|
|
|
|
exit(1);
|
2004-07-22 17:43:11 +00:00
|
|
|
}
|
2005-08-11 23:53:24 +00:00
|
|
|
|
|
|
|
if (!one_pass) check_stop_daemons();
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
return did_something;
|
|
|
|
}
|
|
|
|
|
2005-07-17 19:52:44 +00:00
|
|
|
void main_loop() {
|
2002-11-07 19:31:34 +00:00
|
|
|
int retval;
|
|
|
|
|
2004-01-15 23:53:13 +00:00
|
|
|
retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd);
|
2002-11-07 19:31:34 +00:00
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL, "boinc_db.open: %d\n", retval);
|
2002-11-07 19:31:34 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-07-17 19:52:44 +00:00
|
|
|
while (1) {
|
2008-03-03 19:33:32 +00:00
|
|
|
log_messages.printf(MSG_DEBUG, "doing a pass\n");
|
2005-07-17 19:52:44 +00:00
|
|
|
if (!do_pass()) {
|
|
|
|
if (one_pass) break;
|
2008-09-22 17:52:41 +00:00
|
|
|
#ifdef GCL_SIMULATOR
|
|
|
|
continue_simulation("transitioner");
|
|
|
|
signal(SIGUSR2, simulator_signal_handler);
|
|
|
|
pause();
|
|
|
|
#else
|
2008-11-26 19:09:27 +00:00
|
|
|
log_messages.printf(MSG_DEBUG, "sleeping %d\n", sleep_interval);
|
|
|
|
sleep(sleep_interval);
|
2008-09-22 17:52:41 +00:00
|
|
|
#endif
|
2003-06-11 23:12:51 +00:00
|
|
|
}
|
2002-10-24 08:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 17:56:59 +00:00
|
|
|
void usage(char *name) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Handles transitions in the state of a WU\n"
|
|
|
|
" - a result has become DONE (via timeout or client reply)\n"
|
|
|
|
" - the WU error mask is set (e.g. by validater)\n"
|
|
|
|
" - assimilation is finished\n\n"
|
|
|
|
"Usage: %s [OPTION]...\n\n"
|
|
|
|
"Options: \n"
|
|
|
|
" [ -one_pass ] do one pass, then exit\n"
|
|
|
|
" [ -d x ] debug level x\n"
|
|
|
|
" [ -mod n i ] process only WUs with (id mod n) == i\n"
|
|
|
|
" [ -sleep_interval x ] sleep x seconds if nothing to do\n"
|
|
|
|
" [ -h | -help | --help ] Show this help text.\n"
|
|
|
|
" [ -v | -version | --version ] Shows version information.\n",
|
|
|
|
name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2002-10-24 08:25:42 +00:00
|
|
|
int main(int argc, char** argv) {
|
2002-11-07 19:31:34 +00:00
|
|
|
int i, retval;
|
|
|
|
char path[256];
|
|
|
|
|
2002-11-05 18:36:09 +00:00
|
|
|
startup_time = time(0);
|
|
|
|
for (i=1; i<argc; i++) {
|
2007-04-18 20:49:58 +00:00
|
|
|
if (!strcmp(argv[i], "-one_pass")) {
|
2002-12-24 03:03:45 +00:00
|
|
|
one_pass = true;
|
2003-06-11 23:12:48 +00:00
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
2009-09-17 17:56:59 +00:00
|
|
|
if(!argv[++i]) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
log_messages.set_debug_level(atoi(argv[i]));
|
2004-06-27 23:26:52 +00:00
|
|
|
} else if (!strcmp(argv[i], "-mod")) {
|
2009-09-17 17:56:59 +00:00
|
|
|
if(!argv[i+1] || !argv[i+2]) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "%s requires two arguments\n\n", argv[i]);
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-06-27 23:26:52 +00:00
|
|
|
mod_n = atoi(argv[++i]);
|
|
|
|
mod_i = atoi(argv[++i]);
|
|
|
|
do_mod = true;
|
2008-11-26 19:09:27 +00:00
|
|
|
} else if (!strcmp(argv[i], "-sleep_interval")) {
|
2009-09-17 17:56:59 +00:00
|
|
|
if(!argv[++i]) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
sleep_interval = atoi(argv[i]);
|
|
|
|
} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(0);
|
|
|
|
} else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "-version") || !strcmp(argv[i], "--version")) {
|
|
|
|
printf("%s\n", SVN_VERSION);
|
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "unknown command line argument: %s\n\n", argv[i]);
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
2002-11-05 18:36:09 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-17 19:52:44 +00:00
|
|
|
if (!one_pass) check_stop_daemons();
|
2003-02-10 19:51:32 +00:00
|
|
|
|
2009-05-07 13:54:51 +00:00
|
|
|
retval = config.parse_file();
|
2003-02-10 19:51:32 +00:00
|
|
|
if (retval) {
|
2009-05-07 13:54:51 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL, "Can't parse config.xml: %s\n", boincerror(retval));
|
2003-02-10 19:51:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(path, "%s/upload_private", config.key_dir);
|
|
|
|
retval = read_key_file(path, key);
|
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL, "can't read key\n");
|
2003-02-10 19:51:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL, "Starting\n");
|
2003-06-11 23:12:54 +00:00
|
|
|
|
2003-12-31 23:09:21 +00:00
|
|
|
install_stop_signal_handler();
|
2003-02-27 19:29:48 +00:00
|
|
|
|
2005-07-17 19:52:44 +00:00
|
|
|
main_loop();
|
2002-10-24 08:25:42 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_be98c91511 = "$Id$";
|