Skip to content

Commit

Permalink
Improved error reporting on MySQL query failures
Browse files Browse the repository at this point in the history
  • Loading branch information
iagaponenko committed Jul 20, 2023
1 parent 1c42e62 commit bdb776b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/rproc/InfileMerger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ std::string getTimeStampId() {

const char JOB_ID_BASE_NAME[] = "jobId";
size_t const MB_SIZE_BYTES = 1024 * 1024;

/// @return Error info on the last operation with MySQL
string lastMysqlError(MYSQL* mysql) {
return "error: " + string(mysql_error(mysql)) + ", errno: " + to_string(mysql_errno(mysql));
}
} // anonymous namespace

namespace lsst::qserv::rproc {
Expand Down Expand Up @@ -349,27 +354,34 @@ bool InfileMerger::_applyMysqlMyIsam(std::string const& query) {
sleep(1);
lock.lock();
} else {
LOGS(_log, LOG_LVL_ERROR, "InfileMerger::_applyMysql _setupConnection() failed!!!");
LOGS(_log, LOG_LVL_ERROR,
"InfileMerger::_applyMysqlMyIsam _setupConnectionMyIsam() failed!!!");
return false; // Reconnection failed. This is an error.
}
}
}

int rc = mysql_real_query(_mysqlConn.getMySql(), query.data(), query.size());
return rc == 0;
if (rc == 0) return true;
LOGS(_log, LOG_LVL_ERROR,
"InfileMerger::_applyMysqlMyIsam mysql_real_query() " + ::lastMysqlError(_mysqlConn.getMySql()));
return false;
}

bool InfileMerger::_applyMysqlInnoDb(std::string const& query) {
mysql::MySqlConnection mySConn(_config.mySqlConfig);
if (!mySConn.connected()) {
if (!_setupConnectionInnoDb(mySConn)) {
LOGS(_log, LOG_LVL_ERROR, "InfileMerger::_applyMysql _setupConnection() failed!!!");
LOGS(_log, LOG_LVL_ERROR, "InfileMerger::_applyMysqlInnoDb _setupConnectionInnoDb() failed!!!");
return false; // Reconnection failed. This is an error.
}
}

int rc = mysql_real_query(mySConn.getMySql(), query.data(), query.size());
return rc == 0;
if (rc == 0) return true;
LOGS(_log, LOG_LVL_ERROR,
"InfileMerger::_applyMysqlInnoDb mysql_real_query() " + ::lastMysqlError(mySConn.getMySql()));
return false;
}

bool InfileMerger::_setupConnectionInnoDb(mysql::MySqlConnection& mySConn) {
Expand Down

0 comments on commit bdb776b

Please sign in to comment.