1 /* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. 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 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef RPL_INFO_H 24 #define RPL_INFO_H 25 26 #include "my_global.h" 27 #include "mysql_com.h" // NAME_LEN 28 #include "rpl_info_handler.h" // Rpl_info_handler 29 #include "rpl_reporting.h" // Slave_reporting_capability 30 #include "atomic_class.h" // Atomic_int32 31 32 33 #define CHANNEL_NAME_LENGTH NAME_LEN 34 35 class Rpl_info : public Slave_reporting_capability 36 { 37 public: 38 virtual ~Rpl_info(); 39 40 /* 41 standard lock acquisition order to avoid deadlocks: 42 run_lock, data_lock, relay_log.LOCK_log, relay_log.LOCK_index 43 run_lock, sleep_lock 44 run_lock, info_thd_lock 45 46 info_thd_lock is to protect operations on info_thd: 47 - before *reading* info_thd we must hold *either* info_thd_lock or 48 run_lock; 49 - before *writing* we must hold *both* run_lock and info_thd_lock. 50 */ 51 mysql_mutex_t data_lock, run_lock, sleep_lock, info_thd_lock; 52 /* 53 start_cond is broadcast when SQL thread is started 54 stop_cond - when stopped 55 data_cond - when data protected by data_lock changes 56 sleep_cond - when killed 57 58 'data_cond' is only being used in class Relay_log_info and not in the 59 class Master_info. So 'data_cond' could be moved to Relay_log_info. 60 */ 61 mysql_cond_t data_cond, start_cond, stop_cond, sleep_cond; 62 63 #ifdef HAVE_PSI_INTERFACE 64 PSI_mutex_key *key_info_run_lock, *key_info_data_lock, *key_info_sleep_lock, 65 *key_info_thd_lock; 66 67 PSI_mutex_key *key_info_data_cond, *key_info_start_cond, *key_info_stop_cond, 68 *key_info_sleep_cond; 69 #endif 70 71 THD *info_thd; 72 73 bool inited; 74 volatile bool abort_slave; 75 volatile uint slave_running; 76 volatile ulong slave_run_id; 77 78 #ifndef DBUG_OFF 79 int events_until_exit; 80 #endif 81 82 /** 83 Sets the persistency component/handler. 84 85 @param[in] hanlder Pointer to the handler. 86 */ set_rpl_info_handler(Rpl_info_handler * param_handler)87 void set_rpl_info_handler(Rpl_info_handler * param_handler) 88 { 89 handler= param_handler; 90 } 91 92 /** 93 Gets the persistency component/handler. 94 95 @return the handler if there is one. 96 */ get_rpl_info_handler()97 Rpl_info_handler *get_rpl_info_handler() 98 { 99 return (handler); 100 } 101 check_info()102 enum_return_check check_info() 103 { 104 return (handler->check_info()); 105 } 106 remove_info()107 int remove_info() 108 { 109 return (handler->remove_info()); 110 } 111 clean_info()112 int clean_info() 113 { 114 return (handler->clean_info()); 115 } 116 is_transactional()117 bool is_transactional() 118 { 119 return (handler->is_transactional()); 120 } 121 update_is_transactional()122 bool update_is_transactional() 123 { 124 return (handler->update_is_transactional()); 125 } 126 get_description_info()127 char *get_description_info() 128 { 129 return (handler->get_description_info()); 130 } 131 copy_info(Rpl_info_handler * from,Rpl_info_handler * to)132 bool copy_info(Rpl_info_handler *from, Rpl_info_handler *to) 133 { 134 if (read_info(from) || write_info(to)) 135 return(TRUE); 136 137 return(FALSE); 138 } 139 get_internal_id()140 uint get_internal_id() 141 { 142 return internal_id; 143 } 144 get_channel()145 char *get_channel() 146 { 147 return channel; 148 } 149 150 /** 151 To search in the slave repositories, each slave info object 152 (mi, rli or worker) should use a primary key. This function 153 sets the field values of the slave info objects with 154 the search information, which is nothing but PK in mysql slave 155 info tables. 156 Ex: field_value[23]="channel_name" in the master info 157 object. 158 159 Currently, used only for TABLE repository. 160 */ 161 162 virtual bool set_info_search_keys(Rpl_info_handler *to)= 0; 163 164 protected: 165 /** 166 Pointer to the repository's handler. 167 */ 168 Rpl_info_handler *handler; 169 170 /** 171 Uniquely and internaly identifies an info entry (.e.g. a row or 172 file). This information is completely transparent to users and 173 is used only during startup to retrieve information from the 174 repositories. 175 176 @todo, This is not anymore required for Master_info and 177 Relay_log_info, since Channel can be used to uniquely 178 identify this. To preserve backward compatibility, 179 we keep this for Master_info and Relay_log_info. 180 However, {id, channel} is still required for a worker info. 181 */ 182 uint internal_id; 183 184 /** 185 Every slave info object acts on a particular channel in Multisource 186 Replication. 187 */ 188 char channel[CHANNEL_NAME_LENGTH+1]; 189 190 Rpl_info(const char* type 191 #ifdef HAVE_PSI_INTERFACE 192 ,PSI_mutex_key *param_key_info_run_lock, 193 PSI_mutex_key *param_key_info_data_lock, 194 PSI_mutex_key *param_key_info_sleep_lock, 195 PSI_mutex_key *param_key_info_thd_lock, 196 PSI_mutex_key *param_key_info_data_cond, 197 PSI_mutex_key *param_key_info_start_cond, 198 PSI_mutex_key *param_key_info_stop_cond, 199 PSI_mutex_key *param_key_info_sleep_cond 200 #endif 201 ,uint param_id, const char* param_channel 202 ); 203 204 private: 205 virtual bool read_info(Rpl_info_handler *from)= 0; 206 virtual bool write_info(Rpl_info_handler *to)= 0; 207 208 Rpl_info(const Rpl_info& info); 209 Rpl_info& operator=(const Rpl_info& info); 210 211 public: 212 /* True when the thread is still running, but started the stop procedure */ 213 Atomic_int32 is_stopping; 214 }; 215 #endif /* RPL_INFO_H */ 216