Files
fail/tools/prune-trace/BasicPruner.cc
Christian Dietrich f18cddc63c 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
2013-04-02 09:52:42 +02:00

51 lines
1.9 KiB
C++

#include <sstream>
#include "BasicPruner.hpp"
#include "util/Logger.hpp"
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'";
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";
if (!db->query(ss.str().c_str())) return false;
ss.str("");
rows += db->affected_rows();
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;
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'";
if (!db->query(ss.str().c_str())) return false;
ss.str("");
rows += db->affected_rows();
LOG << "created " << rows << " fspgroup entries" << std::endl;
return true;
}