2004-12-02 23:00:30 +00:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-11-20 07:32:32 +00:00
|
|
|
static volatile const char *BOINCrcsid="$Id$";
|
2003-06-11 23:12:55 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-12-03 18:57:40 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-06-11 23:12:55 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-06-11 23:12:57 +00:00
|
|
|
//
|
2002-12-03 18:57:40 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-06-11 23:12:57 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-12-03 18:57:40 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-06-11 23:12:55 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-06-11 23:12:57 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-12-03 18:57:40 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
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:
|
2002-11-07 19:31:34 +00:00
|
|
|
// [ -asynch ] be asynchronous
|
2003-08-15 20:35:44 +00:00
|
|
|
// [ -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
|
2002-10-24 08:25:42 +00:00
|
|
|
|
2002-11-08 08:54:16 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2002-11-05 18:36:09 +00:00
|
|
|
#include <vector>
|
2002-11-07 19:31:34 +00:00
|
|
|
#include <unistd.h>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <climits>
|
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"
|
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"
|
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
|
2004-12-06 22:41:19 +00:00
|
|
|
#define SLEEP_INTERVAL 5
|
2004-07-21 21:50:25 +00:00
|
|
|
#define BATCH_INSERT 1
|
|
|
|
|
2002-11-05 18:36:09 +00:00
|
|
|
int startup_time;
|
2003-09-02 21:16:55 +00:00
|
|
|
SCHED_CONFIG config;
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
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-04-09 06:01:25 +00:00
|
|
|
bool all_over_and_validated, have_result_to_validate, do_delete;
|
2004-08-13 15:52:55 +00:00
|
|
|
unsigned int i;
|
2002-10-24 08:25:42 +00:00
|
|
|
|
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;
|
2003-08-15 20:35:44 +00:00
|
|
|
have_result_to_validate = false;
|
2004-07-16 21:23:43 +00:00
|
|
|
int rs, max_result_suffix = -1;
|
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
TRANSITIONER_ITEM& wu_item = items[0];
|
|
|
|
|
|
|
|
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++;
|
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;
|
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) {
|
2004-07-16 21:23:43 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::NORMAL,
|
|
|
|
"[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) {
|
2003-10-06 23:42:43 +00:00
|
|
|
log_messages.printf(
|
2004-07-16 21:23:43 +00:00
|
|
|
SCHED_MSG_LOG::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-07-02 23:27:15 +00:00
|
|
|
nover++;
|
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:
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::NORMAL,
|
|
|
|
"[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) {
|
2004-07-16 21:23:43 +00:00
|
|
|
have_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;
|
2004-12-02 23:00:30 +00:00
|
|
|
case RESULT_OUTCOME_NO_REPLY:
|
|
|
|
nno_reply++;
|
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_DIDNT_NEED:
|
|
|
|
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
|
|
|
|
2003-10-10 20:10:18 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::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",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, ntotal,
|
2004-12-02 23:00:30 +00:00
|
|
|
nunsent, ninprogress, nover, nsuccess, nerrors, ncouldnt_send, nno_reply, ndidnt_need
|
2003-10-10 20:10:18 +00:00
|
|
|
);
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// trigger validation if we have a quorum
|
|
|
|
// and some result hasn't been validated
|
2003-01-23 08:07:48 +00:00
|
|
|
//
|
2004-08-13 15:52:55 +00:00
|
|
|
if (nsuccess >= wu_item.min_quorum && have_result_to_validate) {
|
|
|
|
wu_item.need_validate = true;
|
2003-10-10 05:36:09 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
2003-10-10 05:36:09 +00:00
|
|
|
"[WU#%d %s] need_validate:=>true [nsuccess=%d >= min_quorum=%d]\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, nsuccess, wu_item.min_quorum
|
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
|
|
|
}
|
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
if (nerrors > wu_item.max_error_results) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
2003-06-14 20:15:53 +00:00
|
|
|
"[WU#%d %s] WU has too many errors (%d errors for %d results)\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, nerrors, (int)items.size()
|
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
|
|
|
}
|
2004-08-13 15:52:55 +00:00
|
|
|
if ((int)items.size() > wu_item.max_total_results) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
2003-08-15 20:35:44 +00:00
|
|
|
"[WU#%d %s] WU has too many total results (%d)\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, (int)items.size()
|
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];
|
|
|
|
if (res_item.res_id) {
|
2004-07-02 23:27:15 +00:00
|
|
|
bool update_result = false;
|
2004-08-13 15:52:55 +00:00
|
|
|
if (res_item.res_server_state == RESULT_SERVER_STATE_UNSENT) {
|
2003-10-06 23:42:43 +00:00
|
|
|
log_messages.printf(
|
2004-07-02 23:27:15 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] server_state:UNSENT=>OVER; outcome:=>DIDNT_NEED\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-02 19:45:33 +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_DIDNT_NEED;
|
2004-07-02 23:27:15 +00:00
|
|
|
update_result = true;
|
|
|
|
}
|
2004-10-15 23:02:44 +00:00
|
|
|
if ((res_item.res_validate_state == VALIDATE_STATE_INIT) &&
|
|
|
|
(res_item.res_outcome != RESULT_OUTCOME_SUCCESS)) {
|
2004-08-13 15:52:55 +00:00
|
|
|
res_item.res_validate_state = VALIDATE_STATE_NO_CHECK;
|
2004-07-02 23:27:15 +00:00
|
|
|
update_result = true;
|
|
|
|
}
|
|
|
|
if (update_result) {
|
2004-08-13 15:52:55 +00:00
|
|
|
retval = transitioner.update_result(res_item);
|
2004-07-02 23:27:15 +00:00
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] result.update() == %d\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, res_item.res_id, res_item.res_name, retval
|
2004-07-02 23:27:15 +00:00
|
|
|
);
|
|
|
|
}
|
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;
|
2003-10-10 05:36:09 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::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
|
|
|
}
|
2004-08-13 15:52:55 +00:00
|
|
|
} else if (wu_item.assimilate_state == ASSIMILATE_INIT) {
|
2003-01-23 08:07:48 +00:00
|
|
|
// If no error, generate new results if needed.
|
2004-07-21 21:50:25 +00:00
|
|
|
// NOTE: n must be signed
|
|
|
|
//
|
2004-08-13 15:52:55 +00:00
|
|
|
int n = wu_item.target_nresults - nunsent - ninprogress - nsuccess;
|
2004-07-21 21:50:25 +00:00
|
|
|
string values;
|
|
|
|
char value_buf[MAX_QUERY_LEN];
|
2003-08-15 20:35:44 +00:00
|
|
|
if (n > 0) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::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",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, n, wu_item.target_nresults, nunsent, ninprogress, nsuccess
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2004-08-13 15:52:55 +00:00
|
|
|
for (j=0; j<n; j++) {
|
|
|
|
sprintf(suffix, "%d", max_result_suffix+j+1);
|
2004-07-02 19:45:33 +00:00
|
|
|
char rtfpath[256];
|
2004-08-13 15:52:55 +00:00
|
|
|
sprintf(rtfpath, "../%s", wu_item.result_template_file);
|
2004-07-21 21:50:25 +00:00
|
|
|
#ifdef BATCH_INSERT
|
2004-07-02 19:45:33 +00:00
|
|
|
retval = create_result(
|
2004-12-06 22:41:19 +00:00
|
|
|
wu_item, rtfpath, suffix, key, config, value_buf
|
2004-07-02 19:45:33 +00:00
|
|
|
);
|
2003-08-15 23:44:28 +00:00
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-08-15 23:44:28 +00:00
|
|
|
"[WU#%d %s] create_result() %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;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
retval = create_result(
|
2004-12-06 22:41:19 +00:00
|
|
|
wu_item, rtfpath, suffix, key, config, 0
|
2004-07-21 21:50:25 +00:00
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[WU#%d %s] create_result() %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;
|
2003-08-15 23:44:28 +00:00
|
|
|
}
|
2004-07-21 21:50:25 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef BATCH_INSERT
|
|
|
|
DB_RESULT r;
|
|
|
|
retval = r.insert_batch(values.c_str());
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[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
|
|
|
}
|
2004-07-21 21:50:25 +00:00
|
|
|
#endif
|
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
|
|
|
|
// - look for canonical result
|
2003-08-15 20:35:44 +00:00
|
|
|
//
|
2004-07-02 17:53:31 +00:00
|
|
|
canonical_result_index = -1;
|
2004-04-09 06:01:25 +00:00
|
|
|
all_over_and_validated = true;
|
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) {
|
|
|
|
if (res_item.res_server_state == RESULT_SERVER_STATE_OVER) {
|
|
|
|
if (res_item.res_outcome == RESULT_OUTCOME_SUCCESS) {
|
|
|
|
if (res_item.res_validate_state == VALIDATE_STATE_INIT) {
|
2004-07-02 23:04:16 +00:00
|
|
|
all_over_and_validated = false;
|
|
|
|
}
|
2004-04-09 06:01:25 +00:00
|
|
|
}
|
2004-07-02 23:04:16 +00:00
|
|
|
} else {
|
|
|
|
all_over_and_validated = false;
|
|
|
|
}
|
2004-08-13 15:52:55 +00:00
|
|
|
if (res_item.res_id == wu_item.canonical_resultid) {
|
2004-07-02 23:04:16 +00:00
|
|
|
canonical_result_index = i;
|
2004-04-09 06:01:25 +00:00
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-13 15:52:55 +00:00
|
|
|
if (wu_item.canonical_resultid && (canonical_result_index == -1)) {
|
2003-08-15 20:35:44 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-08-15 20:35:44 +00:00
|
|
|
"[WU#%d %s] can't find canonical result\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name
|
2003-08-15 20:35:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if WU is assimilated, trigger file deletion
|
|
|
|
//
|
2004-08-13 15:52:55 +00:00
|
|
|
if (wu_item.assimilate_state == ASSIMILATE_DONE) {
|
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;
|
2003-08-15 20:35:44 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::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
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
if (res_item.res_id) {
|
2004-07-02 23:27:15 +00:00
|
|
|
do_delete = false;
|
2004-08-13 15:52:55 +00:00
|
|
|
switch(res_item.res_outcome) {
|
2004-07-02 23:27:15 +00:00
|
|
|
case RESULT_OUTCOME_CLIENT_ERROR:
|
|
|
|
do_delete = true;
|
|
|
|
break;
|
|
|
|
case RESULT_OUTCOME_SUCCESS:
|
2004-08-13 15:52:55 +00:00
|
|
|
do_delete = (res_item.res_validate_state != VALIDATE_STATE_INIT);
|
2004-07-02 23:27:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-13 15:52:55 +00:00
|
|
|
if (do_delete && res_item.res_file_delete_state == FILE_DELETE_INIT) {
|
2003-10-06 23:42:43 +00:00
|
|
|
log_messages.printf(
|
2004-07-02 23:27:15 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] file_delete_state:=>READY\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-02 19:45:33 +00:00
|
|
|
);
|
2004-08-13 15:52:55 +00:00
|
|
|
res_item.res_file_delete_state = FILE_DELETE_READY;
|
2004-07-02 23:27:15 +00:00
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
retval = transitioner.update_result(res_item);
|
2004-07-02 23:27:15 +00:00
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[WU#%d %s] [RESULT#%d %s] result.update() == %d\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, res_item.res_id, res_item.res_name, retval
|
2004-07-02 23:27:15 +00:00
|
|
|
);
|
|
|
|
}
|
2003-10-06 23:42:43 +00:00
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
2002-11-03 23:05:12 +00:00
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.transition_time = INT_MAX;
|
|
|
|
for (i=0; i<items.size(); i++) {
|
|
|
|
TRANSITIONER_ITEM& res_item = items[i];
|
|
|
|
if (res_item.res_id) {
|
|
|
|
if (res_item.res_server_state == RESULT_SERVER_STATE_IN_PROGRESS) {
|
|
|
|
x = res_item.res_sent_time + wu_item.delay_bound;
|
|
|
|
if (x < wu_item.transition_time) {
|
|
|
|
wu_item.transition_time = x;
|
2004-07-02 23:27:15 +00:00
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2004-07-02 17:53:31 +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.
|
|
|
|
// Make sure we don't process this WU again for at least a day.
|
|
|
|
//
|
2004-08-16 14:30:41 +00:00
|
|
|
if (wu_item.transition_time < now + 86400) {
|
|
|
|
wu_item.transition_time = now + 86400;
|
2004-08-13 15:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::DEBUG,
|
|
|
|
"[WU#%d %s] setting transition_time to %d\n",
|
|
|
|
wu_item.id, wu_item.name, wu_item.transition_time
|
|
|
|
);
|
|
|
|
|
|
|
|
retval = transitioner.update_workunit(wu_item);
|
2003-01-23 08:07:48 +00:00
|
|
|
if (retval) {
|
2003-06-14 20:15:53 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::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;
|
|
|
|
|
2004-05-03 19:30:01 +00:00
|
|
|
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
|
|
|
//
|
2004-07-22 19:13:10 +00:00
|
|
|
while (!transitioner.enumerate((int)time(0), SELECT_LIMIT, items)) {
|
2003-01-23 08:07:48 +00:00
|
|
|
did_something = true;
|
2004-07-03 23:35:23 +00:00
|
|
|
|
2004-08-13 15:52:55 +00:00
|
|
|
TRANSITIONER_ITEM& wu_item = items[0];
|
|
|
|
|
|
|
|
// if we are assigned a transitioner number,
|
|
|
|
// limit which records we should looked at.
|
|
|
|
// It'll be less expensive to do the check here than in the DB.
|
|
|
|
// ??? why ???
|
|
|
|
//
|
|
|
|
if ((mod_n == 0) || ((mod_n != 0) && (mod_i == (wu_item.id % mod_n)))) {
|
2004-08-04 10:34:33 +00:00
|
|
|
if (config.use_transactions) {
|
|
|
|
retval = boinc_db.start_transaction();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[WU#%d %s] transitioner.start_transaction() == %d\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, retval
|
2004-08-04 10:34:33 +00:00
|
|
|
);
|
|
|
|
}
|
2004-07-22 17:43:11 +00:00
|
|
|
}
|
2004-07-03 23:35:23 +00:00
|
|
|
|
2004-07-22 17:43:11 +00:00
|
|
|
retval = handle_wu(transitioner, items);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[WU#%d %s] handle_wu: %d; quitting\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, retval
|
2004-07-22 17:43:11 +00:00
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-07-03 23:35:23 +00:00
|
|
|
|
2004-08-04 10:34:33 +00:00
|
|
|
if (config.use_transactions) {
|
|
|
|
retval = boinc_db.commit_transaction();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[WU#%d %s] transitioner.commit_transaction() == %d\n",
|
2004-08-13 15:52:55 +00:00
|
|
|
wu_item.id, wu_item.name, retval
|
2004-08-04 10:34:33 +00:00
|
|
|
);
|
|
|
|
}
|
2004-07-22 17:43:11 +00:00
|
|
|
}
|
|
|
|
check_stop_daemons();
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
}
|
2002-11-07 19:31:34 +00:00
|
|
|
return did_something;
|
|
|
|
}
|
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
void main_loop(bool one_pass) {
|
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) {
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "boinc_db.open: %d\n", retval);
|
2002-11-07 19:31:34 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-06-11 23:12:51 +00:00
|
|
|
if (one_pass) {
|
2003-08-15 20:35:44 +00:00
|
|
|
do_pass();
|
2003-06-11 23:12:51 +00:00
|
|
|
} else {
|
|
|
|
while (1) {
|
2004-12-06 22:41:19 +00:00
|
|
|
if (!do_pass()) sleep(SLEEP_INTERVAL);
|
2003-06-11 23:12:51 +00:00
|
|
|
}
|
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;
|
2002-12-24 03:03:45 +00:00
|
|
|
bool asynch = false, one_pass=false;
|
2002-11-07 19:31:34 +00:00
|
|
|
char path[256];
|
|
|
|
|
2004-05-03 19:30:01 +00:00
|
|
|
check_stop_daemons();
|
2002-11-05 18:36:09 +00:00
|
|
|
startup_time = time(0);
|
|
|
|
for (i=1; i<argc; i++) {
|
2003-08-15 20:35:44 +00:00
|
|
|
if (!strcmp(argv[i], "-asynch")) {
|
2002-11-05 18:36:09 +00:00
|
|
|
asynch = true;
|
2002-12-24 03:03:45 +00:00
|
|
|
} else if (!strcmp(argv[i], "-one_pass")) {
|
|
|
|
one_pass = true;
|
2003-06-11 23:12:48 +00:00
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
2003-06-11 23:12:56 +00:00
|
|
|
log_messages.set_debug_level(atoi(argv[++i]));
|
2004-06-27 23:26:52 +00:00
|
|
|
} else if (!strcmp(argv[i], "-mod")) {
|
|
|
|
mod_n = atoi(argv[++i]);
|
|
|
|
mod_i = atoi(argv[++i]);
|
|
|
|
do_mod = true;
|
2002-11-05 18:36:09 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-10 19:51:32 +00:00
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
retval = config.parse_file("..");
|
2003-02-10 19:51:32 +00:00
|
|
|
if (retval) {
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read config file\n");
|
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) {
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't read key\n");
|
2003-02-10 19:51:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-11-05 18:36:09 +00:00
|
|
|
if (asynch) {
|
2002-12-03 18:57:40 +00:00
|
|
|
if (fork()) {
|
|
|
|
exit(0);
|
2002-11-05 18:36:09 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-27 19:29:48 +00:00
|
|
|
|
2003-06-11 23:12:57 +00:00
|
|
|
// // Call lock_file after fork(), because file locks are not always inherited
|
|
|
|
// if (lock_file(LOCKFILE)) {
|
2004-04-08 08:15:23 +00:00
|
|
|
// log_messages.printf(SCHED_MSG_LOG::NORMAL, "Another copy of transitioner is already running\n");
|
2003-06-11 23:12:57 +00:00
|
|
|
// exit(1);
|
|
|
|
// }
|
|
|
|
// write_pid_file(PIDFILE);
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::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
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
main_loop(one_pass);
|
2002-10-24 08:25:42 +00:00
|
|
|
}
|