*** empty log message ***

svn path=/trunk/boinc/; revision=4088
This commit is contained in:
David Anderson 2004-08-21 00:40:01 +00:00
parent 31023415a0
commit 7d08159c7d
4 changed files with 73 additions and 27 deletions

View File

@ -16554,3 +16554,27 @@ David 20 Aug 2004
client/
app_control.C
David 20 Aug 2004
- already_sent_to_different_platform():
fix concurrency bug by reading WU.workseq_next
from database just prior to checking,
then updating the field immediately if needed.
- scheduler: update_wu_transition_time():
use update_field(); more efficient
- Added DB_BASE::get_field_int(): get a single integer
field from a DB record.
A little cheaper than reading the whole record
- DB_BASE::lookup(): remove code that sees if record is unique.
It's called after mysql_free_result(),
so it will never return anything.
- DB code: changed "if (db->mysql && is_high_priority) to just
"if (is_high_priority)".
db->mysql is a pointer, and is always nonzero.
It's not a flag saying whether the DB is MySQL.
All this code is only for MySQL anyway.
db/
db_base.C,h
sched/
sched_send.C

View File

@ -108,13 +108,31 @@ int DB_BASE::update_field(char* clause) {
return db->do_query(query);
}
int DB_BASE::get_field_int(char* field, int& val) {
char query[MAX_QUERY_LEN];
int retval;
MYSQL_ROW row;
MYSQL_RES* rp;
sprintf(query, "select %s from %s where id=%d", field, table_name, get_id());
retval = db->do_query(query);
if (retval) return retval;
rp = mysql_store_result(db->mysql);
if (!rp) return -1;
row = mysql_fetch_row(rp);
if (row) val = atoi(row[0]);
mysql_free_result(rp);
if (row == 0) return ERR_DB_NOT_FOUND;
return 0;
}
int DB_BASE::lookup(char* clause) {
char query[MAX_QUERY_LEN];
int retval;
MYSQL_ROW row;
MYSQL_RES* rp;
if (db->mysql && is_high_priority) {
if (is_high_priority) {
sprintf(query, "select HIGH_PRIORITY * from %s %s", table_name, clause);
} else {
sprintf(query, "select * from %s %s", table_name, clause);
@ -128,11 +146,6 @@ int DB_BASE::lookup(char* clause) {
if (row) db_parse(row);
mysql_free_result(rp);
if (row == 0) return ERR_DB_NOT_FOUND;
// make sure there's exactly one row
//
row = mysql_fetch_row(rp);
if (row) return ERR_DB_NOT_UNIQUE;
return 0;
}
@ -142,7 +155,7 @@ int DB_BASE::lookup_id(int id) {
MYSQL_ROW row;
MYSQL_RES* rp;
if (db->mysql && is_high_priority) {
if (is_high_priority) {
sprintf(query, "select HIGH_PRIORITY * from %s where id=%d", table_name, id);
} else {
sprintf(query, "select * from %s where id=%d", table_name, id);
@ -169,7 +182,7 @@ int DB_BASE::enumerate(char* clause) {
if (!cursor.active) {
cursor.active = true;
if (db->mysql && is_high_priority) {
if (is_high_priority) {
sprintf(query, "select HIGH_PRIORITY * from %s %s", table_name, clause);
} else {
sprintf(query, "select * from %s %s", table_name, clause);
@ -242,7 +255,7 @@ int DB_BASE::get_double(char* query, double& x) {
int DB_BASE::count(int& n, char* clause) {
char query[MAX_QUERY_LEN];
if (db->mysql && is_high_priority) {
if (is_high_priority) {
sprintf(query, "select HIGH_PRIORITY count(*) from %s %s", table_name, clause);
} else {
sprintf(query, "select count(*) from %s %s", table_name, clause);
@ -254,7 +267,7 @@ int DB_BASE::count(int& n, char* clause) {
int DB_BASE::sum(double& x, char* field, char* clause) {
char query[MAX_QUERY_LEN];
if (db->mysql && is_high_priority) {
if (is_high_priority) {
sprintf(query, "select HIGH_PRIORITY sum(%s) from %s %s", field, table_name, clause);
} else {
sprintf(query, "select sum(%s) from %s %s", field, table_name, clause);

View File

@ -82,6 +82,7 @@ public:
int insert_batch(const char*);
int update();
int update_field(char*);
int get_field_int(char*, int&);
int lookup_id(int id);
int lookup(char*);
int enumerate(char* clause="");

View File

@ -354,20 +354,13 @@ int insert_deadline_tag(RESULT& result) {
}
static int update_wu_transition_time(WORKUNIT wu, time_t x) {
// 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.
DB_WORKUNIT dbwu;
int retval;
char buf[256];
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;
dbwu.id = wu.id;
sprintf(buf, "transition_time=%d", x);
return dbwu.update_field(buf);
}
// return true iff a result for same WU is already being sent
@ -431,15 +424,30 @@ bool same_platform(DB_HOST& host, SCHEDULER_REQUEST& sreq) {
static bool already_sent_to_different_platform(
SCHEDULER_REQUEST& sreq, WORKUNIT& workunit, WORK_REQ& wreq
) {
DB_WORKUNIT db_wu;
int wsn;
char buf[256];
// reread workseq_next field from DB in case it's changed
//
db_wu.id = workunit.id;
retval = db_wu.get_field("workseq_next", wsn);
if (retval) {
log_messages.printf(
SCHED_MSG_LOG::ERROR, "can't get workseq_next for %s: %d\n",
dbwu.id, retval
);
return true;
}
wreq.homogeneous_redundancy_reject = false;
if (workunit.workseq_next != unspec) {
if (OS(sreq) + CPU(sreq) != workunit.workseq_next)
if (wsn != unspec) {
if (OS(sreq) + CPU(sreq) != wsn) {
wreq.homogeneous_redundancy_reject = true;
}
} else {
workunit.workseq_next = OS(sreq) + CPU(sreq);
DB_WORKUNIT db_wu;
db_wu = workunit;
db_wu.update();
wsn = OS(sreq) + CPU(sreq);
sprintf(buf, "workseq_next=%d", wsn);
db_wu.update_field(buf);
}
return wreq.homogeneous_redundancy_reject;
}