svn path=/trunk/boinc/; revision=12532

This commit is contained in:
Matt Lebofsky 2007-05-02 18:51:51 +00:00
parent a100628ee8
commit 846ec9fbb0
7 changed files with 106 additions and 6 deletions

View File

@ -4217,3 +4217,24 @@ Rom 2 May 2007
lib/
str_util.h
Matt 2 May 2007
- updated db/validator to add logic for wuhash table.
wuhash table (see schema.sql) has two fields, user and
project-specific workunit id so that a user's contribution
can be tied to the appropriate workunit ID in the science
database (a different ID than in the BOINC database). This logic
is only enacted with -update_wuhash flag on command line.
The project-specific workunit id is expected to be found
in the workunit.opaque field.
db/
schema.sql
constraints.sql
boinc_db.C,h
sched/
validator.C
html/ops/
db_update.php

View File

@ -61,6 +61,7 @@ void TEAM::clear() {memset(this, 0, sizeof(*this));}
void HOST::clear() {memset(this, 0, sizeof(*this));}
void RESULT::clear() {memset(this, 0, sizeof(*this));}
void WORKUNIT::clear() {memset(this, 0, sizeof(*this));}
void WUHASH::clear() {memset(this, 0, sizeof(*this));}
void MSG_FROM_HOST::clear() {memset(this, 0, sizeof(*this));}
void MSG_TO_HOST::clear() {memset(this, 0, sizeof(*this));}
void TRANSITIONER_ITEM::clear() {memset(this, 0, sizeof(*this));}
@ -81,6 +82,8 @@ DB_HOST::DB_HOST(DB_CONN* dc) :
DB_BASE("host", dc?dc:&boinc_db){}
DB_WORKUNIT::DB_WORKUNIT(DB_CONN* dc) :
DB_BASE("workunit", dc?dc:&boinc_db){}
DB_WUHASH::DB_WUHASH(DB_CONN* dc) :
DB_BASE("wuhash", dc?dc:&boinc_db){}
DB_RESULT::DB_RESULT(DB_CONN* dc) :
DB_BASE("result", dc?dc:&boinc_db){}
DB_MSG_FROM_HOST::DB_MSG_FROM_HOST(DB_CONN* dc) :
@ -686,6 +689,20 @@ void DB_WORKUNIT::db_parse(MYSQL_ROW &r) {
strcpy2(mod_time, r[i++]);
}
void DB_WUHASH::db_print(char* buf){
sprintf(buf,
"userid=%d, workunitid=%d",
userid, workunitid
);
}
void DB_WUHASH::db_parse(MYSQL_ROW &r) {
int i=0;
clear();
userid = atoi(r[i++]);
workunitid = atoi(r[i++]);
};
void DB_RESULT::db_print(char* buf){
ESCAPE(xml_doc_out);
ESCAPE(stderr_out);

View File

@ -374,6 +374,14 @@ struct WORKUNIT {
void clear();
};
struct WUHASH {
int userid;
long workunitid;
// the following not used in the DB
void clear();
};
// WARNING: be Very careful about changing any values,
// especially for a project already running -
// the database will become inconsistent
@ -593,6 +601,14 @@ public:
void operator=(WORKUNIT& w) {WORKUNIT::operator=(w);}
};
class DB_WUHASH : public DB_BASE, public WUHASH {
public:
DB_WUHASH(DB_CONN* p=0);
void db_print(char*);
void db_parse(MYSQL_ROW &row);
void operator=(WUHASH& wh) {WUHASH::operator=(wh);}
};
class DB_MSG_FROM_HOST : public DB_BASE, public MSG_FROM_HOST {
public:
DB_MSG_FROM_HOST(DB_CONN* p=0);

View File

@ -104,3 +104,8 @@ alter table post
add index post_user (user),
add index post_thread (thread),
add fulltext index post_content(content);
alter table wuhash
add index wuhash_user (userid),
add index wuhash_wu (workunitid),
add unique wuhash_user_wu (userid, workunitid);

View File

@ -464,4 +464,9 @@ create table private_messages (
content text not null,
primary key(id),
key userid (userid)
) TYPE=MyISAM;
) TYPE=MyISAM;
create table wuhash (
userid integer not null,
workunitid bigint not null
) TYPE=MyISAM;

View File

@ -380,11 +380,22 @@ function update_4_29_2007() {
);
}
function update_4_30_2007() {
do_query("create table wuhash (
userid integer not null,
workunitid bigint not null
) TYPE=MyISAM;");
do_query("alter table wuhash add index wuhash_user (userid),
add index wuhash_wu (workunitid),
add unique wuhash_user_wu (userid, workunitid);"
);
}
// modify the following to call the function you want.
// Make sure you do all needed functions, in order.
// (Look at your DB structure using "explain" queries to see
// which ones you need).
//update_4_29_2007();
//update_4_30_2007();
?>

View File

@ -26,6 +26,7 @@
// [-max_granted_credit X] // limit maximum granted credit to X
// [-max_claimed_credit Y] // invalid if claims more than Y
// [-grant_claimed_credit] // just grant whatever is claimed
// [-update_wuhash] // add userid/wuid pair to wuhash table
//
// This program must be linked with two project-specific functions:
// check_set() and check_pair().
@ -78,6 +79,7 @@ bool one_pass = false;
double max_granted_credit = 0;
double max_claimed_credit = 0;
bool grant_claimed_credit = false;
bool update_wuhash = false;
void update_error_rate(DB_HOST& host, bool valid) {
if (host.error_rate > 1) host.error_rate = 1;
@ -89,13 +91,14 @@ void update_error_rate(DB_HOST& host, bool valid) {
}
}
// Here when a result has been validated and its granted_credit as been set.
// Here when a result has been validated and its granted_credit has been set.
// Grant credit to host, user and team, and update host error rate.
//
int is_valid(RESULT& result) {
int is_valid(RESULT& result, WORKUNIT& wu) {
DB_USER user;
DB_HOST host;
DB_TEAM team;
DB_WUHASH wuhash;
int retval;
char buf[256];
@ -201,6 +204,25 @@ int is_valid(RESULT& result) {
}
}
if (update_wuhash) {
wuhash.userid = user.id;
wuhash.workunitid = long(wu.opaque);
retval = wuhash.insert();
if (retval) {
log_messages.printf(
SCHED_MSG_LOG::MSG_NORMAL,
"[RESULT#%d] Warning: wuhash insert failed (userid: %d workunit: %d err: %d)\n",
result.id, user.id, long(wu.opaque), retval
);
} else {
log_messages.printf(
SCHED_MSG_LOG::MSG_DEBUG,
"[RESULT#%d %s] Granted contribution to valid result [WU#%d OPAQUE#%d USER#%d]\n",
result.id, result.name, wu.id, long(wu.opaque), user.id
);
}
}
return 0;
}
@ -325,7 +347,7 @@ int handle_wu(
"[RESULT#%d %s] pair_check() matched: setting result to valid; credit %f\n",
result.id, result.name, result.granted_credit
);
retval = is_valid(result);
retval = is_valid(result,wu);
if (retval) {
log_messages.printf(
SCHED_MSG_LOG::MSG_NORMAL,
@ -434,7 +456,7 @@ int handle_wu(
if (max_granted_credit && result.granted_credit > max_granted_credit) {
result.granted_credit = max_granted_credit;
}
retval = is_valid(result);
retval = is_valid(result,wu);
if (retval) {
log_messages.printf(
SCHED_MSG_LOG::MSG_DEBUG,
@ -637,6 +659,7 @@ int main(int argc, char** argv) {
" -max_claimed_credit X If a result claims more credit than this, mark it as invalid\n"
" -max_granted_credit X Grant no more than this amount of credit to a result\n"
" -grant_claimed_credit Grant the claimed credit, regardless of what other results for this workunit claimed\n"
" -update_wuhash Add userid/wuid pair to wuhash after granting credit\n"
" -sleep_interval n Set sleep-interval to n\n"
" -d level Set debug-level\n\n";
@ -670,6 +693,8 @@ int main(int argc, char** argv) {
max_claimed_credit = atof(argv[++i]);
} else if (!strcmp(argv[i], "-grant_claimed_credit")) {
grant_claimed_credit = true;
} else if (!strcmp(argv[i], "-update_wuhash")) {
update_wuhash = true;
} else {
fprintf(stderr, "Invalid option '%s'\nTry `%s --help` for more information\n", argv[i], argv[0]);
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "unrecognized arg: %s\n", argv[i]);