Commit 595348fb authored by Carla Guillen Carias's avatar Carla Guillen Carias
Browse files

Adding update of last_suffix in all jobs

parent 574f4ebb
......@@ -223,12 +223,7 @@ bool PerSystDB::insertIntoJob(const std::string& job_id_string, const std::strin
std::lock_guard<std::mutex> lock(mut);
std::stringstream build_insert;
build_insert << "INSERT INTO Accounting (job_id_string, user, aggregate_first_suffix, aggregate_last_suffix) VALUES (\'" << job_id_string << "\',\'";
auto* pass = getpwuid(static_cast<uid_t>(std::stoull(uid)));
if (pass == nullptr) {
LOG(error)<< "User " << uid << " not found in system.";
return false;
}
build_insert << pass->pw_name << "\',\'";
build_insert << uid << "\',\'";
build_insert << suffix << "\',\'" << suffix << "\')";
std::string query = build_insert.str();
LOG(debug)<< query;
......@@ -321,35 +316,38 @@ bool PerSystDB::createNewAggregate(std::string& new_suffix){
bool PerSystDB::updateJobsLastSuffix(std::map<std::string, std::string>& job_map, std::string & suffix){
std::stringstream build_update;
build_update << "UPDATE Accounting SET aggregate_last_suffix=\'" << suffix << "\' WHERE job_id IN (";
unsigned int count = 0;
for(auto & kv: job_map){
build_update << kv.second;
if(count + 1 != job_map.size() ){
build_update << ",";
} else {
build_update << ")";
}
count++;
}
auto query = build_update.str();
LOG(debug) << query;
std::lock_guard<std::mutex> lock(mut);
std::stringstream build_update;
build_update << "UPDATE Accounting SET aggregate_last_suffix=\'" << suffix
<< "\' WHERE job_id IN (";
unsigned int count = 0;
for (auto & kv : job_map) {
build_update << kv.second;
if (count + 1 != job_map.size()) {
build_update << ",";
} else {
build_update << ")";
}
count++;
}
auto query = build_update.str();
LOG(debug)<< query;
if (mysql_real_query(_mysql, query.c_str(), query.size())){
print_error();
return false;
}
return true;
if (mysql_real_query(_mysql, query.c_str(), query.size())) {
print_error();
return false;
}
return true;
}
bool PerSystDB::getTableSuffix(std::string & table_suffix){
std::lock_guard<std::mutex> lock(mut);
if(!getCurrentSuffixAggregateTable(table_suffix) && !createNewAggregate(table_suffix)){
return false;
}
return true;
std::lock_guard<std::mutex> lock(mut);
if (!getCurrentSuffixAggregateTable(table_suffix)
&& !createNewAggregate(table_suffix)) {
return false;
}
return true;
}
void PerSystDB::getNewDates(const std::string& last_end_timestamp, std::string & begin_timestamp, std::string & end_timestamp){
......
......@@ -187,6 +187,7 @@ void PerSystSqlOperator::compute(U_Ptr unit, qeJobData& jobData) {
return;
}
// handle jobs which are not present
for(auto &job_id_string : job_ids ){
auto search = job_map.find(job_id_string);
......@@ -198,11 +199,12 @@ void PerSystSqlOperator::compute(U_Ptr unit, qeJobData& jobData) {
continue;
}
} else { //found
agg_info.job_id_db = search->second;
}
agg_info.job_id_db = search->second;
}
}
agg_info.timestamp = (my_timestamp/1e9);
_persystdb->updateJobsLastSuffix(job_map, table_suffix);
agg_info.timestamp = (my_timestamp/1e9);
_persystdb->insertInAggregateTable(table_suffix, agg_info);
}
}
......
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