Commit 6189b177 authored by Carla Guillen Carias's avatar Carla Guillen Carias

Bugfix

parent 8a184a8b
......@@ -84,14 +84,13 @@ void JobCache::addJobToCache(const std::string uid, int number_of_nodes, const s
_jobCacheMap[createIdJobCache(uid, number_of_nodes, job_id_string)] = ji;
}
bool JobCache::findJobInCache(const std::string uid, int number_of_nodes, const std::string &job_id_string, Job_info_t * job_info){
Job_info_t * JobCache::find(const std::string uid, int number_of_nodes, const std::string &job_id_string){
auto found = _jobCacheMap.find(createIdJobCache(uid, number_of_nodes, job_id_string));
if(found != _jobCacheMap.end()){ //found
job_info = &(found->second);
job_info->last_seen_timestamp = getTimestamp();
return true;
found->second.last_seen_timestamp = getTimestamp();
return &(found->second);
}
return false;
return nullptr;
}
/**************MariaDB****************/
......@@ -153,14 +152,14 @@ MariaDB::~MariaDB(){
bool MariaDB::getDBJobID(const std::string & job_id_string, std::string& job_db_id, const std::string & user, int number_nodes) {
std::lock_guard<std::mutex> lock(mut);
Job_info_t *job_info=nullptr;
if(_jobCache.findJobInCache(user, number_nodes, job_id_string, job_info)){ //found
Job_info_t *job_info=_jobCache.find(user, number_nodes, job_id_string);
if(job_info){ //found
job_db_id = job_info->job_id_db;
return true; //job found
}
std::stringstream build_query;
build_query << "SELECT job_id, job_id_string FROM Accounting WHERE job_id_string LIKE '" << job_id_string << "' AND user LIKE '" << user << "'";
build_query << "SELECT job_id, job_id_string FROM Accounting WHERE job_id_string='" << job_id_string << "' AND user='" << user << "'";
build_query << " AND nodes=" << number_nodes;
auto query = build_query.str();
LOG(debug)<< query;
......@@ -228,8 +227,8 @@ bool MariaDB::getCurrentSuffixAggregateTable(std::string & suffix){
bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string& uid, std::string & job_id_db, const std::string & suffix, int number_nodes){
std::lock_guard<std::mutex> lock(mut);
//maybe another thread did this for us
Job_info_t *job_info=nullptr;
if(_jobCache.findJobInCache(uid,number_nodes, job_id_string, job_info )){
Job_info_t *job_info=_jobCache.find(uid,number_nodes, job_id_string);
if(job_info){
job_id_db = job_info->job_id_db;
return true;
}
......@@ -359,9 +358,9 @@ bool MariaDB::createNewAggregate(std::string& new_suffix){
bool MariaDB::updateJobsLastSuffix(const std::string & job_id_string, const std::string & user, int number_nodes, const std::string& job_id_db, std::string & suffix){
std::lock_guard<std::mutex> lock(mut);
Job_info_t* job_info = nullptr;
if(_jobCache.findJobInCache(user, number_nodes, job_id_string, job_info)){ //found
if(job_info->job_current_table_suffix.empty() ||job_info->job_current_table_suffix != suffix){
Job_info_t* job_info = _jobCache.find(user, number_nodes, job_id_string);
if(job_info){ //found
if(job_info->job_current_table_suffix.empty() || job_info->job_current_table_suffix != suffix){
job_info->job_current_table_suffix = suffix; //set new suffix
//must update;
} else {
......
......@@ -57,7 +57,7 @@ private:
const std::size_t JOB_CACHE_MAX_SIZE = 10000;
public:
void addJobToCache(const std::string uid, int number_of_nodes, const std::string &job_id_string, const std::string & job_id_db);
bool findJobInCache(const std::string uid, int number_of_nodes, const std::string &job_id_string, Job_info_t * job_info);
Job_info_t * find(const std::string uid, int number_of_nodes, const std::string &job_id_string);
};
class MariaDB {
......
......@@ -184,11 +184,10 @@ void PerSystSqlOperator::compute(U_Ptr unit, qeJobData& jobData) {
LOG(error) << "Failed to create Aggregate table!";
return;
}
if(!_persystdb->getDBJobID(jobData.jobId, agg_info.job_id_db, jobData.userId, jobData.nodes.size())){
if(!_persystdb->insertIntoJob(jobData.jobId, jobData.userId, agg_info.job_id_db, table_suffix, jobData.nodes.size())){
if(!_persystdb->getDBJobID(jobData.jobId, agg_info.job_id_db, jobData.userId, jobData.nodes.size()) &&
!_persystdb->insertIntoJob(jobData.jobId, jobData.userId, agg_info.job_id_db, table_suffix, jobData.nodes.size()) ){
LOG(error) << "Job insertion not possible, no job id db available for slurm job id" << jobData.jobId;
return;
}
}
_persystdb->updateJobsLastSuffix(jobData.jobId, jobData.userId, jobData.nodes.size(), agg_info.job_id_db, table_suffix);
......
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