MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_mi.h
1 /* Copyright (c) 2006, 2011, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 #ifndef RPL_MI_H
17 #define RPL_MI_H
18 
19 #ifdef HAVE_REPLICATION
20 
21 #include <my_global.h>
22 #include <sql_priv.h>
23 
24 #define DEFAULT_CONNECT_RETRY 60
25 
26 #include "rpl_rli.h"
27 #include "my_sys.h"
28 
29 typedef struct st_mysql MYSQL;
30 class Rpl_info_factory;
31 
32 /*****************************************************************************
33  Replication IO Thread
34 
35  Master_info contains:
36  - information about how to connect to a master
37  - current master log name
38  - current master log offset
39  - misc control variables
40 
41  Master_info is initialized once from the master.info repository if such
42  exists. Otherwise, data members corresponding to master.info fields
43  are initialized with defaults specified by master-* options. The
44  initialization is done through mi_init_info() call.
45 
46  Logically, the format of master.info repository is presented as follows:
47 
48  log_name
49  log_pos
50  master_host
51  master_user
52  master_pass
53  master_port
54  master_connect_retry
55 
56  To write out the contents of master.info to disk a call to flush_info()
57  is required. Currently, it is needed every time we read and queue data
58  from the master.
59 
60  To clean up, call end_info()
61 
62 *****************************************************************************/
63 
64 class Master_info : public Rpl_info
65 {
66 friend class Rpl_info_factory;
67 
68 public:
72  char host[HOSTNAME_LENGTH + 1];
73 
74 private:
78  bool start_user_configured;
82  char user[USERNAME_LENGTH + 1];
86  char password[MAX_PASSWORD_LENGTH + 1];
90  char start_user[USERNAME_LENGTH + 1];
94  char start_password[MAX_PASSWORD_LENGTH + 1];
98  char start_plugin_auth[FN_REFLEN + 1];
103  char start_plugin_dir[FN_REFLEN + 1];
104 
105 public:
112  bool is_start_user_configured() const
113  {
114  return start_user_configured;
115  }
121  bool is_start_plugin_auth_configured() const
122  {
123  return (start_plugin_auth[0] != 0);
124  }
130  bool is_start_plugin_dir_configured() const
131  {
132  return (start_plugin_dir[0] != 0);
133  }
140  void set_start_user_configured(bool config)
141  {
142  start_user_configured= config;
143  }
151  void set_user(const char* user_arg)
152  {
153  if (user_arg && start_user_configured)
154  {
155  strmake(start_user, user_arg, sizeof(start_user) - 1);
156  }
157  else if (user_arg)
158  {
159  strmake(user, user_arg, sizeof(user) - 1);
160  }
161  }
162  /*
163  Returns user's size name. See @code get_user().
164 
165  @return user's size name.
166  */
167  size_t get_user_size() const
168  {
169  return (start_user_configured ? sizeof(start_user) : sizeof(user));
170  }
177  const char *get_user() const
178  {
179  return start_user_configured ? start_user : user;
180  }
191  bool set_password(const char* password_arg, int password_arg_size);
200  bool get_password(char *password_arg, int *password_arg_size);
204  void reset_start_info();
210  const char *get_start_plugin_auth()
211  {
212  return start_plugin_auth;
213  }
219  const char *get_start_plugin_dir()
220  {
221  return start_plugin_dir;
222  }
228  void set_plugin_auth(const char* src)
229  {
230  if (src)
231  strmake(start_plugin_auth, src, sizeof(start_plugin_auth) - 1);
232  }
238  void set_plugin_dir(const char* src)
239  {
240  if (src)
241  strmake(start_plugin_dir, src, sizeof(start_plugin_dir) - 1);
242  }
243 
244  my_bool ssl; // enables use of SSL connection if true
245  char ssl_ca[FN_REFLEN], ssl_capath[FN_REFLEN], ssl_cert[FN_REFLEN];
246  char ssl_cipher[FN_REFLEN], ssl_key[FN_REFLEN];
247  char ssl_crl[FN_REFLEN], ssl_crlpath[FN_REFLEN];
248  my_bool ssl_verify_server_cert;
249 
250  MYSQL* mysql;
251  uint32 file_id; /* for 3.23 load data infile */
252  Relay_log_info *rli;
253  uint port;
254  uint connect_retry;
255  /*
256  The difference in seconds between the clock of the master and the clock of
257  the slave (second - first). It must be signed as it may be <0 or >0.
258  clock_diff_with_master is computed when the I/O thread starts; for this the
259  I/O thread does a SELECT UNIX_TIMESTAMP() on the master.
260  "how late the slave is compared to the master" is computed like this:
261  clock_of_slave - last_timestamp_executed_by_SQL_thread - clock_diff_with_master
262 
263  */
264  long clock_diff_with_master;
265  float heartbeat_period; // interface with CHANGE MASTER or master.info
266  ulonglong received_heartbeats; // counter of received heartbeat events
267 
268  time_t last_heartbeat;
269 
270  Dynamic_ids *ignore_server_ids;
271 
272  ulong master_id;
273  /*
274  to hold checksum alg in use until IO thread has received FD.
275  Initialized to novalue, then set to the queried from master
276  @@global.binlog_checksum and deactivated once FD has been received.
277  */
278  uint8 checksum_alg_before_fd;
279  ulong retry_count;
280  char master_uuid[UUID_LENGTH+1];
281  char bind_addr[HOSTNAME_LENGTH+1];
282 
283  ulong master_gtid_mode;
284 
285  int mi_init_info();
286  void end_info();
287  int flush_info(bool force= FALSE);
288  void set_relay_log_info(Relay_log_info *info);
289 
290  bool shall_ignore_server_id(ulong s_id);
291 
292  virtual ~Master_info();
293 
294 protected:
295  char master_log_name[FN_REFLEN];
296  my_off_t master_log_pos;
297 
298 public:
299  void clear_in_memory_info(bool all);
300 
301  inline const char* get_master_log_name() { return master_log_name; }
302  inline ulonglong get_master_log_pos() { return master_log_pos; }
303  inline void set_master_log_name(const char *log_file_name)
304  {
305  strmake(master_log_name, log_file_name, sizeof(master_log_name) - 1);
306  }
307  inline void set_master_log_pos(ulonglong log_pos)
308  {
309  master_log_pos= log_pos;
310  }
311  inline const char* get_io_rpl_log_name()
312  {
313  return (master_log_name[0] ? master_log_name : "FIRST");
314  }
315  static size_t get_number_info_mi_fields();
316 
317  bool is_auto_position()
318  {
319  return auto_position;
320  }
321 
322  void set_auto_position(bool auto_position_param)
323  {
324  auto_position= auto_position_param;
325  }
326 
327 private:
346  Format_description_log_event *mi_description_event;
347 public:
348  Format_description_log_event *get_mi_description_event()
349  {
350  mysql_mutex_assert_owner(&data_lock);
351  return mi_description_event;
352  }
353  void set_mi_description_event(Format_description_log_event *fdle)
354  {
355  mysql_mutex_assert_owner(&data_lock);
356  delete mi_description_event;
357  mi_description_event= fdle;
358  }
359 
360 private:
361  void init_master_log_pos();
362 
363  bool read_info(Rpl_info_handler *from);
364  bool write_info(Rpl_info_handler *to);
365 
366  bool auto_position;
367 
368  Master_info(
369 #ifdef HAVE_PSI_INTERFACE
370  PSI_mutex_key *param_key_info_run_lock,
371  PSI_mutex_key *param_key_info_data_lock,
372  PSI_mutex_key *param_key_info_sleep_lock,
373  PSI_mutex_key *param_key_info_data_cond,
374  PSI_mutex_key *param_key_info_start_cond,
375  PSI_mutex_key *param_key_info_stop_cond,
376  PSI_mutex_key *param_key_info_sleep_cond,
377 #endif
378  uint param_id
379  );
380 
381  Master_info(const Master_info& info);
382  Master_info& operator=(const Master_info& info);
383 };
384 int change_master_server_id_cmp(ulong *id1, ulong *id2);
385 
386 #endif /* HAVE_REPLICATION */
387 #endif /* RPL_MI_H */