[MXS-1964] Master is taken from last row of SHOW ALL SLAVES STATUS Created: 2018-07-06  Updated: 2018-07-31  Resolved: 2018-07-31

Status: Closed
Project: MariaDB MaxScale
Component/s: mariadbmon
Affects Version/s: 2.0.6, 2.1.17, 2.2.11
Fix Version/s: 2.3.0

Type: Bug Priority: Major
Reporter: markus makela Assignee: Esa Korhonen
Resolution: Done Votes: 0
Labels: None


 Description   

When a slave has more than one configured replication source, mariadbmon will use the last one that is returned by SHOW ALL SLAVES STATUS. This causes various problems which would all be solved by only inspecting the default replication source (i.e. @@default_master_connection).



 Comments   
Comment by markus makela [ 2018-07-06 ]

The following patch would ignore all non-default replication configurations.

diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc
index 8d9fe779e..dc2972db4 100644
--- a/server/modules/monitor/mariadbmon/mariadbmon.cc
+++ b/server/modules/monitor/mariadbmon/mariadbmon.cc
@@ -1407,6 +1407,29 @@ static enum mysql_server_version get_server_version(MXS_MONITORED_SERVER* db)
     return MYSQL_SERVER_VERSION_51;
 }
 
+std::string get_result(MYSQL* conn, const char* query)
+{
+    std::string rval;
+
+    if (mxs_mysql_query(conn, query) == 0)
+    {
+        if (MYSQL_RES* result = mysql_store_result(conn))
+        {
+            if (MYSQL_ROW row = mysql_fetch_row(result))
+            {
+                if (row[0])
+                {
+                    rval = row[0];
+                }
+            }
+
+            mysql_free_result(result);
+        }
+    }
+
+    return rval;
+}
+
 static bool do_show_slave_status(MYSQL_MONITOR* mon,
                                  MySqlServerInfo* serv_info,
                                  MXS_MONITORED_SERVER* database)
@@ -1443,6 +1466,8 @@ static bool do_show_slave_status(MYSQL_MONITOR* mon,
     int nconfigured = 0;
     int nrunning = 0;
 
+    std::string source_name = get_result(database->con, "SELECT @@default_master_connection");
+
     if (mxs_mysql_query(database->con, query) == 0
         && (result = mysql_store_result(database->con)) != NULL)
     {
@@ -1454,14 +1479,20 @@ static bool do_show_slave_status(MYSQL_MONITOR* mon,
             return false;
         }
 
-        MYSQL_ROW row = mysql_fetch_row(result);
-
-        if (row)
+        if (mysql_num_rows(result) > 0)
         {
             serv_info->slave_configured = true;
 
-            do
+            while (MYSQL_ROW row = mysql_fetch_row(result))
             {
+                ss_dassert(row[0]);
+
+                if (source_name != row[0])
+                {
+                    // Not the default replication configuration, skip it
+                    continue;
+                }
+
                 /* get Slave_IO_Running and Slave_SQL_Running values*/
                 serv_info->slave_status.slave_io_running = strncmp(row[i_slave_io_running], "Yes", 3) == 0;
                 serv_info->slave_status.slave_sql_running = strncmp(row[i_slave_sql_running], "Yes", 3) == 0;
@@ -1542,9 +1573,7 @@ static bool do_show_slave_status(MYSQL_MONITOR* mon,
                 }
 
                 nconfigured++;
-                row = mysql_fetch_row(result);
             }
-            while (row);
         }
         else
         {

As a side-effect, stopping non-default slaves would have no effect on the slave's status in MaxScale. Currently the slave would be considered broken as not all replication sources would be running. This behavior can be considered as a bug as one could expect only the default master connection to be used.

Comment by markus makela [ 2018-07-31 ]

Solved as a part of monitor refactoring.

Generated at Thu Feb 08 04:10:42 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.