From 2a38902aa640efa40f06c33b49bf8cdfca1f8f78 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Tue, 24 Apr 2018 10:59:00 +0300 Subject: [PATCH] MXS-1639 Discard results when executing sql text files This removes the limitation of not returning resultsets. --- Documentation/Monitors/MariaDB-Monitor.md | 13 +++++++++---- server/modules/monitor/mariadbmon/mariadbmon.cc | 9 ++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Documentation/Monitors/MariaDB-Monitor.md b/Documentation/Monitors/MariaDB-Monitor.md index 0ceff9a34..5528c3408 100644 --- a/Documentation/Monitors/MariaDB-Monitor.md +++ b/Documentation/Monitors/MariaDB-Monitor.md @@ -446,10 +446,15 @@ servers_no_promotion=backup_dc_server1,backup_dc_server2 #### `promotion_sql_file` and `demotion_sql_file` -These are paths to text files with SQL statements in them. During promotion or -demotion, the contents are read line-by-line and executed on the backend. Empty -lines or lines starting with '#' are ignored. All statements must succeed and -none may return results, otherwise the switchover or failover fails. +These optional settings are paths to text files with SQL statements in them. +During promotion or demotion, the contents are read line-by-line and executed on +the backend. Use these settings to execute custom statements on the servers to +complement the built-in operations. + +Empty lines or lines starting with '#' are ignored. Any results returned by the +statements are ignored. All statements must succeed for the failover, switchover +or rejoin to continue. The monitor user may require additional privileges and +grants for the custom commands to succeed. When promoting a slave to master during switchover or failover, the `promotion_sql_file` is read and executed on the new master server after its diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index 464fd3ef9..33e89ac77 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -4919,7 +4919,8 @@ static int64_t scan_server_id(const char* id_string) } /** - * Read the file contents and send them as sql queries to the server. Queries should not return any data. + * Read the file contents and send them as sql queries to the server. Any data returned by the queries is + * discarded. * * @param server Server to send queries to * @param path Text file path. @@ -4953,6 +4954,12 @@ static bool run_sql_from_file(MXS_MONITORED_SERVER* server, const string& path, if (mxs_mysql_query(conn, line.c_str()) == 0) { lines_executed++; + // Discard results if any. + MYSQL_RES* res = mysql_store_result(conn); + if (res != NULL) + { + mysql_free_result(res); + } } else {