From 32add4c08d5d9e0092ca1dd5bd11e6dae1b9e433 Mon Sep 17 00:00:00 2001 From: Igor Gaponenko Date: Wed, 19 Jul 2023 01:35:42 +0000 Subject: [PATCH] Improved error reporting on MySQL query failures --- src/rproc/InfileMerger.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rproc/InfileMerger.cc b/src/rproc/InfileMerger.cc index 487355722..f928ec3f6 100644 --- a/src/rproc/InfileMerger.cc +++ b/src/rproc/InfileMerger.cc @@ -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 { @@ -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) {