1 /* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #include "member_info.h"
24 #include "plugin.h"
25 #include "asynchronous_channels_state_observer.h"
26 
27 Asynchronous_channels_state_observer::
Asynchronous_channels_state_observer()28 Asynchronous_channels_state_observer()
29 {}
30 
31 int Asynchronous_channels_state_observer::
thread_start(Binlog_relay_IO_param * param)32 thread_start(Binlog_relay_IO_param* param)
33 {
34   /* Can't start slave relay io thread when group replication is running on
35      single primary-mode on secondary */
36   if (plugin_is_group_replication_running() &&
37       strcmp(param->channel_name, "group_replication_recovery") != 0 &&
38       strcmp(param->channel_name, "group_replication_applier") != 0 &&
39       group_member_mgr)
40   {
41     std::string m_uuid;
42     group_member_mgr->get_primary_member_uuid(m_uuid);
43 
44     if (m_uuid == "UNDEFINED")
45     {
46       log_message(MY_ERROR_LEVEL, "Can't start slave IO THREAD when group"
47                                   " replication is running with single"
48                                   " primary-mode and the primary member is"
49                                   " not known.");
50       return 1;
51     }
52 
53     if (m_uuid != local_member_info->get_uuid())
54     {
55       log_message(MY_ERROR_LEVEL, "Can't start slave IO THREAD when group"
56                                   " replication is running with single"
57                                   " primary-mode on a secondary member.");
58       return 1;
59     }
60   }
61 
62   return 0;
63 }
64 
thread_stop(Binlog_relay_IO_param *)65 int Asynchronous_channels_state_observer::thread_stop(Binlog_relay_IO_param*)
66 {
67   return 0;
68 }
69 
70 int Asynchronous_channels_state_observer::
applier_start(Binlog_relay_IO_param * param)71 applier_start(Binlog_relay_IO_param *param)
72 {
73   /* Can't start slave relay sql thread when group replication is running on
74      single primary-mode on secondary */
75   if (plugin_is_group_replication_running() &&
76       strcmp(param->channel_name, "group_replication_recovery") != 0 &&
77       strcmp(param->channel_name, "group_replication_applier") != 0 &&
78       group_member_mgr)
79   {
80     std::string m_uuid;
81     group_member_mgr->get_primary_member_uuid(m_uuid);
82 
83     if (m_uuid == "UNDEFINED")
84     {
85       log_message(MY_ERROR_LEVEL, "Can't start slave SQL THREAD when group"
86                                   " replication is running with single"
87                                   " primary-mode and the primary member is"
88                                   " not known.");
89       return 1;
90     }
91 
92     if (m_uuid != local_member_info->get_uuid())
93     {
94       log_message(MY_ERROR_LEVEL, "Can't start slave SQL THREAD when group"
95                                   " replication is running with single"
96                                   " primary-mode on a secondary member.");
97       return 1;
98     }
99   }
100 
101   return 0;
102 }
103 
104 int Asynchronous_channels_state_observer::
applier_stop(Binlog_relay_IO_param * param,bool aborted)105 applier_stop(Binlog_relay_IO_param *param, bool aborted)
106 {
107   return 0;
108 }
109 
110 int Asynchronous_channels_state_observer::
before_request_transmit(Binlog_relay_IO_param *,uint32)111 before_request_transmit(Binlog_relay_IO_param*,
112                         uint32)
113 {
114   return 0;
115 }
116 
117 int Asynchronous_channels_state_observer::
after_read_event(Binlog_relay_IO_param *,const char *,unsigned long,const char **,unsigned long *)118 after_read_event(Binlog_relay_IO_param*,
119                  const char*, unsigned long,
120                  const char**,
121                  unsigned long*)
122 {
123   return 0;
124 }
125 
126 int Asynchronous_channels_state_observer::
after_queue_event(Binlog_relay_IO_param *,const char *,unsigned long,uint32)127 after_queue_event(Binlog_relay_IO_param*,
128                   const char*,
129                   unsigned long,
130                   uint32)
131 {
132   return 0;
133 }
134 
135 int Asynchronous_channels_state_observer::
after_reset_slave(Binlog_relay_IO_param *)136 after_reset_slave(Binlog_relay_IO_param*)
137 {
138   return 0;
139 }
140