From 846ec9fbb036bfbed231986b89d4b86bd03e1d17 Mon Sep 17 00:00:00 2001 From: Matt Lebofsky Date: Wed, 2 May 2007 18:51:51 +0000 Subject: [PATCH] svn path=/trunk/boinc/; revision=12532 --- checkin_notes | 21 +++++++++++++++++++++ db/boinc_db.C | 17 +++++++++++++++++ db/boinc_db.h | 16 ++++++++++++++++ db/constraints.sql | 5 +++++ db/schema.sql | 7 ++++++- html/ops/db_update.php | 13 ++++++++++++- sched/validator.C | 33 +++++++++++++++++++++++++++++---- 7 files changed, 106 insertions(+), 6 deletions(-) diff --git a/checkin_notes b/checkin_notes index 2421364db2..9ac01a6b98 100755 --- a/checkin_notes +++ b/checkin_notes @@ -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 + + + diff --git a/db/boinc_db.C b/db/boinc_db.C index 9c46d7da8c..d0d0c0a6a3 100644 --- a/db/boinc_db.C +++ b/db/boinc_db.C @@ -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); diff --git a/db/boinc_db.h b/db/boinc_db.h index fc482c08db..3f64491c31 100755 --- a/db/boinc_db.h +++ b/db/boinc_db.h @@ -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); diff --git a/db/constraints.sql b/db/constraints.sql index 8aa89d1077..723182651b 100644 --- a/db/constraints.sql +++ b/db/constraints.sql @@ -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); diff --git a/db/schema.sql b/db/schema.sql index 85f8c7ff9a..5a523dd102 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -464,4 +464,9 @@ create table private_messages ( content text not null, primary key(id), key userid (userid) -) TYPE=MyISAM; \ No newline at end of file +) TYPE=MyISAM; + +create table wuhash ( + userid integer not null, + workunitid bigint not null +) TYPE=MyISAM; diff --git a/html/ops/db_update.php b/html/ops/db_update.php index ebbaad66fa..1cb8c161fc 100755 --- a/html/ops/db_update.php +++ b/html/ops/db_update.php @@ -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(); ?> diff --git a/sched/validator.C b/sched/validator.C index 9624cf3d8a..011cae0a86 100644 --- a/sched/validator.C +++ b/sched/validator.C @@ -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]);