2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +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:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-06-11 23:36:50 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +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:36:50 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-06-11 23:36:48 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-06-11 23:36:50 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-12-03 18:57:40 +00:00
|
|
|
// Handle a scheduling server RPC
|
|
|
|
|
2002-09-26 23:12:13 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
#include <stdio.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <time.h>
|
2002-07-11 01:09:53 +00:00
|
|
|
#include <assert.h>
|
2003-03-27 18:10:12 +00:00
|
|
|
#include <math.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "backend_lib.h"
|
2003-10-21 04:06:55 +00:00
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
2003-04-03 18:35:40 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "server_types.h"
|
2003-06-11 23:36:40 +00:00
|
|
|
#include "sched_util.h"
|
2002-10-04 20:35:56 +00:00
|
|
|
#include "main.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "handle_request.h"
|
|
|
|
|
2003-08-09 00:11:32 +00:00
|
|
|
const int MIN_SECONDS_TO_SEND = 0;
|
|
|
|
const int MAX_SECONDS_TO_SEND = (28*SECONDS_PER_DAY);
|
|
|
|
const int MAX_WUS_TO_SEND = 10;
|
2003-12-23 19:21:52 +00:00
|
|
|
const int MIN_SENDWORK_INTERVAL = 15*60;
|
2003-08-09 00:11:32 +00:00
|
|
|
|
2003-09-07 09:11:41 +00:00
|
|
|
const double COBBLESTONE_FACTOR = 300.0;
|
2003-09-06 01:46:08 +00:00
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
struct WORK_REQ {
|
|
|
|
bool infeasible_only;
|
|
|
|
double seconds_to_fill;
|
|
|
|
double disk_available;
|
|
|
|
int nresults;
|
|
|
|
|
|
|
|
// the following flags are set whenever a result is infeasible;
|
|
|
|
// used to construct explanatory message to user
|
|
|
|
//
|
|
|
|
bool insufficient_disk;
|
|
|
|
bool insufficient_mem;
|
|
|
|
bool insufficient_speed;
|
|
|
|
bool no_app_version;
|
|
|
|
};
|
|
|
|
|
2003-11-04 22:22:06 +00:00
|
|
|
// compute the max disk usage we can request of the host
|
|
|
|
//
|
|
|
|
double max_allowable_disk(USER& user, SCHEDULER_REQUEST& req) {
|
|
|
|
GLOBAL_PREFS prefs;
|
|
|
|
HOST host = req.host;
|
2003-11-07 00:54:53 +00:00
|
|
|
double x1, x2, x3, x;
|
2003-11-04 22:22:06 +00:00
|
|
|
|
|
|
|
prefs.parse(user.global_prefs);
|
|
|
|
|
|
|
|
// fill in default values for missing prefs
|
|
|
|
//
|
2003-11-11 23:14:49 +00:00
|
|
|
if (prefs.disk_max_used_gb == 0) prefs.disk_max_used_gb = 0.1; // 100 MB
|
2003-11-04 22:22:06 +00:00
|
|
|
if (prefs.disk_max_used_pct == 0) prefs.disk_max_used_pct = 10;
|
|
|
|
// min_free_gb can be zero
|
|
|
|
|
|
|
|
// default values for BOINC disk usage (project and total) is zero
|
|
|
|
//
|
|
|
|
|
|
|
|
// no defaults for total/free disk space (host.d_total, d_free)
|
|
|
|
// if they're zero, project will get no work.
|
|
|
|
//
|
|
|
|
|
|
|
|
x1 = prefs.disk_max_used_gb*1e9 - req.total_disk_usage;
|
|
|
|
x2 = host.d_total*prefs.disk_max_used_pct/100.;
|
|
|
|
x3 = host.d_free - prefs.disk_min_free_gb*1e9; // may be negative
|
|
|
|
|
2003-11-07 00:54:53 +00:00
|
|
|
x = min(x1, min(x2, x3));
|
|
|
|
if (x < 0) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"disk_max_used_gb %f disk_max_used_pct %f disk_min_free_gb %f\n",
|
|
|
|
prefs.disk_max_used_gb, prefs.disk_max_used_pct,
|
|
|
|
prefs.disk_min_free_gb
|
|
|
|
);
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"req.total_disk_usage %f host.d_total %f host.d_free %f\n",
|
|
|
|
req.total_disk_usage, host.d_total, host.d_free
|
|
|
|
);
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"x1 %f x2 %f x3 %f x %f\n",
|
|
|
|
x1, x2, x3, x
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return x;
|
2003-11-04 22:22:06 +00:00
|
|
|
}
|
|
|
|
|
2003-12-24 21:49:35 +00:00
|
|
|
// if a host has active_frac < 0.1, assume 0.1 so we don't deprive it of work.
|
2003-11-04 22:22:06 +00:00
|
|
|
//
|
2003-12-24 21:49:35 +00:00
|
|
|
const double HOST_ACTIVE_FRAC_MIN = 0.1;
|
2003-08-09 00:11:32 +00:00
|
|
|
|
|
|
|
// estimate the number of seconds that a workunit requires running 100% on a
|
|
|
|
// single CPU of this host.
|
|
|
|
//
|
|
|
|
// TODO: improve this. take memory bandwidth into account
|
|
|
|
//
|
2003-12-24 21:49:35 +00:00
|
|
|
inline double estimate_cpu_duration(WORKUNIT& wu, HOST& host) {
|
2003-08-09 00:11:32 +00:00
|
|
|
if (host.p_fpops <= 0) host.p_fpops = 1e9;
|
2003-09-04 00:41:51 +00:00
|
|
|
if (wu.rsc_fpops_est <= 0) wu.rsc_fpops_est = 1e12;
|
|
|
|
return wu.rsc_fpops_est/host.p_fpops;
|
2003-08-09 00:11:32 +00:00
|
|
|
}
|
|
|
|
|
2003-12-24 21:49:35 +00:00
|
|
|
// estimate the amount of real time for this WU based on active_frac
|
2003-11-04 22:22:06 +00:00
|
|
|
//
|
2003-08-09 00:11:32 +00:00
|
|
|
inline double estimate_wallclock_duration(WORKUNIT& wu, HOST& host) {
|
2003-12-24 21:49:35 +00:00
|
|
|
return estimate_cpu_duration(wu, host)
|
|
|
|
/ max(HOST_ACTIVE_FRAC_MIN, host.active_frac)
|
|
|
|
;
|
2003-08-09 00:11:32 +00:00
|
|
|
|
|
|
|
}
|
2002-06-04 23:56:07 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// return true if the WU can be executed on the host
|
|
|
|
//
|
2003-11-11 23:14:49 +00:00
|
|
|
bool wu_is_feasible(WORKUNIT& wu, HOST& host, WORK_REQ& wreq) {
|
2003-09-04 00:41:51 +00:00
|
|
|
if (host.m_nbytes && wu.rsc_memory_bound > host.m_nbytes) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2003-08-09 00:11:32 +00:00
|
|
|
SchedMessages::DEBUG, "[WU#%d %s] needs %f mem; [HOST#%d] has %f\n",
|
2003-09-04 00:41:51 +00:00
|
|
|
wu.id, wu.name, wu.rsc_memory_bound, host.id, host.m_nbytes
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.insufficient_mem = true;
|
2003-02-28 22:39:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-08-09 00:11:32 +00:00
|
|
|
double wu_wallclock_time = estimate_wallclock_duration(wu, host);
|
|
|
|
int host_remaining_time = 0; // TODO
|
|
|
|
|
|
|
|
if (host_remaining_time + wu_wallclock_time > wu.delay_bound) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::DEBUG, "[WU#%d %s] needs requires %d seconds on [HOST#%d]; delay_bound is %d\n",
|
2003-08-12 20:58:24 +00:00
|
|
|
wu.id, wu.name, (int)wu_wallclock_time, host.id, wu.delay_bound
|
|
|
|
);
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.insufficient_speed = true;
|
2003-08-09 00:11:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-10-09 04:56:41 +00:00
|
|
|
// insert "text" right after "after" in the given buffer
|
2002-07-29 00:39:45 +00:00
|
|
|
//
|
2002-10-09 04:56:41 +00:00
|
|
|
int insert_after(char* buffer, char* after, char* text) {
|
|
|
|
char* p;
|
2003-12-07 18:58:08 +00:00
|
|
|
char temp[MEDIUM_BLOB_SIZE];
|
2002-10-09 04:56:41 +00:00
|
|
|
|
2003-12-07 18:58:08 +00:00
|
|
|
if (strlen(buffer) + strlen(text) > MEDIUM_BLOB_SIZE-1) {
|
2003-06-11 23:36:50 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "insert_after: overflow\n");
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_BUFFER_OVERFLOW;
|
2003-01-15 23:54:24 +00:00
|
|
|
}
|
2002-10-09 04:56:41 +00:00
|
|
|
p = strstr(buffer, after);
|
2003-01-15 23:54:24 +00:00
|
|
|
if (!p) {
|
2003-06-11 23:36:50 +00:00
|
|
|
log_messages.printf(SchedMessages::CRITICAL, "insert_after: %s not found in %s\n", after, buffer);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_NULL;
|
2003-01-15 23:54:24 +00:00
|
|
|
}
|
2002-10-09 04:56:41 +00:00
|
|
|
p += strlen(after);
|
|
|
|
strcpy(temp, p);
|
|
|
|
strcpy(p, text);
|
|
|
|
strcat(p, temp);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-20 00:30:13 +00:00
|
|
|
|
2003-05-21 23:23:42 +00:00
|
|
|
// add elements to WU's xml_doc, in preparation for sending
|
|
|
|
// it to a client
|
2002-10-09 04:56:41 +00:00
|
|
|
//
|
2003-05-21 23:23:42 +00:00
|
|
|
int insert_wu_tags(WORKUNIT& wu, APP& app) {
|
2003-12-07 18:58:08 +00:00
|
|
|
char buf[MEDIUM_BLOB_SIZE];
|
2002-10-09 04:56:41 +00:00
|
|
|
|
|
|
|
sprintf(buf,
|
2003-09-04 00:41:51 +00:00
|
|
|
" <rsc_fpops_est>%f</rsc_fpops_est>\n"
|
|
|
|
" <rsc_fpops_bound>%f</rsc_fpops_bound>\n"
|
|
|
|
" <rsc_memory_bound>%f</rsc_memory_bound>\n"
|
|
|
|
" <rsc_disk_bound>%f</rsc_disk_bound>\n"
|
2003-05-21 23:23:42 +00:00
|
|
|
" <name>%s</name>\n"
|
|
|
|
" <app_name>%s</app_name>\n",
|
2003-09-04 00:41:51 +00:00
|
|
|
wu.rsc_fpops_est,
|
|
|
|
wu.rsc_fpops_bound,
|
|
|
|
wu.rsc_memory_bound,
|
|
|
|
wu.rsc_disk_bound,
|
2003-05-21 23:23:42 +00:00
|
|
|
wu.name,
|
|
|
|
app.name
|
2002-11-07 19:31:34 +00:00
|
|
|
);
|
2002-10-09 04:56:41 +00:00
|
|
|
return insert_after(wu.xml_doc, "<workunit>\n", buf);
|
2002-06-21 18:31:32 +00:00
|
|
|
}
|
|
|
|
|
2003-11-25 21:10:54 +00:00
|
|
|
// return the APP and APP_VERSION for the given WU, for the given platform.
|
|
|
|
// return false if none
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2003-11-25 21:10:54 +00:00
|
|
|
bool find_app_version(
|
|
|
|
WORK_REQ& wreq, WORKUNIT& wu, PLATFORM& platform, SCHED_SHMEM& ss,
|
|
|
|
APP*& app, APP_VERSION*& avp
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
2002-05-24 04:29:10 +00:00
|
|
|
app = ss.lookup_app(wu.appid);
|
2003-01-14 23:42:47 +00:00
|
|
|
if (!app) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL, "Can't find APP#%d\n", wu.appid
|
|
|
|
);
|
2003-11-25 21:10:54 +00:00
|
|
|
return false;
|
2003-01-14 23:42:47 +00:00
|
|
|
}
|
2003-05-21 00:13:55 +00:00
|
|
|
avp = ss.lookup_app_version(app->id, platform.id, app->min_version);
|
|
|
|
if (!avp) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2003-11-11 23:14:49 +00:00
|
|
|
SchedMessages::DEBUG,
|
|
|
|
"no app version available: APP#%d PLATFORM#%d min_version %d\n",
|
2003-06-14 17:46:08 +00:00
|
|
|
app->id, platform.id, app->min_version
|
|
|
|
);
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.no_app_version = true;
|
2003-11-25 21:10:54 +00:00
|
|
|
return false;
|
2003-01-14 23:42:47 +00:00
|
|
|
}
|
2003-11-25 21:10:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the given workunit to a reply.
|
|
|
|
// look up its app, and make sure there's a version for this platform.
|
|
|
|
// Add the app and app_version to the reply also.
|
|
|
|
//
|
|
|
|
int add_wu_to_reply(
|
|
|
|
WORKUNIT& wu, SCHEDULER_REPLY& reply, PLATFORM& platform, SCHED_SHMEM& ss,
|
|
|
|
WORK_REQ& wreq, APP* app, APP_VERSION* avp
|
|
|
|
) {
|
|
|
|
int retval;
|
|
|
|
WORKUNIT wu2;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// add the app, app_version, and workunit to the reply,
|
|
|
|
// but only if they aren't already there
|
2003-05-20 00:03:39 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
reply.insert_app_unique(*app);
|
2003-05-20 00:03:39 +00:00
|
|
|
|
2003-11-02 23:08:06 +00:00
|
|
|
reply.insert_app_version_unique(*avp);
|
2003-12-06 01:49:30 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::DEBUG,
|
|
|
|
"[HOST#%d] Sending app_version %s %s %d\n",
|
|
|
|
reply.host.id, app->name, platform.name, avp->version_num
|
|
|
|
);
|
2002-06-21 18:31:32 +00:00
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
// add time estimate to reply
|
|
|
|
//
|
2002-10-09 04:56:41 +00:00
|
|
|
wu2 = wu; // make copy since we're going to modify its XML field
|
2003-05-21 23:23:42 +00:00
|
|
|
retval = insert_wu_tags(wu2, *app);
|
2003-01-14 23:42:47 +00:00
|
|
|
if (retval) {
|
2003-06-11 23:36:50 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "insert_wu_tags failed\n");
|
2003-01-14 23:42:47 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2002-10-09 04:56:41 +00:00
|
|
|
reply.insert_workunit_unique(wu2);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look up the host and its user, and make sure the authenticator matches.
|
|
|
|
// If no host ID is supplied, or if RPC seqno mismatch,
|
|
|
|
// create a new host record and return its ID
|
|
|
|
//
|
2002-08-26 22:57:17 +00:00
|
|
|
int authenticate_user(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2002-04-30 22:22:54 +00:00
|
|
|
int retval;
|
2003-01-17 18:51:39 +00:00
|
|
|
char buf[256];
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_HOST host;
|
|
|
|
DB_USER user;
|
|
|
|
DB_TEAM team;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
if (sreq.hostid) {
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = host.lookup_id(sreq.hostid);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message, "Can't find host record");
|
|
|
|
strcpy(reply.message_priority, "low");
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[HOST#%d?] can't find host\n",
|
|
|
|
sreq.hostid
|
|
|
|
);
|
2003-04-30 22:08:16 +00:00
|
|
|
sreq.hostid = 0;
|
|
|
|
goto new_host;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.host = host;
|
|
|
|
|
|
|
|
retval = user.lookup_id(reply.host.userid);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message, "Can't find user record");
|
|
|
|
strcpy(reply.message_priority, "low");
|
2003-04-30 22:02:53 +00:00
|
|
|
reply.request_delay = 120;
|
|
|
|
reply.nucleus_only = true;
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[HOST#%d] [USER#%d?] can't find user record\n",
|
|
|
|
host.id, reply.host.userid
|
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.user = user;
|
2002-08-26 22:57:17 +00:00
|
|
|
if (strcmp(sreq.authenticator, reply.user.authenticator)) {
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message,
|
2002-04-30 22:22:54 +00:00
|
|
|
"Invalid or missing authenticator. "
|
2002-05-17 22:33:57 +00:00
|
|
|
"Visit this project's web site to get an authenticator."
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2002-10-15 07:41:33 +00:00
|
|
|
reply.request_delay = 120;
|
2003-04-30 22:02:53 +00:00
|
|
|
reply.nucleus_only = true;
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[HOST#%d] [USER#%d] Bad authenticator '%s'\n",
|
|
|
|
host.id, user.id, sreq.authenticator
|
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_AUTHENTICATOR;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the seqno from the host is less than what we expect,
|
|
|
|
// the user must have copied the state file to a different host.
|
|
|
|
// Make a new host record.
|
2002-08-26 22:57:17 +00:00
|
|
|
if (sreq.rpc_seqno < reply.host.rpc_seqno) {
|
2002-04-30 22:22:54 +00:00
|
|
|
sreq.hostid = 0;
|
|
|
|
goto new_host;
|
|
|
|
}
|
2002-08-26 22:57:17 +00:00
|
|
|
reply.host.rpc_seqno = sreq.rpc_seqno;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
2003-06-04 17:21:26 +00:00
|
|
|
// here no hostid was given; we'll have to create a new host record
|
|
|
|
//
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(
|
2003-06-04 17:21:26 +00:00
|
|
|
user.authenticator, sreq.authenticator,
|
|
|
|
sizeof(user.authenticator)
|
2002-09-22 23:27:14 +00:00
|
|
|
);
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where authenticator='%s'", user.authenticator);
|
|
|
|
retval = user.lookup(buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2002-10-15 07:41:33 +00:00
|
|
|
strcpy(reply.message,
|
2003-03-02 19:24:09 +00:00
|
|
|
"Invalid or missing account ID. "
|
|
|
|
"Visit this project's web site to get an account ID."
|
|
|
|
);
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2002-10-15 07:41:33 +00:00
|
|
|
reply.request_delay = 120;
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[HOST#<none>] Bad authenticator '%s'\n",
|
|
|
|
sreq.authenticator
|
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_AUTHENTICATOR;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.user = user;
|
2002-04-30 22:22:54 +00:00
|
|
|
new_host:
|
2002-08-28 21:50:51 +00:00
|
|
|
// reply.user is filled in and valid at this point
|
|
|
|
//
|
2003-06-04 17:21:26 +00:00
|
|
|
host = sreq.host;
|
|
|
|
host.id = 0;
|
|
|
|
host.create_time = time(0);
|
|
|
|
host.userid = reply.user.id;
|
|
|
|
host.rpc_seqno = 0;
|
|
|
|
strcpy(host.venue, reply.user.venue);
|
|
|
|
retval = host.insert();
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message, "server database error");
|
|
|
|
strcpy(reply.message_priority, "low");
|
2003-09-05 21:26:21 +00:00
|
|
|
boinc_db.print_error("host.insert()");
|
2003-06-11 23:36:50 +00:00
|
|
|
log_messages.printf(SchedMessages::CRITICAL, "host.insert() failed\n");
|
2003-10-21 04:06:55 +00:00
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-09-05 21:26:21 +00:00
|
|
|
host.id = boinc_db.insert_id();
|
2003-06-04 17:21:26 +00:00
|
|
|
|
|
|
|
reply.host = host;
|
2002-08-28 21:50:51 +00:00
|
|
|
reply.hostid = reply.host.id;
|
|
|
|
// this tells client to updates its host ID
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-02-24 21:31:36 +00:00
|
|
|
if (reply.user.teamid) {
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = team.lookup_id(reply.user.teamid);
|
2003-02-24 21:31:36 +00:00
|
|
|
if (!retval) reply.team = team;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
// somewhat arbitrary formula for credit as a function of CPU time.
|
|
|
|
// Could also include terms for RAM size, network speed etc.
|
|
|
|
//
|
|
|
|
static void compute_credit_rating(HOST& host) {
|
2003-06-11 23:36:45 +00:00
|
|
|
host.credit_per_cpu_sec =
|
2003-09-06 01:46:08 +00:00
|
|
|
(fabs(host.p_fpops)/1e9 + fabs(host.p_iops)/1e9 + fabs(host.p_membw)/4e9)
|
2003-09-07 09:11:41 +00:00
|
|
|
* COBBLESTONE_FACTOR / (3 * SECONDS_PER_DAY);
|
2002-09-26 05:57:10 +00:00
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// Update host record based on request.
|
|
|
|
// Copy all fields that are determined by the client.
|
|
|
|
//
|
2003-06-04 17:21:26 +00:00
|
|
|
int update_host_record(SCHEDULER_REQUEST& sreq, HOST& xhost) {
|
2002-04-30 22:22:54 +00:00
|
|
|
int retval;
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_HOST host;
|
|
|
|
host = xhost;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
host.timezone = sreq.host.timezone;
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.domain_name, sreq.host.domain_name, sizeof(host.domain_name));
|
|
|
|
strncpy(host.serialnum, sreq.host.serialnum, sizeof(host.serialnum));
|
2002-04-30 22:22:54 +00:00
|
|
|
if (strcmp(host.last_ip_addr, sreq.host.last_ip_addr)) {
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.last_ip_addr, sreq.host.last_ip_addr, sizeof(host.last_ip_addr));
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
host.nsame_ip_addr++;
|
|
|
|
}
|
|
|
|
host.on_frac = sreq.host.on_frac;
|
|
|
|
host.connected_frac = sreq.host.connected_frac;
|
|
|
|
host.active_frac = sreq.host.active_frac;
|
|
|
|
host.p_ncpus = sreq.host.p_ncpus;
|
2003-03-02 19:24:09 +00:00
|
|
|
strncpy(host.p_vendor, sreq.host.p_vendor, sizeof(host.p_vendor));
|
|
|
|
// unlikely this will change
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.p_model, sreq.host.p_model, sizeof(host.p_model));
|
2002-04-30 22:22:54 +00:00
|
|
|
host.p_fpops = sreq.host.p_fpops;
|
|
|
|
host.p_iops = sreq.host.p_iops;
|
|
|
|
host.p_membw = sreq.host.p_membw;
|
2002-06-21 18:31:32 +00:00
|
|
|
host.p_calculated = sreq.host.p_calculated;
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.os_name, sreq.host.os_name, sizeof(host.os_name));
|
|
|
|
strncpy(host.os_version, sreq.host.os_version, sizeof(host.os_version));
|
2002-04-30 22:22:54 +00:00
|
|
|
host.m_nbytes = sreq.host.m_nbytes;
|
|
|
|
host.m_cache = sreq.host.m_cache;
|
|
|
|
host.m_swap = sreq.host.m_swap;
|
|
|
|
host.d_total = sreq.host.d_total;
|
|
|
|
host.d_free = sreq.host.d_free;
|
|
|
|
host.n_bwup = sreq.host.n_bwup;
|
|
|
|
host.n_bwdown = sreq.host.n_bwdown;
|
2002-09-26 05:57:10 +00:00
|
|
|
|
|
|
|
compute_credit_rating(host);
|
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = host.update();
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2003-06-11 23:36:50 +00:00
|
|
|
log_messages.printf(SchedMessages::CRITICAL, "host.update() failed: %d\n", retval);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// Deal with global preferences.
|
2002-09-27 20:36:03 +00:00
|
|
|
// If the client sent global prefs, and they're more recent than ours,
|
2002-06-01 20:26:21 +00:00
|
|
|
// update user record in DB.
|
2002-09-29 00:32:11 +00:00
|
|
|
// If DB has more recent global prefs than client's, send them.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2002-09-27 20:36:03 +00:00
|
|
|
int handle_global_prefs(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2002-09-29 00:32:11 +00:00
|
|
|
reply.send_global_prefs = false;
|
2003-04-03 18:35:40 +00:00
|
|
|
if (strlen(sreq.global_prefs_xml)) {
|
2003-07-26 01:35:48 +00:00
|
|
|
bool need_update = false;
|
|
|
|
unsigned req_mod_time=0, db_mod_time=0;
|
|
|
|
parse_int(sreq.global_prefs_xml, "<mod_time>", (int&)req_mod_time);
|
2002-09-29 00:32:11 +00:00
|
|
|
if (strlen(reply.user.global_prefs)) {
|
2003-07-26 01:35:48 +00:00
|
|
|
parse_int(reply.user.global_prefs, "<mod_time>", (int&)db_mod_time);
|
2002-09-29 00:32:11 +00:00
|
|
|
if (req_mod_time > db_mod_time) {
|
|
|
|
need_update = true;
|
|
|
|
} else if (req_mod_time < db_mod_time) {
|
|
|
|
reply.send_global_prefs = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (need_update) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(reply.user.global_prefs, sreq.global_prefs_xml);
|
2003-07-26 01:35:48 +00:00
|
|
|
DB_USER user;
|
2003-06-04 17:21:26 +00:00
|
|
|
user = reply.user;
|
|
|
|
user.update();
|
2002-09-29 00:32:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strlen(reply.user.global_prefs)) {
|
|
|
|
reply.send_global_prefs = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle completed results
|
|
|
|
//
|
2002-09-26 05:57:10 +00:00
|
|
|
int handle_results(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, HOST& host
|
|
|
|
) {
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_RESULT result;
|
|
|
|
RESULT* rp;
|
|
|
|
DB_WORKUNIT wu;
|
2003-01-07 01:02:08 +00:00
|
|
|
char buf[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
for (i=0; i<sreq.results.size(); i++) {
|
|
|
|
rp = &sreq.results[i];
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2002-10-09 04:56:41 +00:00
|
|
|
// acknowledge the result even if we couldn't find it --
|
|
|
|
// don't want it to keep coming back
|
|
|
|
//
|
|
|
|
reply.result_acks.push_back(*rp);
|
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(result.name, rp->name, sizeof(result.name));
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where name='%s'", result.name);
|
|
|
|
retval = result.lookup(buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[HOST#%d] [RESULT#? %s] can't find result\n",
|
|
|
|
host.id, rp->name
|
|
|
|
);
|
2003-01-07 22:49:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2003-06-15 00:09:05 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL, "[HOST#%d] [RESULT#%d %s] got result\n",
|
|
|
|
host.id, result.id, result.name
|
|
|
|
);
|
|
|
|
|
2003-01-23 08:07:48 +00:00
|
|
|
if (result.server_state == RESULT_SERVER_STATE_UNSENT) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[HOST#%d] [RESULT#%d %s] got unexpected result: server state is %d\n",
|
|
|
|
host.id, result.id, result.name, result.server_state
|
|
|
|
);
|
2003-01-07 22:49:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-08-13 00:37:00 +00:00
|
|
|
|
2003-01-07 22:49:42 +00:00
|
|
|
if (result.hostid != sreq.hostid) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[HOST#%d] [RESULT#%d %s] got result from wrong host; expected [HOST#%d]\n",
|
|
|
|
host.id, result.id, result.name, result.hostid
|
|
|
|
);
|
2003-06-14 17:46:09 +00:00
|
|
|
DB_HOST result_host;
|
|
|
|
int retval = result_host.lookup_id(result.hostid);
|
|
|
|
|
|
|
|
if (retval) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[RESULT#%d %s] Can't lookup [HOST#%d]\n",
|
|
|
|
result.id, result.name, result.hostid
|
|
|
|
);
|
2003-06-14 17:46:09 +00:00
|
|
|
continue;
|
|
|
|
} else if (result_host.userid != host.userid) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[USER#%d] [HOST#%d] [RESULT#%d %s] Not even the same user; expected [USER#%d]\n",
|
|
|
|
host.userid, host.id, result.id, result.name, result_host.userid
|
|
|
|
);
|
2003-06-14 17:46:09 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[HOST#%d] [RESULT#%d %s] Allowing result because same USER#%d\n",
|
|
|
|
host.id, result.id, result.name, host.userid
|
|
|
|
);
|
2003-06-14 17:46:09 +00:00
|
|
|
}
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2002-09-22 23:27:14 +00:00
|
|
|
|
2003-12-23 19:21:52 +00:00
|
|
|
// look for exit status in stderr_out
|
|
|
|
// TODO: return separately
|
|
|
|
//
|
|
|
|
parse_int(result.stderr_out, "<exit_status>", result.exit_status);
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// update the result record in DB
|
|
|
|
//
|
2003-01-07 22:49:42 +00:00
|
|
|
result.hostid = reply.host.id;
|
|
|
|
result.received_time = time(0);
|
|
|
|
result.client_state = rp->client_state;
|
|
|
|
result.cpu_time = rp->cpu_time;
|
|
|
|
result.claimed_credit = result.cpu_time * host.credit_per_cpu_sec;
|
2003-01-23 08:07:48 +00:00
|
|
|
result.server_state = RESULT_SERVER_STATE_OVER;
|
2003-06-11 23:36:45 +00:00
|
|
|
// TODO: if client application aborted e.g. exceeded resource limits,
|
|
|
|
// should client_state be RESULT_OUTCOME_CLIENT_ERROR ?
|
2003-02-06 01:02:56 +00:00
|
|
|
if (result.client_state == RESULT_FILES_UPLOADED) {
|
2003-01-23 08:07:48 +00:00
|
|
|
result.outcome = RESULT_OUTCOME_SUCCESS;
|
2003-01-07 22:49:42 +00:00
|
|
|
} else {
|
2003-01-23 08:07:48 +00:00
|
|
|
result.outcome = RESULT_OUTCOME_CLIENT_ERROR;
|
|
|
|
result.validate_state = VALIDATE_STATE_INVALID;
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
|
|
|
strncpy(result.stderr_out, rp->stderr_out, sizeof(result.stderr_out));
|
|
|
|
strncpy(result.xml_doc_out, rp->xml_doc_out, sizeof(result.xml_doc_out));
|
2003-07-25 20:48:29 +00:00
|
|
|
result.client_version_num =
|
|
|
|
sreq.core_client_major_version*100 + sreq.core_client_minor_version;
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = result.update();
|
2003-01-07 22:49:42 +00:00
|
|
|
if (retval) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[HOST#%d] [RESULT#%d %s] can't update result: %s\n",
|
2003-09-05 21:26:21 +00:00
|
|
|
host.id, result.id, result.name, boinc_db.error_string()
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
// trigger the transition handle for the result's WU
|
|
|
|
//
|
|
|
|
retval = wu.lookup_id(result.workunitid);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[HOST#%d] [RESULT#%d %s] Can't find [WU#%d] for result\n",
|
|
|
|
host.id, result.id, result.name, result.workunitid
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
wu.transition_time = time(0);
|
|
|
|
retval = wu.update();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"[HOST#%d] [RESULT#%d %s] Can't update [WU#%d %s]\n",
|
|
|
|
host.id, result.id, result.name, wu.id, wu.name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-07 22:48:36 +00:00
|
|
|
int insert_name_tags(RESULT& result, WORKUNIT const& wu) {
|
2002-10-09 04:56:41 +00:00
|
|
|
char buf[256];
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
sprintf(buf, "<name>%s</name>\n", result.name);
|
|
|
|
retval = insert_after(result.xml_doc_in, "<result>\n", buf);
|
|
|
|
if (retval) return retval;
|
|
|
|
sprintf(buf, "<wu_name>%s</wu_name>\n", wu.name);
|
|
|
|
retval = insert_after(result.xml_doc_in, "<result>\n", buf);
|
|
|
|
if (retval) return retval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-07 22:48:36 +00:00
|
|
|
int insert_deadline_tag(RESULT& result) {
|
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "<report_deadline>%d</report_deadline>\n", result.report_deadline);
|
|
|
|
int retval = insert_after(result.xml_doc_in, "<result>\n", buf);
|
|
|
|
if (retval) return retval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
static int update_wu_transition_time(WORKUNIT wu, time_t x) {
|
2003-11-28 23:25:36 +00:00
|
|
|
// TODO: this might be better: a mysql statement such as "update set
|
|
|
|
// transition_time=X where id=ID and transition_time<X". this avoids
|
|
|
|
// concurrency problems altogether.
|
2003-08-15 20:35:44 +00:00
|
|
|
DB_WORKUNIT dbwu;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = dbwu.lookup_id(wu.id);
|
|
|
|
if (retval) return retval;
|
|
|
|
if (x < dbwu.transition_time) {
|
|
|
|
dbwu.transition_time = x;
|
|
|
|
retval = dbwu.update();
|
|
|
|
if (retval) return retval;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-07 04:35:56 +00:00
|
|
|
// return true iff a result for same WU is already being sent
|
|
|
|
//
|
|
|
|
static bool already_in_reply(WU_RESULT& wu_result, SCHEDULER_REPLY& reply) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<reply.results.size(); i++) {
|
|
|
|
if (wu_result.workunit.id == reply.results[i].workunitid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-09-21 21:00:25 +00:00
|
|
|
// Make a pass through the wu/results array, sending work.
|
|
|
|
// If "infeasible_only" is true, send only results that were
|
|
|
|
// previously infeasible for some host
|
|
|
|
//
|
|
|
|
static void scan_work_array(
|
2003-11-11 23:14:49 +00:00
|
|
|
WORK_REQ& wreq,
|
2002-04-30 22:22:54 +00:00
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, PLATFORM& platform,
|
2003-11-11 23:14:49 +00:00
|
|
|
SCHED_SHMEM& ss
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
2003-10-16 18:10:56 +00:00
|
|
|
int i, retval, n;
|
2002-04-30 22:22:54 +00:00
|
|
|
WORKUNIT wu;
|
2003-10-07 04:35:56 +00:00
|
|
|
DB_RESULT result;
|
|
|
|
double wu_seconds_filled;
|
2003-10-16 18:10:56 +00:00
|
|
|
char buf[256];
|
2003-11-25 21:10:54 +00:00
|
|
|
APP* app;
|
|
|
|
APP_VERSION* avp;
|
|
|
|
bool found;
|
2003-01-07 22:49:42 +00:00
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
if (wreq.disk_available < 0) wreq.insufficient_disk = true;
|
2003-11-07 00:54:53 +00:00
|
|
|
|
2003-11-04 22:22:06 +00:00
|
|
|
for (i=0; i<ss.nwu_results; i++) {
|
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
if (wreq.seconds_to_fill <= 0) break;
|
|
|
|
if (wreq.disk_available <= 0) break;
|
2003-11-04 22:22:06 +00:00
|
|
|
|
2003-09-21 21:00:25 +00:00
|
|
|
WU_RESULT& wu_result = ss.wu_results[i];
|
2002-05-24 04:29:10 +00:00
|
|
|
|
|
|
|
// the following should be a critical section
|
|
|
|
//
|
2003-09-21 21:00:25 +00:00
|
|
|
if (!wu_result.present) {
|
|
|
|
continue;
|
|
|
|
}
|
2003-10-07 04:35:56 +00:00
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
if (wu_result.workunit.rsc_disk_bound > wreq.disk_available) {
|
|
|
|
wreq.insufficient_disk = true;
|
2003-11-04 22:22:06 +00:00
|
|
|
wu_result.infeasible_count++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
if (wreq.infeasible_only && wu_result.infeasible_count==0) {
|
2003-01-14 23:42:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-08-09 00:11:32 +00:00
|
|
|
|
2003-10-07 04:35:56 +00:00
|
|
|
// don't send if we're already sending a result for same WU
|
|
|
|
//
|
|
|
|
if (already_in_reply(wu_result, reply)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-10-17 20:09:14 +00:00
|
|
|
// don't send if we've already sent a result of this WU to this user
|
2003-10-16 18:10:56 +00:00
|
|
|
//
|
2003-10-16 19:03:49 +00:00
|
|
|
if (config.one_result_per_user_per_wu) {
|
|
|
|
sprintf(buf,
|
|
|
|
"where workunitid=%d and userid=%d",
|
|
|
|
wu_result.workunit.id, reply.user.id
|
2003-10-16 18:10:56 +00:00
|
|
|
);
|
2003-10-16 19:03:49 +00:00
|
|
|
retval = result.count(n, buf);
|
|
|
|
if (retval) {
|
2003-10-16 18:10:56 +00:00
|
|
|
log_messages.printf(
|
2003-10-16 19:03:49 +00:00
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"send_work: can't get result count (%d)\n", retval
|
2003-10-16 18:10:56 +00:00
|
|
|
);
|
2003-10-16 19:03:49 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (n>0) {
|
2003-10-24 20:13:50 +00:00
|
|
|
#if 0
|
2003-10-16 19:03:49 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
2003-10-19 03:52:28 +00:00
|
|
|
"send_work: user %d already has %d result(s) for WU %d\n",
|
2003-10-16 19:03:49 +00:00
|
|
|
reply.user.id, n, wu_result.workunit.id
|
|
|
|
);
|
2003-10-24 20:13:50 +00:00
|
|
|
#endif
|
2003-10-16 19:03:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-10-16 18:10:56 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-17 20:09:14 +00:00
|
|
|
|
2003-10-19 03:52:28 +00:00
|
|
|
// don't send if host can't handle it
|
2003-10-16 18:10:56 +00:00
|
|
|
//
|
2003-10-07 04:35:56 +00:00
|
|
|
wu = wu_result.workunit;
|
2003-11-11 23:14:49 +00:00
|
|
|
if (!wu_is_feasible(wu, reply.host, wreq)) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::DEBUG, "[HOST#%d] [WU#%d %s] WU is infeasible\n",
|
|
|
|
reply.host.id, wu.id, wu.name
|
|
|
|
);
|
2003-09-21 21:00:25 +00:00
|
|
|
wu_result.infeasible_count++;
|
2002-08-28 21:50:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-10-09 04:56:41 +00:00
|
|
|
|
2003-11-25 21:10:54 +00:00
|
|
|
// Find the app and app_version for the client's platform.
|
|
|
|
// If none, treat the WU as infeasible
|
2003-10-07 04:35:56 +00:00
|
|
|
//
|
2003-11-25 21:10:54 +00:00
|
|
|
found = find_app_version(wreq, wu, platform, ss, app, avp);
|
|
|
|
if (!found) {
|
2003-09-21 22:33:43 +00:00
|
|
|
wu_result.infeasible_count++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-10-07 04:35:56 +00:00
|
|
|
result = wu_result.result;
|
|
|
|
|
|
|
|
// mark slot as empty AFTER we've copied out of it
|
2003-11-04 22:22:06 +00:00
|
|
|
// (since otherwise feeder might overwrite it)
|
2003-10-07 04:35:56 +00:00
|
|
|
//
|
2003-09-21 22:33:43 +00:00
|
|
|
wu_result.present = false;
|
2002-10-09 04:56:41 +00:00
|
|
|
|
2003-10-07 04:35:56 +00:00
|
|
|
// reread result from DB, make sure it's still unsent
|
|
|
|
// TODO: from here to update() should be a transaction
|
|
|
|
//
|
|
|
|
retval = result.lookup_id(result.id);
|
|
|
|
if (retval) continue;
|
|
|
|
if (result.server_state != RESULT_SERVER_STATE_UNSENT) continue;
|
2002-11-07 19:31:34 +00:00
|
|
|
|
2003-11-04 22:22:06 +00:00
|
|
|
// ****** HERE WE'VE COMMITTED TO SENDING THIS RESULT TO HOST ******
|
|
|
|
//
|
|
|
|
|
2003-11-25 21:10:54 +00:00
|
|
|
retval = add_wu_to_reply(wu, reply, platform, ss, wreq, app, avp);
|
|
|
|
if (retval) continue;
|
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.disk_available -= wu.rsc_disk_bound;
|
2003-11-04 22:22:06 +00:00
|
|
|
|
2003-10-07 04:35:56 +00:00
|
|
|
// update the result in DB
|
|
|
|
//
|
2003-08-07 22:48:36 +00:00
|
|
|
result.server_state = RESULT_SERVER_STATE_IN_PROGRESS;
|
|
|
|
result.hostid = reply.host.id;
|
2003-10-16 18:10:56 +00:00
|
|
|
result.userid = reply.user.id;
|
2003-08-07 22:48:36 +00:00
|
|
|
result.sent_time = time(0);
|
|
|
|
result.report_deadline = result.sent_time + wu.delay_bound;
|
|
|
|
result.update();
|
|
|
|
|
2003-12-24 21:49:35 +00:00
|
|
|
wu_seconds_filled = estimate_cpu_duration(wu, reply.host);
|
2003-10-07 04:35:56 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"[HOST#%d] Sending [RESULT#%d %s] (fills %d seconds)\n",
|
|
|
|
reply.host.id, result.id, result.name, int(wu_seconds_filled)
|
|
|
|
);
|
|
|
|
|
2003-08-15 20:35:44 +00:00
|
|
|
retval = update_wu_transition_time(wu, result.report_deadline);
|
|
|
|
if (retval) {
|
2003-09-21 21:00:25 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"send_work: can't update WU transition time\n"
|
|
|
|
);
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 04:35:56 +00:00
|
|
|
// The following overwrites the result's xml_doc field.
|
|
|
|
// But that's OK cuz we're done with DB updates
|
2002-11-07 19:31:34 +00:00
|
|
|
//
|
2003-10-07 04:35:56 +00:00
|
|
|
retval = insert_name_tags(result, wu);
|
2002-10-09 04:56:41 +00:00
|
|
|
if (retval) {
|
2003-10-07 04:35:56 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL, "send_work: can't insert name tags\n"
|
|
|
|
);
|
2003-08-07 22:48:36 +00:00
|
|
|
}
|
2003-10-07 04:35:56 +00:00
|
|
|
retval = insert_deadline_tag(result);
|
2003-08-07 22:48:36 +00:00
|
|
|
if (retval) {
|
2003-10-07 04:35:56 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL,
|
|
|
|
"send_work: can't insert deadline tag\n"
|
|
|
|
);
|
2002-10-09 04:56:41 +00:00
|
|
|
}
|
2003-10-07 04:35:56 +00:00
|
|
|
reply.insert_result(result);
|
2002-11-07 19:31:34 +00:00
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.seconds_to_fill -= wu_seconds_filled;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.nresults++;
|
|
|
|
if (wreq.nresults == MAX_WUS_TO_SEND) break;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-09-21 21:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int send_work(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, PLATFORM& platform,
|
|
|
|
SCHED_SHMEM& ss
|
|
|
|
) {
|
2003-11-11 23:14:49 +00:00
|
|
|
WORK_REQ wreq;
|
2003-11-04 22:22:06 +00:00
|
|
|
|
2003-11-25 21:10:54 +00:00
|
|
|
memset(&wreq, 0, sizeof(wreq));
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.disk_available = max_allowable_disk(reply.user, sreq);
|
|
|
|
wreq.insufficient_disk = false;
|
|
|
|
wreq.insufficient_mem = false;
|
|
|
|
wreq.insufficient_speed = false;
|
|
|
|
wreq.no_app_version = false;
|
2003-11-25 21:10:54 +00:00
|
|
|
wreq.nresults = 0;
|
2003-09-21 21:00:25 +00:00
|
|
|
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
2003-11-04 22:22:06 +00:00
|
|
|
"[HOST#%d] got request for %d seconds of work; available disk %f GB\n",
|
2003-11-11 23:14:49 +00:00
|
|
|
reply.host.id, sreq.work_req_seconds, wreq.disk_available/1e9
|
2003-09-21 21:00:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (sreq.work_req_seconds <= 0) return 0;
|
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.seconds_to_fill = sreq.work_req_seconds;
|
|
|
|
if (wreq.seconds_to_fill > MAX_SECONDS_TO_SEND) {
|
|
|
|
wreq.seconds_to_fill = MAX_SECONDS_TO_SEND;
|
2003-09-21 21:00:25 +00:00
|
|
|
}
|
2003-11-11 23:14:49 +00:00
|
|
|
if (wreq.seconds_to_fill < MIN_SECONDS_TO_SEND) {
|
|
|
|
wreq.seconds_to_fill = MIN_SECONDS_TO_SEND;
|
2003-09-21 21:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// give priority to results that were infeasible for some other host
|
|
|
|
//
|
2003-11-11 23:14:49 +00:00
|
|
|
wreq.infeasible_only = true;
|
|
|
|
scan_work_array(wreq, sreq, reply, platform, ss);
|
|
|
|
|
|
|
|
wreq.infeasible_only = false;
|
|
|
|
scan_work_array(wreq, sreq, reply, platform, ss);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL, "[HOST#%d] Sent %d results\n",
|
2003-11-25 21:10:54 +00:00
|
|
|
reply.host.id, wreq.nresults
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2003-01-07 22:49:42 +00:00
|
|
|
|
2003-11-11 23:14:49 +00:00
|
|
|
if (wreq.nresults == 0) {
|
2003-11-07 00:54:53 +00:00
|
|
|
strcpy(reply.message, "No work available");
|
2003-11-11 23:14:49 +00:00
|
|
|
if (wreq.no_app_version) {
|
|
|
|
strcat(reply.message,
|
|
|
|
" (there was work for other platforms)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (wreq.insufficient_disk) {
|
|
|
|
strcat(reply.message,
|
|
|
|
" (there was work but you don't have enough disk space allocated)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (wreq.insufficient_mem) {
|
|
|
|
strcat(reply.message,
|
|
|
|
" (there was work but your computer doesn't have enough memory)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (wreq.insufficient_mem) {
|
2003-11-07 00:54:53 +00:00
|
|
|
strcat(reply.message,
|
2003-11-11 23:14:49 +00:00
|
|
|
" (there was work but your computer would not finish it before it is due"
|
2003-11-07 00:54:53 +00:00
|
|
|
);
|
|
|
|
}
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2002-04-30 22:22:54 +00:00
|
|
|
reply.request_delay = 10;
|
2003-06-11 23:36:53 +00:00
|
|
|
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2003-11-07 00:54:53 +00:00
|
|
|
SchedMessages::NORMAL, "[HOST#%d] %s\n",
|
|
|
|
reply.host.id, reply.message
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
// if the client has an old code sign public key,
|
2002-07-07 20:39:24 +00:00
|
|
|
// send it the new one, with a signature based on the old one.
|
|
|
|
// If they don't have a code sign key, send them one
|
|
|
|
//
|
|
|
|
void send_code_sign_key(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, char* code_sign_key
|
|
|
|
) {
|
|
|
|
char* oldkey, *signature;
|
|
|
|
int i, retval;
|
|
|
|
char path[256];
|
|
|
|
|
2003-04-03 18:35:40 +00:00
|
|
|
if (strlen(sreq.code_sign_key)) {
|
2002-07-07 20:39:24 +00:00
|
|
|
if (strcmp(sreq.code_sign_key, code_sign_key)) {
|
2003-06-11 23:36:50 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "received old code sign key\n");
|
2003-04-03 18:35:40 +00:00
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
// look for a signature file
|
|
|
|
//
|
|
|
|
for (i=0; ; i++) {
|
2002-10-04 20:35:56 +00:00
|
|
|
sprintf(path, "%s/old_key_%d", config.key_dir, i);
|
2002-07-07 20:39:24 +00:00
|
|
|
retval = read_file_malloc(path, oldkey);
|
|
|
|
if (retval) {
|
|
|
|
strcpy(reply.message,
|
2003-10-19 04:00:48 +00:00
|
|
|
"Can't update code signing key. "
|
|
|
|
"Please report this to the project administrators."
|
2002-07-07 20:39:24 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!strcmp(oldkey, sreq.code_sign_key)) {
|
2002-10-04 20:35:56 +00:00
|
|
|
sprintf(path, "%s/signature_%d", config.key_dir, i);
|
2002-07-07 20:39:24 +00:00
|
|
|
retval = read_file_malloc(path, signature);
|
|
|
|
if (retval) {
|
|
|
|
strcpy(reply.message,
|
2003-10-19 04:00:48 +00:00
|
|
|
"Can't update code signing key. "
|
|
|
|
"Please report this to the project administrators."
|
2002-07-07 20:39:24 +00:00
|
|
|
);
|
|
|
|
} else {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(reply.code_sign_key, code_sign_key);
|
|
|
|
safe_strcpy(reply.code_sign_key_signature, signature);
|
|
|
|
free(signature);
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(oldkey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(reply.code_sign_key, code_sign_key);
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
bool wrong_major_version(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2003-06-11 23:36:51 +00:00
|
|
|
// char buf[256];
|
2002-12-02 04:29:40 +00:00
|
|
|
if (sreq.core_client_major_version != MAJOR_VERSION) {
|
|
|
|
reply.nucleus_only = true;
|
2003-08-15 22:39:56 +00:00
|
|
|
// TODO: check for user-agent not empty and not BOINC
|
|
|
|
reply.probable_user_browser = true;
|
2002-12-02 04:29:40 +00:00
|
|
|
sprintf(reply.message,
|
|
|
|
"To participate in this project, "
|
|
|
|
"you must use major version %d of the BOINC core client. "
|
|
|
|
"Your core client is major version %d.",
|
|
|
|
MAJOR_VERSION,
|
|
|
|
sreq.core_client_major_version
|
|
|
|
);
|
2003-05-12 20:46:21 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
2003-09-21 22:33:43 +00:00
|
|
|
"[HOST#%d] [auth %s] Wrong major version from user: wanted %d, got %d\n",
|
|
|
|
sreq.hostid, sreq.authenticator,
|
2003-09-06 01:46:08 +00:00
|
|
|
MAJOR_VERSION, sreq.core_client_major_version
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2002-12-02 04:29:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2002-10-22 21:44:16 +00:00
|
|
|
|
2003-09-21 22:33:43 +00:00
|
|
|
inline static const char* get_remote_addr() {
|
2003-07-29 01:05:13 +00:00
|
|
|
const char * r = getenv("REMOTE_ADDR");
|
|
|
|
return r ? r : "?.?.?.?";
|
2003-07-25 20:48:29 +00:00
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
void process_request(
|
2002-07-07 20:39:24 +00:00
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss,
|
|
|
|
char* code_sign_key
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
|
|
|
PLATFORM* platform;
|
2002-06-21 18:31:32 +00:00
|
|
|
int retval;
|
2003-12-23 19:21:52 +00:00
|
|
|
double last_rpc_time;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
// if different major version of BOINC, just send a message
|
|
|
|
//
|
|
|
|
if (wrong_major_version(sreq, reply)) return;
|
2003-06-11 23:36:45 +00:00
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
retval = authenticate_user(sreq, reply);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) return;
|
|
|
|
|
2003-12-23 19:21:52 +00:00
|
|
|
last_rpc_time = reply.host.rpc_time;
|
|
|
|
reply.host.rpc_time = time(0);
|
2002-08-26 22:57:17 +00:00
|
|
|
retval = update_host_record(sreq, reply.host);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// look up the client's platform in the DB
|
|
|
|
//
|
2002-05-24 04:29:10 +00:00
|
|
|
platform = ss.lookup_platform(sreq.platform_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!platform) {
|
2003-07-29 01:09:53 +00:00
|
|
|
sprintf(reply.message, "platform '%s' not found", sreq.platform_name);
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::CRITICAL, "[HOST#%d] platform '%s' not found\n",
|
|
|
|
reply.host.id, sreq.platform_name
|
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-25 20:48:29 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL, "Processing request from [USER#%d] [HOST#%d] [IP %s] [RPC#%d] core client version %d.%02d\n",
|
2003-07-26 00:04:48 +00:00
|
|
|
reply.user.id, reply.host.id,
|
2003-07-25 20:48:29 +00:00
|
|
|
get_remote_addr(),
|
|
|
|
sreq.rpc_seqno,
|
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version
|
|
|
|
);
|
|
|
|
++log_messages;
|
2002-09-27 20:36:03 +00:00
|
|
|
handle_global_prefs(sreq, reply);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
handle_results(sreq, reply, reply.host);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-12-23 19:21:52 +00:00
|
|
|
// if last RPC was within MIN_SENDWORK_INTERVAL, don't send work
|
|
|
|
//
|
|
|
|
double diff = dtime() - last_rpc_time;
|
|
|
|
if (diff < MIN_SENDWORK_INTERVAL) {
|
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL,
|
|
|
|
"Not sending work - last RPC too recent: %f\n", diff
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
send_work(sreq, reply, *platform, ss);
|
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
|
|
|
|
send_code_sign_key(sreq, reply, code_sign_key);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
void handle_request(
|
|
|
|
FILE* fin, FILE* fout, SCHED_SHMEM& ss, char* code_sign_key
|
|
|
|
) {
|
2002-04-30 22:22:54 +00:00
|
|
|
SCHEDULER_REQUEST sreq;
|
|
|
|
SCHEDULER_REPLY sreply;
|
2002-08-20 00:30:13 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
memset(&sreq, 0, sizeof(sreq));
|
|
|
|
sreq.parse(fin);
|
2003-10-17 17:22:49 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SchedMessages::NORMAL, "Handling request: IP %s, auth %s, platform %s, version %d.%d\n",
|
|
|
|
get_remote_addr(), sreq.authenticator, sreq.platform_name,
|
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version
|
|
|
|
);
|
2002-07-07 20:39:24 +00:00
|
|
|
process_request(sreq, sreply, ss, code_sign_key);
|
2002-04-30 22:22:54 +00:00
|
|
|
sreply.write(fout);
|
|
|
|
}
|