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_TABLE_H
24 #define RPL_INFO_TABLE_H
25 
26 #include "my_global.h"
27 #include "mysql/mysql_lex_string.h"  // LEX_STRING
28 #include "rpl_info_handler.h"        // Rpl_info_handler
29 #include "table.h"                   // TABLE
30 
31 class Rpl_info_table_access;
32 typedef struct st_mysql_lex_string LEX_STRING;
33 
34 
35 /**
36   Methods to find information in a table:
37 
38   FIND_SCAN does a index scan and stops at n-th occurrence.
39 
40   FIND_KEY retrieves the index entry previous populated at
41   values if there is any.
42 */
43 enum enum_find_method { FIND_SCAN, FIND_KEY };
44 
45 class Rpl_info_table : public Rpl_info_handler
46 {
47   friend class Rpl_info_factory;
48 
49 public:
50   virtual ~Rpl_info_table();
51 
52 private:
53   /**
54     This property identifies the name of the schema where a
55     replication table is created.
56   */
57   LEX_STRING str_schema;
58 
59   /**
60     This property identifies the name of a replication
61     table.
62   */
63   LEX_STRING str_table;
64 
65   /**
66     This property represents a description of the repository.
67     Speciffically, "schema"."table".
68   */
69   char *description;
70 
71   /**
72     This property represents the amount of fields in the repository
73     primary key.
74   */
75   uint m_n_pk_fields;
76 
77   /**
78     This property identifies the indexes of the primary keys fields
79     in the table.
80   */
81   const uint *m_pk_field_indexes;
82 
83   /**
84     This is a pointer to a class that facilitates manipulation
85     of replication tables.
86   */
87   Rpl_info_table_access *access;
88 
89   /**
90     Identifies if a table is transactional or non-transactional.
91     This is used to provide a crash-safe behaviour.
92   */
93   bool is_transactional;
94 
95   int do_init_info();
96   int do_init_info(uint instance);
97   int do_init_info(enum_find_method method, uint instance);
98   enum_return_check do_check_info();
99   enum_return_check do_check_info(uint instance);
100   void do_end_info();
101   int do_flush_info(const bool force);
102   int do_remove_info();
103   int do_clean_info();
104   /**
105     Returns the number of entries in the table identified by:
106     param_schema.param_table.
107 
108     @param[in]  nparam           Number of fields in the table.
109     @param[in]  param_schema     Table's schema.
110     @param[in]  param_table      Table's name.
111     @param[out] counter          Number of entries found.
112 
113     @retval false Success
114     @retval true  Error
115   */
116   static bool do_count_info(uint nparam, const char* param_schema,
117                             const char* param_table,  uint* counter);
118   static int do_reset_info(uint nparam, const char* param_schema,
119                            const char *param_table,
120                            const char *channel_name, uint channel_idx);
121   int do_prepare_info_for_read();
122   int do_prepare_info_for_write();
123 
124   bool do_set_info(const int pos, const char *value);
125   bool do_set_info(const int pos, const uchar *value,
126                    const size_t size);
127   bool do_set_info(const int pos, const int value);
128   bool do_set_info(const int pos, const ulong value);
129   bool do_set_info(const int pos, const float value);
130   bool do_set_info(const int pos, const Server_ids *value);
131   bool do_get_info(const int pos, char *value, const size_t size,
132                    const char *default_value);
133   bool do_get_info(const int pos, uchar *value, const size_t size,
134                    const uchar *default_value);
135   bool do_get_info(const int pos, int *value,
136                    const int default_value);
137   bool do_get_info(const int pos, ulong *value,
138                    const ulong default_value);
139   bool do_get_info(const int pos, float *value,
140                    const float default_value);
141   bool do_get_info(const int pos, Server_ids *value,
142                    const Server_ids *default_value);
143   char* do_get_description_info();
144 
145   bool do_is_transactional();
146   bool do_update_is_transactional();
147   uint do_get_rpl_info_type();
148 
149   /**
150     Verify if the table primary key fields are at the expected (column)
151     position.
152 
153     @param table The table handle where the verification will be done.
154 
155     @return false if the table primary key fields are fine.
156     @return true  if problems were found with table primary key fields.
157   */
158   bool verify_table_primary_key_fields(TABLE* table);
159 
160   Rpl_info_table(uint nparam,
161                  const char* param_schema,
162                  const char *param_table,
163                  const uint param_n_pk_fields= 0,
164                  const uint *param_pk_field_indexes= NULL);
165 
166   Rpl_info_table(const Rpl_info_table& info);
167   Rpl_info_table& operator=(const Rpl_info_table& info);
168 };
169 #endif /* RPL_INFO_TABLE_H */
170