From 8721c9117ad3abc5fb6793f7cf12c8b314cff9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 11 Jun 2018 09:31:18 +0300 Subject: [PATCH] Expose function for checking MYSQL connection errors If a query done via the connector fails, the return value can be inspected with the function. This helps separate fatal problems from transient ones. --- include/maxscale/mysql_utils.h | 7 +++++++ server/core/mysql_utils.cc | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/maxscale/mysql_utils.h b/include/maxscale/mysql_utils.h index 7bb1f68b5..8c1f50a16 100644 --- a/include/maxscale/mysql_utils.h +++ b/include/maxscale/mysql_utils.h @@ -41,6 +41,13 @@ char* mxs_lestr_consume(uint8_t** c, size_t *size); */ MYSQL* mxs_mysql_real_connect(MYSQL *mysql, SERVER *server, const char *user, const char *passwd); +/** + * Check if the MYSQL error number is a connection error + * + * @return True if the MYSQL error number is a connection error + */ +bool mxs_mysql_is_net_error(int errcode); + /** * Execute a query * diff --git a/server/core/mysql_utils.cc b/server/core/mysql_utils.cc index f09e5ed89..2218fe5bc 100644 --- a/server/core/mysql_utils.cc +++ b/server/core/mysql_utils.cc @@ -217,7 +217,7 @@ MYSQL *mxs_mysql_real_connect(MYSQL *con, SERVER *server, const char *user, cons return mysql; } -static bool is_connection_error(int errcode) +bool mxs_mysql_is_net_error(int errcode) { switch (errcode) { @@ -242,7 +242,7 @@ int mxs_mysql_query(MYSQL* conn, const char* query) int rc = mysql_query(conn, query); for (int n = 0; rc != 0 && n < cnf->query_retries && - is_connection_error(mysql_errno(conn)) && + mxs_mysql_is_net_error(mysql_errno(conn)) && time(NULL) - start < cnf->query_retry_timeout; n++) { rc = mysql_query(conn, query);