1 /* Copyright (c) 2010, 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 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef RPL_INFO_FACTORY_H 24 #define RPL_INFO_FACTORY_H 25 26 #ifdef HAVE_REPLICATION 27 28 #include "my_global.h" 29 #include "rpl_channel_service_interface.h" // enum_channel_type 30 #include "rpl_info_handler.h" // enum_return_check 31 32 #include <vector> 33 #include <string> 34 35 class Master_info; 36 class Multisource_info; 37 class Relay_log_info; 38 class Rpl_info; 39 class Slave_worker; 40 41 42 extern ulong opt_mi_repository_id; 43 extern ulong opt_rli_repository_id; 44 45 class Rpl_info_factory 46 { 47 public: 48 static bool create_slave_info_objects(uint mi_option, uint rli_option, int 49 thread_mask, Multisource_info *pchannel_map); 50 51 static Master_info* create_mi_and_rli_objects(uint mi_option, 52 uint rli_option, 53 const char* channel, 54 bool convert_repo, 55 Multisource_info* channel_map); 56 57 static Master_info *create_mi(uint rli_option, const char* channel, 58 bool conver_repo); 59 static bool change_mi_repository(Master_info *mi, const uint mi_option, 60 const char **msg); 61 static Relay_log_info *create_rli(uint rli_option, bool is_slave_recovery, 62 const char* channel, bool convert_repo); 63 static bool change_rli_repository(Relay_log_info *rli, const uint rli_option, 64 const char **msg); 65 static Slave_worker *create_worker(uint rli_option, uint worker_id, 66 Relay_log_info *rli, 67 bool is_gaps_collecting_phase); 68 static bool reset_workers(Relay_log_info *rli); 69 private: 70 typedef struct 71 { 72 uint n_fields; 73 char name[FN_REFLEN]; 74 char pattern[FN_REFLEN]; 75 bool name_indexed; // whether file name should include instance number 76 } struct_file_data; 77 78 typedef struct 79 { 80 uint n_fields; 81 const char* schema; 82 const char* name; 83 uint n_pk_fields; 84 const uint* pk_field_indexes; 85 } struct_table_data; 86 87 static struct_table_data rli_table_data; 88 static struct_file_data rli_file_data; 89 static struct_table_data mi_table_data; 90 static struct_file_data mi_file_data; 91 static struct_table_data worker_table_data; 92 static struct_file_data worker_file_data; 93 94 static void init_repository_metadata(); 95 static bool decide_repository(Rpl_info *info, 96 uint option, 97 Rpl_info_handler **handler_src, 98 Rpl_info_handler **handler_dest, 99 const char **msg); 100 static bool init_repositories(const struct_table_data table_data, 101 const struct_file_data file_data, 102 uint option, 103 uint instance, 104 Rpl_info_handler **handler_src, 105 Rpl_info_handler **handler_dest, 106 const char **msg); 107 108 static enum_return_check check_src_repository(Rpl_info *info, 109 uint option, 110 Rpl_info_handler **handler_src); 111 static bool check_error_repository(Rpl_info *info, 112 Rpl_info_handler *handler_src, 113 Rpl_info_handler *handler_dst, 114 enum_return_check err_src, 115 enum_return_check err_dst, 116 const char **msg); 117 static bool init_repositories(Rpl_info *info, 118 Rpl_info_handler **handler_src, 119 Rpl_info_handler **handler_dst, 120 const char **msg); 121 static bool scan_repositories(uint* found_instances, 122 uint* found_rep_option, 123 const struct_table_data table_data, 124 const struct_file_data file_data, const char **msg); 125 static bool load_channel_names_from_repository(std::vector<std::string> & channel_list, uint mi_instances, 126 uint mi_repository, const char *default_channel, 127 bool *default_channel_created_previously); 128 129 static bool load_channel_names_from_table(std::vector<std::string> &channel_list, 130 const char *default_channel, 131 bool *default_channel_created_previously); 132 }; 133 134 #endif 135 136 #endif 137