From 010d4a892d832c72edcdd1b4f5e855124fe483cc Mon Sep 17 00:00:00 2001 From: Florian Lukas Date: Wed, 12 Mar 2014 11:25:54 +0100 Subject: [PATCH] DatabaseCampaign: fix finished experiments SQL The database queries to fetch all unfinished experiments were broken. The server tried to insert all finished pilot_ids into the temporary result_ids table and then discard all experiments which have the correct (finished) count of IDs in this table. This cannot work as the pilot_id is the only column of result_ids and must be a unique primary key. As a fix, the count of results is stored as a second field in result_ids and the result table is now joined against result_ids to check this field. Change-Id: I6a9fb774825f0cc4ce104c6e51d7b2fe16957aec --- src/core/cpn/DatabaseCampaign.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/cpn/DatabaseCampaign.cc b/src/core/cpn/DatabaseCampaign.cc index 365a896b..b9832275 100644 --- a/src/core/cpn/DatabaseCampaign.cc +++ b/src/core/cpn/DatabaseCampaign.cc @@ -134,14 +134,15 @@ bool DatabaseCampaign::run_variant(Database::Variant variant) { * other, collect_result_thread() may even starve until the memory for the * JobServer's "done" queue runs out, resulting in a crash and the loss of * all queued results. */ - db->query("CREATE TEMPORARY TABLE IF NOT EXISTS result_ids (pilot_id INT NOT NULL PRIMARY KEY)"); + db->query("CREATE TEMPORARY TABLE IF NOT EXISTS result_ids (pilot_id INT NOT NULL PRIMARY KEY, count INT NOT NULL)"); db->query("TRUNCATE TABLE result_ids"); std::stringstream ss; ss << "INSERT INTO result_ids " - << "SELECT r.pilot_id FROM " << db_connect.result_table() << " r " + << "SELECT r.pilot_id, COUNT(*) FROM " << db_connect.result_table() << " r " << "JOIN fsppilot p ON r.pilot_id = p.id " << "WHERE p.fspmethod_id = " << fspmethod_id - << " AND p.variant_id = " << variant.id; + << " AND p.variant_id = " << variant.id + << " GROUP BY r.pilot_id"; db->query(ss.str().c_str()); ss.str(""); @@ -149,10 +150,12 @@ bool DatabaseCampaign::run_variant(Database::Variant variant) { int experiment_count; std::string sql_select = "SELECT p.id, p.fspmethod_id, p.variant_id, p.injection_instr, p.injection_instr_absolute, p.data_address, p.data_width "; ss << " FROM fsppilot p " + << " LEFT JOIN result_ids r ON r.pilot_id = p.id" << " WHERE p.fspmethod_id = " << fspmethod_id << " AND p.variant_id = " << variant.id - << " AND (SELECT COUNT(*) FROM result_ids as r WHERE r.pilot_id = p.id)" + << " AND (r.count" << " < " << expected_number_of_results(variant.variant, variant.benchmark) + << " OR r.count IS NULL)" << " ORDER BY p.injection_instr"; std::string sql_body = ss.str();