Fix monitor connection error messages
The connection is closed by the ping_or_connect_to_db function which causes the information about why the connection failed to be lost.
This commit is contained in:
@ -246,6 +246,8 @@ private:
|
|||||||
const SERVER::DiskSpaceLimits& monitor_limits; /**< Monitor-level disk-space limits */
|
const SERVER::DiskSpaceLimits& monitor_limits; /**< Monitor-level disk-space limits */
|
||||||
|
|
||||||
bool ok_to_check_disk_space {true}; /**< Set to false if check fails */
|
bool ok_to_check_disk_space {true}; /**< Set to false if check fails */
|
||||||
|
|
||||||
|
std::string latest_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -268,10 +270,13 @@ public:
|
|||||||
* @param pServer A server
|
* @param pServer A server
|
||||||
* @param ppConn Address of pointer to a MYSQL instance. The instance should either be
|
* @param ppConn Address of pointer to a MYSQL instance. The instance should either be
|
||||||
* valid or NULL.
|
* valid or NULL.
|
||||||
|
* @param pError Pointer to a string where the error message is stored
|
||||||
|
*
|
||||||
* @return Connection status.
|
* @return Connection status.
|
||||||
*/
|
*/
|
||||||
static MonitorServer::ConnectResult
|
static MonitorServer::ConnectResult
|
||||||
ping_or_connect_to_db(const MonitorServer::ConnectionSettings& sett, SERVER& server, MYSQL** ppConn);
|
ping_or_connect_to_db(const MonitorServer::ConnectionSettings& sett,
|
||||||
|
SERVER& server, MYSQL** ppConn, std::string* pError);
|
||||||
|
|
||||||
static bool connection_is_ok(MonitorServer::ConnectResult connect_result);
|
static bool connection_is_ok(MonitorServer::ConnectResult connect_result);
|
||||||
|
|
||||||
|
@ -1125,9 +1125,11 @@ int Monitor::launch_command(MonitorServer* ptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MonitorServer::ConnectResult
|
MonitorServer::ConnectResult
|
||||||
Monitor::ping_or_connect_to_db(const MonitorServer::ConnectionSettings& sett, SERVER& server, MYSQL** ppConn)
|
Monitor::ping_or_connect_to_db(const MonitorServer::ConnectionSettings& sett,
|
||||||
|
SERVER& server, MYSQL** ppConn, std::string* pError)
|
||||||
{
|
{
|
||||||
mxb_assert(ppConn);
|
mxb_assert(ppConn);
|
||||||
|
mxb_assert(pError);
|
||||||
auto pConn = *ppConn;
|
auto pConn = *ppConn;
|
||||||
if (pConn)
|
if (pConn)
|
||||||
{
|
{
|
||||||
@ -1137,6 +1139,7 @@ Monitor::ping_or_connect_to_db(const MonitorServer::ConnectionSettings& sett, SE
|
|||||||
return ConnectResult::OLDCONN_OK;
|
return ConnectResult::OLDCONN_OK;
|
||||||
}
|
}
|
||||||
/** Otherwise close the handle. */
|
/** Otherwise close the handle. */
|
||||||
|
*pError = mysql_error(pConn);
|
||||||
mysql_close(pConn);
|
mysql_close(pConn);
|
||||||
pConn = nullptr;
|
pConn = nullptr;
|
||||||
}
|
}
|
||||||
@ -1176,6 +1179,7 @@ Monitor::ping_or_connect_to_db(const MonitorServer::ConnectionSettings& sett, SE
|
|||||||
conn_result = ConnectResult::TIMEOUT;
|
conn_result = ConnectResult::TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*pError = mysql_error(pConn);
|
||||||
auto err = mysql_errno(pConn);
|
auto err = mysql_errno(pConn);
|
||||||
mysql_close(pConn);
|
mysql_close(pConn);
|
||||||
pConn = nullptr;
|
pConn = nullptr;
|
||||||
@ -1193,7 +1197,7 @@ Monitor::ping_or_connect_to_db(const MonitorServer::ConnectionSettings& sett, SE
|
|||||||
|
|
||||||
ConnectResult MonitorServer::ping_or_connect(const ConnectionSettings& settings)
|
ConnectResult MonitorServer::ping_or_connect(const ConnectionSettings& settings)
|
||||||
{
|
{
|
||||||
return Monitor::ping_or_connect_to_db(settings, *server, &con);
|
return Monitor::ping_or_connect_to_db(settings, *server, &con, &latest_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1231,7 +1235,7 @@ void MonitorServer::log_connect_error(ConnectResult rval)
|
|||||||
server->name(),
|
server->name(),
|
||||||
server->address,
|
server->address,
|
||||||
server->port,
|
server->port,
|
||||||
mysql_error(con));
|
latest_error.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonitorServer::log_state_change()
|
void MonitorServer::log_state_change()
|
||||||
|
@ -208,7 +208,8 @@ bool xpand::ping_or_connect_to_hub(const char* zName,
|
|||||||
MYSQL** ppCon)
|
MYSQL** ppCon)
|
||||||
{
|
{
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
MonitorServer::ConnectResult rv = Monitor::ping_or_connect_to_db(settings, server, ppCon);
|
std::string err;
|
||||||
|
MonitorServer::ConnectResult rv = Monitor::ping_or_connect_to_db(settings, server, ppCon, &err);
|
||||||
|
|
||||||
if (Monitor::connection_is_ok(rv))
|
if (Monitor::connection_is_ok(rv))
|
||||||
{
|
{
|
||||||
@ -229,7 +230,7 @@ bool xpand::ping_or_connect_to_hub(const char* zName,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("%s: Could either not ping or create connection to %s:%d: %s",
|
MXS_ERROR("%s: Could either not ping or create connection to %s:%d: %s",
|
||||||
zName, server.address, server.port, mysql_error(*ppCon));
|
zName, server.address, server.port, err.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return connected;
|
return connected;
|
||||||
|
Reference in New Issue
Block a user