Commit 4904e57d authored by Carla Guillen's avatar Carla Guillen
Browse files

Optimizing with more fine grained locks.

parent 62e58e94
...@@ -117,13 +117,16 @@ MariaDB::~MariaDB(){ ...@@ -117,13 +117,16 @@ MariaDB::~MariaDB(){
} }
bool MariaDB::getDBJobIDs(std::vector<std::string> & job_id_strings, std::map<std::string, std::string>& job_id_map) { bool MariaDB::getDBJobIDs(std::vector<std::string> & job_id_strings, std::map<std::string, std::string>& job_id_map) {
std::lock_guard<std::mutex> lock(mut);
std::vector<std::string> notfound; std::vector<std::string> notfound;
std::unique_lock<std::mutex> lock(mut);
lock.unlock();
for(auto & job_id_str: job_id_strings){ for(auto & job_id_str: job_id_strings){
auto found = _jobCache.find(job_id_str); auto found = _jobCache.find(job_id_str);
if(found != _jobCache.end()){ if(found != _jobCache.end()){
job_id_map[job_id_str] = found->second.job_id_db; job_id_map[job_id_str] = found->second.job_id_db;
lock.lock();
found->second.last_seen_timestamp = getTimestamp(); found->second.last_seen_timestamp = getTimestamp();
lock.unlock();
} else { } else {
notfound.push_back(job_id_str); notfound.push_back(job_id_str);
} }
...@@ -142,6 +145,7 @@ bool MariaDB::getDBJobIDs(std::vector<std::string> & job_id_strings, std::map<st ...@@ -142,6 +145,7 @@ bool MariaDB::getDBJobIDs(std::vector<std::string> & job_id_strings, std::map<st
build_query << ")"; build_query << ")";
auto query = build_query.str(); auto query = build_query.str();
LOG(debug)<< query; LOG(debug)<< query;
lock.lock();
if (mysql_real_query(_mysql, query.c_str(), query.size())) { if (mysql_real_query(_mysql, query.c_str(), query.size())) {
print_error(); print_error();
return false; return false;
...@@ -217,7 +221,6 @@ bool MariaDB::getCurrentSuffixAggregateTable(std::string & suffix){ ...@@ -217,7 +221,6 @@ bool MariaDB::getCurrentSuffixAggregateTable(std::string & suffix){
bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string& uid, int & job_id_db, const std::string & suffix){ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string& uid, int & job_id_db, const std::string & suffix){
std::lock_guard<std::mutex> lock(mut);
std::stringstream build_insert; std::stringstream build_insert;
build_insert << "INSERT INTO Accounting (job_id_string, user, aggregate_first_suffix, aggregate_last_suffix) VALUES (\'" << job_id_string << "\',\'"; build_insert << "INSERT INTO Accounting (job_id_string, user, aggregate_first_suffix, aggregate_last_suffix) VALUES (\'" << job_id_string << "\',\'";
build_insert << uid << "\',\'"; build_insert << uid << "\',\'";
...@@ -225,6 +228,7 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string& ...@@ -225,6 +228,7 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string&
std::string query = build_insert.str(); std::string query = build_insert.str();
LOG(debug)<< query; LOG(debug)<< query;
std::lock_guard<std::mutex> lock(mut);
if (mysql_real_query(_mysql, query.c_str(), query.size())) { if (mysql_real_query(_mysql, query.c_str(), query.size())) {
print_error(); print_error();
return false; return false;
...@@ -235,7 +239,6 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string& ...@@ -235,7 +239,6 @@ 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::lock_guard<std::mutex> lock(mut);
std::stringstream build_insert; std::stringstream build_insert;
build_insert << "INSERT INTO Aggregate_" << suffix << " VALUES ( FROM_UNIXTIME(\'" << agg.timestamp; build_insert << "INSERT INTO Aggregate_" << suffix << " VALUES ( FROM_UNIXTIME(\'" << agg.timestamp;
build_insert << "\'), \'" << agg.job_id_db; build_insert << "\'), \'" << agg.job_id_db;
...@@ -249,6 +252,7 @@ bool MariaDB::insertInAggregateTable(const std::string& suffix, Aggregate_info_t ...@@ -249,6 +252,7 @@ bool MariaDB::insertInAggregateTable(const std::string& suffix, Aggregate_info_t
std::string query = build_insert.str(); std::string query = build_insert.str();
LOG(debug) << query; LOG(debug) << query;
std::lock_guard<std::mutex> lock(mut);
if(mysql_real_query(_mysql, query.c_str(), query.size())){ if(mysql_real_query(_mysql, query.c_str(), query.size())){
print_error(); print_error();
return false; return false;
...@@ -313,7 +317,6 @@ bool MariaDB::createNewAggregate(std::string& new_suffix){ ...@@ -313,7 +317,6 @@ bool MariaDB::createNewAggregate(std::string& new_suffix){
bool MariaDB::updateJobsLastSuffix(std::map<std::string, std::string>& job_map, std::string & suffix){ bool MariaDB::updateJobsLastSuffix(std::map<std::string, std::string>& job_map, std::string & suffix){
std::lock_guard<std::mutex> lock(mut);
std::stringstream build_update; std::stringstream build_update;
build_update << "UPDATE Accounting SET aggregate_last_suffix=\'" << suffix build_update << "UPDATE Accounting SET aggregate_last_suffix=\'" << suffix
<< "\' WHERE job_id IN ("; << "\' WHERE job_id IN (";
...@@ -330,6 +333,7 @@ bool MariaDB::updateJobsLastSuffix(std::map<std::string, std::string>& job_map, ...@@ -330,6 +333,7 @@ bool MariaDB::updateJobsLastSuffix(std::map<std::string, std::string>& job_map,
auto query = build_update.str(); auto query = build_update.str();
LOG(debug)<< query; LOG(debug)<< query;
std::lock_guard<std::mutex> lock(mut);
if (mysql_real_query(_mysql, query.c_str(), query.size())) { if (mysql_real_query(_mysql, query.c_str(), query.size())) {
print_error(); print_error();
return false; return false;
......
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