DatabaseCampaign: abstract campain for interaction with MySQL Database
The DatabaseCampaign interacts with the MySQL tables that are created
by the import-trace and prune-trace tools. It does offer all
unfinished experiment pilots from the database to the
fail-clients. Those clients send back a (by the experiment) defined
protobuf message as a result. The custom protobuf message does have to
need the form:
import "DatabaseCampaignMessage.proto";
message ExperimentMsg {
required DatabaseCampaignMessage fsppilot = 1;
repeated group Result = 2 {
// custom fields
required int32 bitoffset = 1;
optional int32 result = 2;
}
}
The DatabaseCampaignMessage is the pilot identifier from the
database. For each of the repeated result entries a row in a table is
allocated. The structure of this table is constructed (by protobuf
reflection) from the description of the message. Each field in the
Result group becomes a column in the result table. For the given
example it would be:
CREATE TABLE result_ExperimentMessage(
pilot_id INT,
bitoffset INT NOT NULL,
result INT,
PRIMARY_KEY(pilot_id)
)
Change-Id: I28fb5488e739d4098b823b42426c5760331027f8
This commit is contained in:
@ -1,50 +1,50 @@
|
||||
#include <sstream>
|
||||
#include "BasicPruner.hpp"
|
||||
#include "util/Logger.hpp"
|
||||
static fail::Logger log ("BasicPruner");
|
||||
static fail::Logger LOG ("BasicPruner");
|
||||
|
||||
|
||||
bool BasicPruner::prune_all() {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "INSERT INTO fsppilot (known_outcome, variant_id, instr2, data_address, fspmethod_id) "
|
||||
"SELECT 0, variant_id, instr2, data_address, " << m_method_id << " "
|
||||
"FROM trace "
|
||||
"WHERE variant_id = " << m_variant_id << " AND accesstype = 'R'";
|
||||
"SELECT 0, variant_id, instr2, data_address, " << m_method_id << " "
|
||||
"FROM trace "
|
||||
"WHERE variant_id = " << m_variant_id << " AND accesstype = 'R'";
|
||||
if (!db->query(ss.str().c_str())) return false;
|
||||
ss.str("");
|
||||
|
||||
int rows = db->affected_rows();
|
||||
// single entry for known outcome (write access)
|
||||
ss << "INSERT INTO fsppilot (known_outcome, variant_id, instr2, data_address, fspmethod_id) "
|
||||
"SELECT 1, variant_id, instr2, data_address, " << m_method_id << " "
|
||||
"FROM trace "
|
||||
"WHERE variant_id = " << m_variant_id << " AND accesstype = 'W' "
|
||||
"LIMIT 1";
|
||||
"SELECT 1, variant_id, instr2, data_address, " << m_method_id << " "
|
||||
"FROM trace "
|
||||
"WHERE variant_id = " << m_variant_id << " AND accesstype = 'W' "
|
||||
"LIMIT 1";
|
||||
if (!db->query(ss.str().c_str())) return false;
|
||||
ss.str("");
|
||||
rows += db->affected_rows();
|
||||
|
||||
log << "created " << rows << " fsppilot entries" << std::endl;
|
||||
LOG << "created " << rows << " fsppilot entries" << std::endl;
|
||||
|
||||
ss << "INSERT INTO fspgroup (variant_id, instr2, data_address, fspmethod_id, pilot_id) "
|
||||
"SELECT variant_id, instr2, data_address, fspmethod_id, id "
|
||||
"FROM fsppilot "
|
||||
"WHERE known_outcome = 0 AND fspmethod_id = " << m_method_id << " AND variant_id = " << m_variant_id;
|
||||
"SELECT variant_id, instr2, data_address, fspmethod_id, id "
|
||||
"FROM fsppilot "
|
||||
"WHERE known_outcome = 0 AND fspmethod_id = " << m_method_id << " AND variant_id = " << m_variant_id;
|
||||
if (!db->query(ss.str().c_str())) return false;
|
||||
ss.str("");
|
||||
rows = db->affected_rows();
|
||||
ss << "INSERT INTO fspgroup (variant_id, instr2, data_address, fspmethod_id, pilot_id) "
|
||||
"SELECT t.variant_id, t.instr2, t.data_address, p.fspmethod_id, p.id "
|
||||
"FROM trace t "
|
||||
"JOIN fsppilot p "
|
||||
"ON t.variant_id = p.variant_id AND p.fspmethod_id = " << m_method_id << " AND p.known_outcome = 1 "
|
||||
"WHERE t.variant_id = " << m_variant_id << " AND t.accesstype = 'W'";
|
||||
"SELECT t.variant_id, t.instr2, t.data_address, p.fspmethod_id, p.id "
|
||||
"FROM trace t "
|
||||
"JOIN fsppilot p "
|
||||
"ON t.variant_id = p.variant_id AND p.fspmethod_id = " << m_method_id << " AND p.known_outcome = 1 "
|
||||
"WHERE t.variant_id = " << m_variant_id << " AND t.accesstype = 'W'";
|
||||
if (!db->query(ss.str().c_str())) return false;
|
||||
ss.str("");
|
||||
rows += db->affected_rows();
|
||||
|
||||
log << "created " << rows << " fspgroup entries" << std::endl;
|
||||
LOG << "created " << rows << " fspgroup entries" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -3,10 +3,11 @@
|
||||
#include "util/Logger.hpp"
|
||||
|
||||
using namespace fail;
|
||||
static Logger log ("Pruner");
|
||||
static Logger LOG ("Pruner");
|
||||
|
||||
#include "Pruner.hpp"
|
||||
|
||||
|
||||
bool Pruner::init(const std::string &variant, const std::string &benchmark, Database *db) {
|
||||
this->db = db;
|
||||
if (!(m_variant_id = db->get_variant_id(variant, benchmark))) {
|
||||
@ -15,7 +16,7 @@ bool Pruner::init(const std::string &variant, const std::string &benchmark, Data
|
||||
if (!(m_method_id = db->get_fspmethod_id(method_name()))) {
|
||||
return false;
|
||||
}
|
||||
log << "Pruning variant "
|
||||
LOG << "Pruning variant "
|
||||
<< variant << "/" << benchmark << " (ID: " << m_variant_id << ")"
|
||||
<< " with method " << method_name() << " (ID: " << m_method_id << ")"
|
||||
<< std::endl;
|
||||
@ -52,12 +53,12 @@ bool Pruner::clear_database() {
|
||||
std::stringstream ss;
|
||||
ss << "DELETE FROM fsppilot WHERE variant_id = " << m_variant_id << " AND fspmethod_id = " << m_method_id;
|
||||
bool ret = (bool) db->query(ss.str().c_str());
|
||||
log << "deleted " << db->affected_rows() << " rows from fsppilot table" << std::endl;
|
||||
LOG << "deleted " << db->affected_rows() << " rows from fsppilot table" << std::endl;
|
||||
ss.str("");
|
||||
|
||||
ss << "DELETE FROM fspgroup WHERE variant_id = " << m_variant_id << " AND fspmethod_id = " << m_method_id;
|
||||
ret = ret && (bool) db->query(ss.str().c_str());
|
||||
log << "deleted " << db->affected_rows() << " rows from fspgroup table" << std::endl;
|
||||
LOG << "deleted " << db->affected_rows() << " rows from fspgroup table" << std::endl;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
#include "util/CommandLine.hpp"
|
||||
#include "util/Logger.hpp"
|
||||
static fail::Logger log("prune-trace", true);
|
||||
static fail::Logger LOG("prune-trace", true);
|
||||
|
||||
using namespace fail;
|
||||
using std::endl;
|
||||
@ -29,7 +29,6 @@ int main(int argc, char *argv[]) {
|
||||
"-v/--variant\t Variant label (default: \"none\")");
|
||||
CommandLine::option_handle BENCHMARK = cmd.addOption("b", "benchmark", Arg::Required,
|
||||
"-b/--benchmark\t Benchmark label (default: \"none\")\n");
|
||||
|
||||
CommandLine::option_handle PRUNER = cmd.addOption("p", "prune-method", Arg::Required,
|
||||
"-p/--prune-method\t Which import method to use (default: basic)");
|
||||
|
||||
@ -42,15 +41,15 @@ int main(int argc, char *argv[]) {
|
||||
if (cmd[PRUNER].count() > 0) {
|
||||
std::string imp(cmd[PRUNER].first()->arg);
|
||||
if (imp == "basic") {
|
||||
log << "Using BasicPruner" << endl;
|
||||
LOG << "Using BasicPruner" << endl;
|
||||
pruner = new BasicPruner();
|
||||
} else {
|
||||
log << "Unkown import method: " << imp << endl;
|
||||
LOG << "Unkown import method: " << imp << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
} else {
|
||||
log << "Using BasicPruner" << endl;
|
||||
LOG << "Using BasicPruner" << endl;
|
||||
pruner = new BasicPruner();
|
||||
}
|
||||
|
||||
@ -72,7 +71,7 @@ int main(int argc, char *argv[]) {
|
||||
benchmark = "none";
|
||||
|
||||
if (!pruner->init(variant, benchmark, db)) {
|
||||
log << "pruner->init() failed" << endl;
|
||||
LOG << "pruner->init() failed" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@ -80,17 +79,17 @@ int main(int argc, char *argv[]) {
|
||||
// Do the actual import
|
||||
////////////////////////////////////////////////////////////////
|
||||
if (!pruner->create_database()) {
|
||||
log << "create_database() failed" << endl;
|
||||
LOG << "create_database() failed" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (!pruner->clear_database()) {
|
||||
log << "clear_database() failed" << endl;
|
||||
LOG << "clear_database() failed" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (!pruner->prune_all()) {
|
||||
log << "prune_all() failed" << endl;
|
||||
LOG << "prune_all() failed" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user