From 1b3e1fe4842b630864460d9cdb3ee0f6b6e13b89 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 17 Mar 2006 04:47:51 +0000 Subject: [PATCH] scheduler race condition svn path=/trunk/boinc/; revision=9666 --- checkin_notes | 14 ++++++++++++++ db/boinc_db.C | 16 +++++++++++----- db/boinc_db.h | 2 +- db/db_base.C | 4 ++++ db/db_base.h | 1 + doc/boinc_news.inc | 10 ++++++++++ doc/graphics.php | 12 ++++++------ doc/links.php | 1 + sched/sched_resend.C | 2 +- sched/sched_send.C | 3 ++- 10 files changed, 51 insertions(+), 14 deletions(-) diff --git a/checkin_notes b/checkin_notes index e504e2acf7..146b01798a 100755 --- a/checkin_notes +++ b/checkin_notes @@ -2906,3 +2906,17 @@ Rom 16 Mar 2006 clientlib/win/ boinc_dll.cpp NetworkTracker.cpp + +David 16 Mar 2006 + - scheduler: when mark a result as sent, make sure its + server_state is what we expected (e.g. UNSENT). + This guards against two scheduler instances trying to + send the same result at about the same time. + (from Bruce Allen) + + db/ + boinc_db.C,h + db_base.C,h + sched/ + sched_resend.C + sched_send.C diff --git a/db/boinc_db.C b/db/boinc_db.C index af9fa72cab..8dda1c9075 100644 --- a/db/boinc_db.C +++ b/db/boinc_db.C @@ -736,16 +736,22 @@ void DB_RESULT::db_print_values(char* buf){ UNESCAPE(stderr_out); } -// called from scheduler when dispatch this result +// called from scheduler when dispatch this result. +// The "... and server_state=%d" is a safeguard against +// the case where another scheduler tries to send this result at the same time // -int DB_RESULT::update_subset() { +int DB_RESULT::mark_as_sent(int old_server_state) { char query[MAX_QUERY_LEN]; + int retval; sprintf(query, - "update result set server_state=%d, hostid=%d, userid=%d, sent_time=%d, report_deadline=%d where id=%d", - server_state, hostid, userid, sent_time, report_deadline, id + "update result set server_state=%d, hostid=%d, userid=%d, sent_time=%d, report_deadline=%d where id=%d and server_state=%d", + server_state, hostid, userid, sent_time, report_deadline, id, + old_server_state ); - return db->do_query(query); + retval = db->do_query(query); + if (retval) return retval; + if (db->affected_rows() != 1) return ERR_DB_NOT_FOUND; } void DB_RESULT::db_parse(MYSQL_ROW &r) { diff --git a/db/boinc_db.h b/db/boinc_db.h index 2203261e79..7560cec317 100755 --- a/db/boinc_db.h +++ b/db/boinc_db.h @@ -560,7 +560,7 @@ class DB_RESULT : public DB_BASE, public RESULT { public: DB_RESULT(DB_CONN* p=0); int get_id(); - int update_subset(); + int mark_as_sent(int old_server_state); void db_print(char*); void db_print_values(char*); void db_parse(MYSQL_ROW &row); diff --git a/db/db_base.C b/db/db_base.C index 559e8e04a8..b0346ce3ad 100644 --- a/db/db_base.C +++ b/db/db_base.C @@ -63,6 +63,10 @@ int DB_CONN::do_query(const char* p) { return retval; } +int DB_CONN::affected_rows() { + return mysql_affected_rows(mysql); +} + int DB_CONN::insert_id() { int retval; MYSQL_ROW row; diff --git a/db/db_base.h b/db/db_base.h index e83536e2ad..745e7e74fe 100644 --- a/db/db_base.h +++ b/db/db_base.h @@ -62,6 +62,7 @@ public: DB_CONN(); int open(char* name, char* host, char* user, char* passwd); int do_query(const char*); + int affected_rows(); void close(); int insert_id(); void print_error(const char*); diff --git a/doc/boinc_news.inc b/doc/boinc_news.inc index 310e7fb087..750d098f4d 100644 --- a/doc/boinc_news.inc +++ b/doc/boinc_news.inc @@ -1,6 +1,16 @@ Seasonal Attribution Project, + a spin-off of Climateprediction.net, + seeks to determine the extent to which extreme weather events + are attributable to human-induced climate change. + Its application is a high-resolution simulation of the world's climate, + and is recommended only for computers + with at least 1 GB of RAM, and a 2.4GHz Pentium or faster processor. + " +), array("March 5, 2006", "Tony/Knightrider/Chuggybus has created BOINC coinage. See the large diff --git a/doc/graphics.php b/doc/graphics.php index be6aa436a0..77371bbcf1 100644 --- a/doc/graphics.php +++ b/doc/graphics.php @@ -12,12 +12,12 @@ General comments about graphics: