My Project
rpl_mi.h
00001 /* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software Foundation,
00014    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
00015 
00016 #ifndef RPL_MI_H
00017 #define RPL_MI_H
00018 
00019 #ifdef HAVE_REPLICATION
00020 
00021 #include <my_global.h>
00022 #include <sql_priv.h>
00023 
00024 #define DEFAULT_CONNECT_RETRY 60
00025 
00026 #include "rpl_rli.h"
00027 #include "my_sys.h"
00028 
00029 typedef struct st_mysql MYSQL;
00030 class Rpl_info_factory;
00031 
00032 /*****************************************************************************
00033   Replication IO Thread
00034 
00035   Master_info contains:
00036     - information about how to connect to a master
00037     - current master log name
00038     - current master log offset
00039     - misc control variables
00040 
00041   Master_info is initialized once from the master.info repository if such
00042   exists. Otherwise, data members corresponding to master.info fields
00043   are initialized with defaults specified by master-* options. The
00044   initialization is done through mi_init_info() call.
00045 
00046   Logically, the format of master.info repository is presented as follows:
00047 
00048   log_name
00049   log_pos
00050   master_host
00051   master_user
00052   master_pass
00053   master_port
00054   master_connect_retry
00055 
00056   To write out the contents of master.info to disk a call to flush_info()
00057   is required. Currently, it is needed every time we read and queue data
00058   from the master.
00059 
00060   To clean up, call end_info()
00061 
00062 *****************************************************************************/
00063 
00064 class Master_info : public Rpl_info
00065 {
00066 friend class Rpl_info_factory;
00067 
00068 public:
00072   char host[HOSTNAME_LENGTH + 1];
00073 
00074 private:
00078   bool start_user_configured;
00082   char user[USERNAME_LENGTH + 1];
00086   char password[MAX_PASSWORD_LENGTH + 1]; 
00090   char start_user[USERNAME_LENGTH + 1];
00094   char start_password[MAX_PASSWORD_LENGTH + 1]; 
00098   char start_plugin_auth[FN_REFLEN + 1];
00103   char start_plugin_dir[FN_REFLEN + 1];
00104 
00105 public:
00112   bool is_start_user_configured() const
00113   {
00114     return start_user_configured;
00115   }
00121   bool is_start_plugin_auth_configured() const
00122   {
00123     return (start_plugin_auth[0] != 0);
00124   }
00130   bool is_start_plugin_dir_configured() const
00131   {
00132     return (start_plugin_dir[0] != 0);
00133   }
00140   void set_start_user_configured(bool config)
00141   {
00142     start_user_configured= config;
00143   }
00151   void set_user(const char* user_arg)
00152   {
00153     if (user_arg && start_user_configured)
00154     {
00155       strmake(start_user, user_arg, sizeof(start_user) - 1);
00156     }
00157     else if (user_arg)
00158     {
00159       strmake(user, user_arg, sizeof(user) - 1);
00160     }
00161   }
00162   /*
00163     Returns user's size name. See @code get_user().
00164 
00165     @return user's size name.
00166   */
00167   size_t get_user_size() const
00168   {
00169     return (start_user_configured ? sizeof(start_user) : sizeof(user));
00170   }
00177   const char *get_user() const
00178   {
00179     return start_user_configured ? start_user : user;
00180   } 
00191   bool set_password(const char* password_arg, int password_arg_size);
00200   bool get_password(char *password_arg, int *password_arg_size);
00204   void reset_start_info();
00210   const char *get_start_plugin_auth()
00211   {
00212     return start_plugin_auth;
00213   }
00219   const char *get_start_plugin_dir()
00220   {
00221     return start_plugin_dir;
00222   }
00228   void set_plugin_auth(const char* src)
00229   {
00230     if (src)
00231       strmake(start_plugin_auth, src, sizeof(start_plugin_auth) - 1);
00232   }
00238   void set_plugin_dir(const char* src)
00239   {
00240     if (src)
00241       strmake(start_plugin_dir, src, sizeof(start_plugin_dir) - 1);
00242   }
00243 
00244   my_bool ssl; // enables use of SSL connection if true
00245   char ssl_ca[FN_REFLEN], ssl_capath[FN_REFLEN], ssl_cert[FN_REFLEN];
00246   char ssl_cipher[FN_REFLEN], ssl_key[FN_REFLEN];
00247   char ssl_crl[FN_REFLEN], ssl_crlpath[FN_REFLEN];
00248   my_bool ssl_verify_server_cert;
00249 
00250   MYSQL* mysql;
00251   uint32 file_id;                               /* for 3.23 load data infile */
00252   Relay_log_info *rli;
00253   uint port;
00254   uint connect_retry;
00255   /*
00256      The difference in seconds between the clock of the master and the clock of
00257      the slave (second - first). It must be signed as it may be <0 or >0.
00258      clock_diff_with_master is computed when the I/O thread starts; for this the
00259      I/O thread does a SELECT UNIX_TIMESTAMP() on the master.
00260      "how late the slave is compared to the master" is computed like this:
00261      clock_of_slave - last_timestamp_executed_by_SQL_thread - clock_diff_with_master
00262 
00263   */
00264   long clock_diff_with_master;
00265   float heartbeat_period;         // interface with CHANGE MASTER or master.info
00266   ulonglong received_heartbeats;  // counter of received heartbeat events
00267 
00268   time_t last_heartbeat;
00269 
00270   Dynamic_ids *ignore_server_ids;
00271 
00272   ulong master_id;
00273   /*
00274     to hold checksum alg in use until IO thread has received FD.
00275     Initialized to novalue, then set to the queried from master
00276     @@global.binlog_checksum and deactivated once FD has been received.
00277   */
00278   uint8 checksum_alg_before_fd;
00279   ulong retry_count;
00280   char master_uuid[UUID_LENGTH+1];
00281   char bind_addr[HOSTNAME_LENGTH+1];
00282 
00283   ulong master_gtid_mode;
00284 
00285   int mi_init_info();
00286   void end_info();
00287   int flush_info(bool force= FALSE);
00288   void set_relay_log_info(Relay_log_info *info);
00289 
00290   bool shall_ignore_server_id(ulong s_id);
00291 
00292   virtual ~Master_info();
00293 
00294 protected:
00295   char master_log_name[FN_REFLEN];
00296   my_off_t master_log_pos;
00297 
00298 public:
00299   void clear_in_memory_info(bool all);
00300 
00301   inline const char* get_master_log_name() { return master_log_name; }
00302   inline ulonglong get_master_log_pos() { return master_log_pos; }
00303   inline void set_master_log_name(const char *log_file_name)
00304   {
00305      strmake(master_log_name, log_file_name, sizeof(master_log_name) - 1);
00306   }
00307   inline void set_master_log_pos(ulonglong log_pos)
00308   {
00309     master_log_pos= log_pos;
00310   }
00311   inline const char* get_io_rpl_log_name()
00312   {
00313     return (master_log_name[0] ? master_log_name : "FIRST");
00314   }
00315   static size_t get_number_info_mi_fields();
00316 
00317   bool is_auto_position()
00318   {
00319     return auto_position;
00320   }
00321 
00322   void set_auto_position(bool auto_position_param)
00323   {
00324     auto_position= auto_position_param;
00325   }
00326 
00327 private:
00346   Format_description_log_event *mi_description_event;
00347 public:
00348   Format_description_log_event *get_mi_description_event()
00349   {
00350     mysql_mutex_assert_owner(&data_lock);
00351     return mi_description_event;
00352   }
00353   void set_mi_description_event(Format_description_log_event *fdle)
00354   {
00355     mysql_mutex_assert_owner(&data_lock);
00356     delete mi_description_event;
00357     mi_description_event= fdle;
00358   }
00359 
00360 private:
00361   void init_master_log_pos();
00362 
00363   bool read_info(Rpl_info_handler *from);
00364   bool write_info(Rpl_info_handler *to);
00365 
00366   bool auto_position;
00367 
00368   Master_info(
00369 #ifdef HAVE_PSI_INTERFACE
00370               PSI_mutex_key *param_key_info_run_lock,
00371               PSI_mutex_key *param_key_info_data_lock,
00372               PSI_mutex_key *param_key_info_sleep_lock,
00373               PSI_mutex_key *param_key_info_data_cond,
00374               PSI_mutex_key *param_key_info_start_cond,
00375               PSI_mutex_key *param_key_info_stop_cond,
00376               PSI_mutex_key *param_key_info_sleep_cond,
00377 #endif
00378               uint param_id
00379              );
00380 
00381   Master_info(const Master_info& info);
00382   Master_info& operator=(const Master_info& info);
00383 };
00384 int change_master_server_id_cmp(ulong *id1, ulong *id2);
00385 
00386 #endif /* HAVE_REPLICATION */
00387 #endif /* RPL_MI_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines