dbcampaign: select multiple variants/benchmark pairs

The variant/benchmark selection now can use SQL LIKE syntax, all unfinished
pilots from all selected variants are sent to the clients. E.g.:

./cored-voter-server  -v x86-cored-voter -b simple-% -p basic

Will select the fsppilots in the variants:

- x86-cored-voter/simple-ip/basic
- x86-cored-voter/simple-instr/basic

The variant and benchmark information is now sent within the
fsppilot.

Change-Id: I287bfcddc478d0b79d89e156d6f5bf8188674532
This commit is contained in:
Christian Dietrich
2013-07-03 22:10:18 +02:00
parent 40f610b536
commit 9843b520c1
5 changed files with 124 additions and 60 deletions

View File

@ -63,8 +63,7 @@ bool DatabaseCampaign::run() {
pruner = "basic";
db = Database::cmdline_connect();
variant_id = db->get_variant_id(variant, benchmark);
log_send << "Variant to use " << variant << "/" << benchmark << " (ID: " << variant_id << ")" << std::endl;
log_send << "Variant to use " << variant << "/" << benchmark << std::endl;
fspmethod_id = db->get_fspmethod_id(pruner);
log_send << "Pruner to use " << pruner << " (ID: " << fspmethod_id << ")" << std::endl;
@ -80,56 +79,17 @@ bool DatabaseCampaign::run() {
boost::thread collect_thread(&DatabaseCampaign::collect_result_thread, this);
#endif
/* Gather all unfinished jobs */
int experiment_count;
std::string sql_select = "SELECT pilot_id, g.fspmethod_id, g.variant_id, p.injection_instr, p.injection_instr_absolute, g.data_address";
std::stringstream ss;
ss << " FROM fspgroup g"
<< " INNER JOIN fsppilot p ON p.id = g.pilot_id "
<< " WHERE p.known_outcome = 0 "
<< " AND g.fspmethod_id = " << fspmethod_id
<< " AND g.variant_id = " << variant_id
<< " AND (SELECT COUNT(*) FROM " + db_connect.result_table() + " as r WHERE r.pilot_id = g.pilot_id) < 8"
<< " ORDER BY p.injection_instr";
std::string sql_body = ss.str();
/* Get the number of unfinished experiments */
MYSQL_RES *count = db->query(("SELECT COUNT(*) " + sql_body).c_str(), true);
MYSQL_ROW row = mysql_fetch_row(count);
experiment_count = atoi(row[0]);
MYSQL_RES *pilots = db->query_stream ((sql_select + sql_body).c_str());
log_send << "Found " << experiment_count << " unfinished experiments in database." << std::endl;
sent_pilots = 0;
while ((row = mysql_fetch_row(pilots)) != 0) {
unsigned pilot_id = atoi(row[0]);
unsigned injection_instr = atoi(row[3]);
unsigned data_address = atoi(row[5]);
DatabaseCampaignMessage pilot;
pilot.set_pilot_id(pilot_id);
pilot.set_fspmethod_id(fspmethod_id);
pilot.set_variant_id(variant_id);
pilot.set_injection_instr(injection_instr);
if (row[4]) {
unsigned injection_instr_absolute = atoi(row[4]);
pilot.set_injection_instr_absolute(injection_instr_absolute);
}
pilot.set_data_address(data_address);
this->cb_send_pilot(pilot);
if ((++sent_pilots) % 1000 == 0) {
log_send << "pushed " << sent_pilots << " pilots into the queue" << std::endl;
std::vector<Database::Variant> variants = db->get_variants(variant, benchmark);
for (std::vector<Database::Variant>::const_iterator it = variants.begin();
it != variants.end(); ++it) {
if(!run_variant(*it)) {
log_send << "run_variant failed for " << it->variant << "/" << it->benchmark <<std::endl;
return false;
}
}
log_send << "pushed " << sent_pilots << " pilots into the queue" << std::endl;
log_send << "wait for the clients to complete" << std::endl;
campaignmanager.noMoreParameters();
#ifndef __puma
@ -149,3 +109,58 @@ void DatabaseCampaign::collect_result_thread() {
}
}
bool DatabaseCampaign::run_variant(Database::Variant variant) {
/* Gather all unfinished jobs */
int experiment_count;
std::string sql_select = "SELECT pilot_id, g.fspmethod_id, g.variant_id, p.injection_instr, p.injection_instr_absolute, g.data_address ";
std::stringstream ss;
ss << " FROM fspgroup g"
<< " INNER JOIN fsppilot p ON p.id = g.pilot_id "
<< " WHERE p.known_outcome = 0 "
<< " AND g.fspmethod_id = " << fspmethod_id
<< " AND g.variant_id = " << variant.id
<< " AND (SELECT COUNT(*) FROM " + db_connect.result_table() + " as r WHERE r.pilot_id = g.pilot_id)"
<< " < " << expected_number_of_results(variant.variant, variant.benchmark)
<< " ORDER BY p.injection_instr";
std::string sql_body = ss.str();
/* Get the number of unfinished experiments */
MYSQL_RES *count = db->query(("SELECT COUNT(*) " + sql_body).c_str(), true);
MYSQL_ROW row = mysql_fetch_row(count);
experiment_count = atoi(row[0]);
MYSQL_RES *pilots = db->query_stream ((sql_select + sql_body).c_str());
log_send << "Found " << experiment_count << " unfinished experiments in database. ("
<< variant.variant << "/" << variant.benchmark << ")" << std::endl;
sent_pilots = 0;
while ((row = mysql_fetch_row(pilots)) != 0) {
unsigned pilot_id = atoi(row[0]);
unsigned injection_instr = atoi(row[3]);
unsigned data_address = atoi(row[5]);
DatabaseCampaignMessage pilot;
pilot.set_pilot_id(pilot_id);
pilot.set_fspmethod_id(fspmethod_id);
pilot.set_variant_id(variant.id);
pilot.set_injection_instr(injection_instr);
pilot.set_variant(variant.variant);
pilot.set_benchmark(variant.benchmark);
if (row[4]) {
unsigned injection_instr_absolute = atoi(row[4]);
pilot.set_injection_instr_absolute(injection_instr_absolute);
}
pilot.set_data_address(data_address);
this->cb_send_pilot(pilot);
if ((++sent_pilots) % 1000 == 0) {
log_send << "pushed " << sent_pilots << " pilots into the queue" << std::endl;
}
}
return true;
}

View File

@ -24,7 +24,6 @@ class DatabaseCampaign : public Campaign {
Database *db; // !< The database connection object
DatabaseProtobufAdapter db_connect;
int variant_id; // !< Which variant do we work on (from CMDLINE)
int fspmethod_id; // !< Which fspmethod should be put out to the clients
void collect_result_thread();
@ -41,6 +40,20 @@ public:
*/
virtual bool run();
/**
* Is called by run() for every variant, returned by the variant
* filter (SQL LIKE).
* @return \c true if the campaign was successful, \c false otherwise
*/
virtual bool run_variant(fail::Database::Variant);
/**
* How many results have to are expected from each fsppilot. If
* there are less result rows, the pilot will be again sent to the clients
* @return \c exptected number of results
*/
virtual int expected_number_of_results(std::string variant, std::string benchmark) { return 8;}
/**
* Callback function that can be used to add command line options
* to the campaign