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:
Christian Dietrich
2013-03-25 16:04:05 +01:00
parent 59e5fd3169
commit f18cddc63c
25 changed files with 1161 additions and 119 deletions

View File

@ -2,7 +2,7 @@
#include "util/Logger.hpp"
#include "BasicImporter.hpp"
extern fail::Logger log;
static fail::Logger LOG("BasicImporter");
bool BasicImporter::create_database() {
std::string create_statement = "CREATE TABLE IF NOT EXISTS trace ("
@ -28,7 +28,7 @@ bool BasicImporter::add_trace_event(instruction_count_t begin, instruction_count
"VALUES (?,?,?,?, ?,?,?)");
stmt = mysql_stmt_init(db->getHandle());
if (mysql_stmt_prepare(stmt, sql.c_str(), sql.length())) {
log << "query '" << sql << "' failed: " << mysql_error(db->getHandle()) << std::endl;
LOG << "query '" << sql << "' failed: " << mysql_error(db->getHandle()) << std::endl;
return false;
}
}
@ -61,12 +61,12 @@ bool BasicImporter::add_trace_event(instruction_count_t begin, instruction_count
}
}
if (mysql_stmt_bind_param(stmt, bind)) {
log << "mysql_stmt_bind_param() failed: " << mysql_stmt_error(stmt) << std::endl;
LOG << "mysql_stmt_bind_param() failed: " << mysql_stmt_error(stmt) << std::endl;
return false;
}
if (mysql_stmt_execute(stmt)) {
log << "mysql_stmt_execute() failed: " << mysql_stmt_error(stmt) << std::endl;
log << "IP: " << std::hex<< event.ip() << std::endl;
LOG << "mysql_stmt_execute() failed: " << mysql_stmt_error(stmt) << std::endl;
LOG << "IP: " << std::hex<< event.ip() << std::endl;
return false;
}
return true;

View File

@ -1,22 +1,10 @@
## Setup desired protobuf descriptions HERE ##
set(MY_PROTOS
../../src/plugins/tracing/trace.proto
)
set(SRCS
Importer.cc
BasicImporter.cc
DCiAOKernelImporter.cc
)
#### PROTOBUFS ####
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${MY_PROTOS})
## This is the example's campaign server distributing experiment parameters
add_executable(import-trace main.cc ${SRCS} ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(import-trace ${PROTOBUF_LIBRARY} -lmysqlclient fail-util fail-sal)
target_link_libraries(import-trace ${PROTOBUF_LIBRARY} -lmysqlclient fail-util fail-sal fail-comm)
install(TARGETS import-trace RUNTIME DESTINATION bin)

View File

@ -2,7 +2,7 @@
#include <set>
#include "util/Logger.hpp"
extern fail::Logger log;
static fail::Logger LOG("DCiAOKernelImporter");
using namespace fail;
@ -18,12 +18,12 @@ bool DCiAOKernelImporter::inDynamicKernelMemory(fail::address_t addr) {
bool DCiAOKernelImporter::copy_to_database(fail::ProtoIStream &ps) {
if (m_elf == 0) {
log << "Please give an ELF Binary as a parameter" << std::endl;
LOG << "Please give an ELF Binary as a parameter" << std::endl;
exit(-1);
}
if (getEnterKernelAddress() == 0 || getLeaveKernelAddress() == 0) {
log << "Pleave give a valid CiAO Binary with kernel dependability options enabled" << std::endl;
LOG << "Pleave give a valid CiAO Binary with kernel dependability options enabled" << std::endl;
exit(-1);
}
@ -93,12 +93,12 @@ bool DCiAOKernelImporter::copy_to_database(fail::ProtoIStream &ps) {
// we're currently looking at; the EC is defined by
// data_address [last_kernel_leave, read_instr] (instr_absolute)
if (!add_trace_event(instr1, instr2, ev)) {
log << "add_trace_event failed" << std::endl;
LOG << "add_trace_event failed" << std::endl;
return false;
}
row_count ++;
if (row_count % 1000 == 0) {
log << "Imported " << row_count << " traces into the database" << std::endl;
LOG << "Imported " << row_count << " traces into the database" << std::endl;
}
}
}
@ -106,7 +106,7 @@ bool DCiAOKernelImporter::copy_to_database(fail::ProtoIStream &ps) {
}
log << "Inserted " << row_count << " traces into the database" << std::endl;
LOG << "Inserted " << row_count << " traces into the database" << std::endl;
return true;
}

View File

@ -5,7 +5,7 @@
using namespace fail;
extern Logger log;
static Logger LOG("Importer");
bool Importer::init(const std::string &variant, const std::string &benchmark, Database *db) {
this->db = db;
@ -13,7 +13,7 @@ bool Importer::init(const std::string &variant, const std::string &benchmark, Da
if (!m_variant_id) {
return false;
}
log << "Importing to variant " << variant << "/" << benchmark
LOG << "Importing to variant " << variant << "/" << benchmark
<< " (ID: " << m_variant_id << ")" << std::endl;
return true;
}
@ -23,7 +23,7 @@ bool Importer::clear_database() {
ss << "DELETE FROM trace WHERE variant_id = " << m_variant_id;
bool ret = db->query(ss.str().c_str()) == 0 ? false : true;
log << "deleted " << db->affected_rows() << " rows from trace table" << std::endl;
LOG << "deleted " << db->affected_rows() << " rows from trace table" << std::endl;
return ret;
}
@ -69,12 +69,12 @@ bool Importer::copy_to_database(fail::ProtoIStream &ps) {
// we're currently looking at; the EC is defined by
// data_address [instr1, instr2] (instr_absolute)
if (!add_trace_event(instr1, instr2, ev)) {
log << "add_trace_event failed" << std::endl;
LOG << "add_trace_event failed" << std::endl;
return false;
}
row_count ++;
if (row_count % 1000 == 0) {
log << "Imported " << row_count << " traces into the database" << std::endl;
LOG << "Imported " << row_count << " traces into the database" << std::endl;
}
if (ev.accesstype() == ev.READ) {
@ -91,7 +91,7 @@ bool Importer::copy_to_database(fail::ProtoIStream &ps) {
}
}
log << "Inserted " << row_count << " traces into the database" << std::endl;
LOG << "Inserted " << row_count << " traces into the database" << std::endl;
// FIXME
// close all open intervals (right end of the fault-space) with fake trace event

View File

@ -7,14 +7,14 @@
#include "util/ElfReader.hpp"
#include "sal/SALConfig.hpp"
#include "util/Database.hpp"
#include "trace.pb.h"
#include "comm/TracePlugin.pb.h"
class Importer {
protected:
int m_variant_id;
fail::ElfReader *m_elf;
fail::Database *db;
fail::Database *db;
public:
typedef unsigned instruction_count_t;

View File

@ -17,12 +17,12 @@ using std::cerr;
using std::endl;
using std::cout;
Logger log("import-trace", true);
static Logger LOG("import-trace", true);
ProtoIStream openProtoStream(std::string input_file) {
std::ifstream *gz_test_ptr = new std::ifstream(input_file.c_str()), &gz_test = *gz_test_ptr;
if (!gz_test) {
log << "couldn't open " << input_file << endl;
LOG << "couldn't open " << input_file << endl;
exit(-1);
}
unsigned char b1, b2;
@ -31,16 +31,16 @@ ProtoIStream openProtoStream(std::string input_file) {
if (b1 == 0x1f && b2 == 0x8b) {
igzstream *tracef = new igzstream(input_file.c_str());
if (!tracef) {
log << "couldn't open " << input_file << endl;
LOG << "couldn't open " << input_file << endl;
exit(-1);
}
log << "opened file " << input_file << " in GZip mode" << endl;
LOG << "opened file " << input_file << " in GZip mode" << endl;
delete gz_test_ptr;
ProtoIStream ps(tracef);
return ps;
}
log << "opened file " << input_file << " in normal mode" << endl;
LOG << "opened file " << input_file << " in normal mode" << endl;
ProtoIStream ps(gz_test_ptr);
return ps;
}
@ -85,18 +85,18 @@ int main(int argc, char *argv[]) {
if (cmd[IMPORTER].count() > 0) {
std::string imp(cmd[IMPORTER].first()->arg);
if (imp == "BasicImporter") {
log << "Using BasicImporter" << endl;
LOG << "Using BasicImporter" << endl;
importer = new BasicImporter();
} else if (imp == "DCiAOKernelImporter") {
log << "Using DCiAOKernelImporter" << endl;
LOG << "Using DCiAOKernelImporter" << endl;
importer = new DCiAOKernelImporter();
} else {
log << "Unkown import method: " << imp << endl;
LOG << "Unkown import method: " << imp << endl;
exit(-1);
}
} else {
log << "Using BasicImporter" << endl;
LOG << "Using BasicImporter" << endl;
importer = new BasicImporter();
}
@ -133,7 +133,7 @@ int main(int argc, char *argv[]) {
if (!importer->init(variant, benchmark, db)) {
log << "importer->init() failed" << endl;
LOG << "importer->init() failed" << endl;
exit(-1);
}
importer->set_elf_file(elf_file);
@ -143,17 +143,17 @@ int main(int argc, char *argv[]) {
////////////////////////////////////////////////////////////////
if (!importer->create_database()) {
log << "create_database() failed" << endl;
LOG << "create_database() failed" << endl;
exit(-1);
}
if (!importer->clear_database()) {
log << "clear_database() failed" << endl;
LOG << "clear_database() failed" << endl;
exit(-1);
}
if (!importer->copy_to_database(ps)) {
log << "copy_to_database() failed" << endl;
LOG << "copy_to_database() failed" << endl;
exit(-1);
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}