Commit 20509d76 authored by Carla Guillen's avatar Carla Guillen
Browse files

Adding more restrictive lock guards, adding error log with slurm job id

parent e86a45c3
......@@ -110,9 +110,9 @@ MariaDB * MariaDB::instance = nullptr;
std::mutex MariaDB::mut;
std::once_flag MariaDB::init_once;
void MariaDB::print_error(){
void MariaDB::print_error(std::string add_comment){
if(_initialized){
LOG(error) << "Error(" << mysql_errno(_mysql) << ") [" << mysql_sqlstate(_mysql) << "] \""<< mysql_error(_mysql) << "\"" ;
LOG(error) << "Error(" << mysql_errno(_mysql) << ") " << add_comment <<" [" << mysql_sqlstate(_mysql) << "] \""<< mysql_error(_mysql) << "\"" ;
if(mysql_errno(_mysql) == 2006){
mysql_close(_mysql);
_initialized=false;
......@@ -298,7 +298,8 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string&
}
bool MariaDB::insertInAggregateTable(const std::string& suffix, Aggregate_info_t & agg){
bool MariaDB::insertInAggregateTable(const std::string& suffix, Aggregate_info_t & agg, std::string & slurm_job_id){
std::lock_guard<std::mutex> lock(mut);
std::stringstream build_insert;
build_insert << "INSERT INTO Aggregate_" << suffix << " VALUES ( FROM_UNIXTIME(\'" << agg.timestamp;
build_insert << "\'), \'" << agg.job_id_db;
......@@ -312,9 +313,10 @@ bool MariaDB::insertInAggregateTable(const std::string& suffix, Aggregate_info_t
std::string query = build_insert.str();
LOG(debug) << query;
std::lock_guard<std::mutex> lock(mut);
if(_initialized && mysql_real_query(_mysql, query.c_str(), query.size())){
print_error();
std::stringstream build_job_id;
build_job_id << "SLURM_JOB_ID=" << slurm_job_id;
print_error(build_job_id.str());
return false;
}
return true;
......
......@@ -102,8 +102,10 @@ protected:
/** print error.
* Prints the mysql error message. If connection is gone (Error 2006) then we also close the connection.
* Please check with isInitialized() to initialize it again.
* String is NOT passed as reference to avoid having to pass always an empty string
*/
void print_error();
void print_error(std::string slurm_job_id="");
bool getCurrentSuffixAggregateTable(std::string & new_suffix);
bool createNewAggregate(std::string& new_suffix);
void getNewDates(const std::string& last_end_timestamp, std::string & begin_timestamp, std::string & end_timestamp);
......@@ -130,7 +132,7 @@ public:
* @param job_id_strings job id strings including array jobid.
* @param job_id_map job_id_string to job_id (db) map
*/
bool getDBJobID(const std::string & job_id_string, std::string& job_db_id, const std::string & user, int number_nodes, int batch_domain);
bool getDBJobID(const std::string & job_id_string, std::string& job_db_id, const std::string & user, int number_nodes, int batch_domain);
/**
* Insert job in the accounting table.
......@@ -140,7 +142,7 @@ public:
/**
* Insert performance data into the aggregate table (Aggregate_<suffix>)
*/
bool insertInAggregateTable(const std::string& suffix, Aggregate_info_t & agg_info);
bool insertInAggregateTable(const std::string& suffix, Aggregate_info_t & agg_info, std::string & slurm_job_id);
/**
* Update the last suffix in the Accounting table
......@@ -161,5 +163,4 @@ public:
};
#endif /* ANALYTICS_OPERATORS_PERSYSTSQL_MARIADB_H_ */
......@@ -214,7 +214,8 @@ void PerSystSqlOperator::compute(U_Ptr unit, qeJobData& jobData) {
_persystdb->updateJobsLastSuffix(jobData.jobId, jobData.userId, jobData.nodes.size(), agg_info.job_id_db, table_suffix);
_persystdb->insertInAggregateTable(table_suffix, agg_info);
_persystdb->insertInAggregateTable(table_suffix, agg_info, jobData.jobId);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment