MySQL  8.0.17
Source Code Documentation
rpl_info_handler.h
Go to the documentation of this file.
1 /* Copyright (c) 2010, 2019, 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_HANDLER_H
24 #define RPL_INFO_HANDLER_H
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 #include <type_traits>
29 
30 #include "my_inttypes.h"
31 
32 class Rpl_info_values;
33 class Server_ids;
34 
39  /*
40  Add new types of repository before this
41  entry.
42  */
44 };
45 
46 /*
47  Defines status on the repository.
48 */
53 };
54 
56  friend class Rpl_info_factory;
57 
58  public:
59  /**
60  After creating an object and assembling components, this method is
61  used to initialize internal structures. Everything that does not
62  depend on other components (e.g. mutexes) should be placed in the
63  object's constructor though.
64 
65  @retval false success,
66  @retval true otherwise error.
67  */
68  int init_info() { return do_init_info(); }
69 
70  /**
71  Checks the repository's status.
72 
73  @retval REPOSITORY_EXISTS reposistory is ready to
74  be used.
75  @retval REPOSITORY_DOES_NOT_EXIST repository needs to be
76  configured.
77  @retval ERROR_CHECKING_REPOSITORY error while checking the
78  reposistory.
79  */
81 
82  /**
83  Flushes and syncs in-memory information into a stable storage (i.e.
84  repository). Usually, syncing after flushing depends on other options
85  such as @c relay-log-info-sync, @c master-info-sync. These options
86  dictate after how many events or transactions the information
87  should be synced. We can ignore them and always sync by setting the
88  parameter @c force, which is by default @c false, to @c true.
89 
90  So if the number of events is below a threshold, the parameter
91  @c force is false and we are using a file system as a storage
92  system, it may happen that the changes will only end up in the
93  operating system's cache and a crash may lead to inconsistencies.
94 
95  @retval false No error
96  @retval true Failure
97  */
98  int flush_info(const bool force) { return do_flush_info(force); }
99 
100  /**
101  Deletes any information in it and in some cases the repository.
102  The decision to remove the repository is delegated to the
103  developer.
104 
105  @retval false No error
106  @retval true Failure
107  */
108  int remove_info() { return do_remove_info(); }
109 
110  /**
111  Deletes any information in the repository. In contrast to the
112  @c remove_info() method, the repository is not removed.
113 
114  @retval false No error
115  @retval true Failure
116  */
117  int clean_info() { return do_clean_info(); }
118 
119  /**
120  Closes access to the repository.
121 
122  @retval false No error
123  @retval true Failure
124  */
125  void end_info() { do_end_info(); }
126 
127  /**
128  Enables the storage system to receive reads, i.e.
129  getters.
130 
131  @retval false No error
132  @retval true Failure
133  */
135 
136  /**
137  Enables the storage system to receive writes, i.e.
138  setters.
139 
140  @retval false No error
141  @retval true Failure
142  */
144 
145  /**
146  Gets the type of the repository that is used.
147 
148  @return Type of repository.
149  */
151  /**
152  Returns a string corresponding to the type.
153  */
154  const char *get_rpl_info_type_str();
155 
156  /**
157  Sets the value of a field to @c value.
158  Any call must be done in the right order which
159  is defined by the caller that wants to persist
160  the information.
161 
162  @param[in] value Value to be set.
163 
164  @retval false No error
165  @retval true Failure
166  */
167  template <class TypeHandler>
168  bool set_info(TypeHandler const value) {
169  if (cursor >= ninfo || prv_error) return true;
170 
171  if (!(prv_error = do_set_info(cursor, value))) cursor++;
172 
173  return (prv_error);
174  }
175 
176  template <class TypeHandler>
177  bool set_info(TypeHandler const value, const size_t size) {
178  if (cursor >= ninfo || prv_error) return true;
179 
180  if (!(prv_error = do_set_info(cursor, value, size))) cursor++;
181 
182  return (prv_error);
183  }
184 
185  /**
186  set the value of a field pointed at @c pk_cursor to
187  @ value.
188 
189  @param[in] pk_cursor cursor for the filed value.
190  @param[in] value fieled[pk_cursor] would be set
191  this value.
192 
193  @retval false ok
194  @retval true error.
195  */
196 
197  template <class TypeHandler>
198  bool set_info(int pk_cursor, TypeHandler const value) {
199  if (pk_cursor >= ninfo) return true;
200 
201  return (do_set_info(pk_cursor, value));
202  }
203 
204  /**
205  Returns the value of a field.
206  Any call must be done in the right order which
207  is defined by the caller that wants to return
208  the information.
209 
210  @param[in] value Value to be set.
211  @param[in] default_value Returns a default value
212  if the field is empty.
213 
214  @retval false No error
215  @retval true Failure
216  */
217  template <class TypeHandlerPointer, class TypeHandler>
218  bool get_info(TypeHandlerPointer value, TypeHandler const default_value) {
219  if (cursor >= ninfo || prv_error) return true;
220 
221  if (!(prv_error = do_get_info(cursor, value, default_value))) cursor++;
222 
223  return (prv_error);
224  }
225 
226  /**
227  Returns the value of a string field.
228  Any call must be done in the right order which
229  is defined by the caller that wants to return
230  the information.
231 
232  @param[in] value Value to be returned.
233  @param[in] size Max size of the string to be
234  returned.
235  @param[in] default_value Returns a default value
236  if the field is empty.
237 
238  TypeHandler is either char* or uchar*, while
239  default_value is const char* or const uchar*.
240  Some type trait magic is required to make
241  char* / uchar* into const char* / uchar*.
242 
243  @retval false No error
244  @retval true Failure
245  */
246  template <class TypeHandler>
247  bool get_info(
248  TypeHandler value, const size_t size,
249  std::add_const_t<std::remove_pointer_t<TypeHandler>> *default_value) {
250  if (cursor >= ninfo || prv_error) return true;
251 
252  if (!(prv_error = do_get_info(cursor, value, size, default_value)))
253  cursor++;
254 
255  return (prv_error);
256  }
257 
258  /**
259  Returns the value of a Server_id field.
260  Any call must be done in the right order which
261  is defined by the caller that wants to return
262  the information.
263 
264  @param[out] value Value to be return.
265  @param[in] default_value Returns a default value
266  if the field is empty.
267 
268  @retval false No error
269  @retval true Failure
270  */
271  bool get_info(Server_ids *value, const Server_ids *default_value) {
272  if (cursor >= ninfo || prv_error) return true;
273 
274  if (!(prv_error = do_get_info(cursor, value, default_value))) cursor++;
275 
276  return (prv_error);
277  }
278 
279  /**
280  Returns the number of fields handled by this handler.
281 
282  @return Number of fields handled by the handler.
283  */
284  int get_number_info() { return ninfo; }
285 
286  /**
287  Configures the number of events after which the info (e.g.
288  master info, relay log info) must be synced when flush() is
289  called.
290 
291  @param[in] period Number of events.
292  */
293  void set_sync_period(uint period);
294 
295  /**
296  Returns a string describing the repository. For instance, if the
297  repository is a file, the returned string is path where data is
298  stored.
299 
300  @return a pointer to a string.
301  */
303 
304  /**
305  Any transactional repository may have its updates rolled back in case
306  of a failure. If this is possible, the repository is classified as
307  transactional.
308 
309  @retval true If transactional.
310  @retval false Otherwise.
311  */
313 
314  /**
315  Updates the value returned by the member function is_transactional()
316  because it may be expensive to compute it whenever is_transactional()
317  is called.
318 
319  In the current implementation, the type of the repository can only be
320  changed when replication, i.e. slave, is stopped. For that reason,
321  this member function, i.e. update_is__transactional(), must be called
322  when slave is starting.
323 
324  @retval false No error
325  @retval true Failure
326  */
328 
329  /*
330  Pre-store information before writing it to the repository and if
331  necessary after reading it from the repository. The decision is
332  delegated to the sub-classes.
333  */
335 
336  virtual ~Rpl_info_handler();
337 
338  protected:
339  /* Number of fields to be stored in the repository. */
340  int ninfo;
341 
342  /* From/To where we should start reading/writing. */
343  int cursor;
344 
345  /* Registers if there was failure while accessing a field/information. */
346  bool prv_error;
347 
348  /*
349  Keeps track of the number of events before fsyncing. The option
350  --sync-master-info and --sync-relay-log-info determine how many
351  events should be processed before fsyncing.
352  */
354 
355  /*
356  The number of events after which we should fsync.
357  */
359 
360  Rpl_info_handler(const int nparam);
361 
362  private:
363  virtual int do_init_info() = 0;
364  virtual int do_init_info(uint instance) = 0;
365  virtual enum_return_check do_check_info() = 0;
366  virtual enum_return_check do_check_info(uint instance) = 0;
367  virtual int do_flush_info(const bool force) = 0;
368  virtual int do_remove_info() = 0;
369  virtual int do_clean_info() = 0;
370  virtual void do_end_info() = 0;
371  virtual int do_prepare_info_for_read() = 0;
372  virtual int do_prepare_info_for_write() = 0;
373 
374  virtual bool do_set_info(const int pos, const char *value) = 0;
375  virtual bool do_set_info(const int pos, const uchar *value,
376  const size_t size) = 0;
377  virtual bool do_set_info(const int pos, const ulong value) = 0;
378  virtual bool do_set_info(const int pos, const int value) = 0;
379  virtual bool do_set_info(const int pos, const float value) = 0;
380  virtual bool do_set_info(const int pos, const Server_ids *value) = 0;
381  virtual bool do_get_info(const int pos, char *value, const size_t size,
382  const char *default_value) = 0;
383  virtual bool do_get_info(const int pos, uchar *value, const size_t size,
384  const uchar *default_value) = 0;
385  virtual bool do_get_info(const int pos, ulong *value,
386  const ulong default_value) = 0;
387  virtual bool do_get_info(const int pos, int *value,
388  const int default_value) = 0;
389  virtual bool do_get_info(const int pos, float *value,
390  const float default_value) = 0;
391  virtual bool do_get_info(const int pos, Server_ids *value,
392  const Server_ids *default_value) = 0;
393  virtual char *do_get_description_info() = 0;
394  virtual bool do_is_transactional() = 0;
395  virtual bool do_update_is_transactional() = 0;
396  virtual uint do_get_rpl_info_type() = 0;
397 
399 
401 };
402 #ifndef DBUG_OFF
403 extern ulong w_rr;
405 #endif
406 #endif /* RPL_INFO_HANDLER_H */
int prepare_info_for_read()
Enables the storage system to receive reads, i.e.
Definition: rpl_info_handler.h:134
int get_number_info()
Returns the number of fields handled by this handler.
Definition: rpl_info_handler.h:284
bool set_info(int pk_cursor, TypeHandler const value)
set the value of a field pointed at pk_cursor to @ value.
Definition: rpl_info_handler.h:198
unsigned char uchar
Definition: my_inttypes.h:51
t pos
Definition: dbug_analyze.cc:148
Definition: rpl_info_handler.h:51
int init_info()
After creating an object and assembling components, this method is used to initialize internal struct...
Definition: rpl_info_handler.h:68
bool set_info(TypeHandler const value, const size_t size)
Definition: rpl_info_handler.h:177
Definition: rpl_info_handler.h:55
Some integer typedefs for easier portability.
Definition: rpl_info_handler.h:38
virtual int do_prepare_info_for_write()=0
uint sync_counter
Definition: rpl_info_handler.h:353
bool is_transactional()
Any transactional repository may have its updates rolled back in case of a failure.
Definition: rpl_info_handler.h:312
virtual uint do_get_rpl_info_type()=0
Definition: dynamic_ids.h:32
void end_info()
Closes access to the repository.
Definition: rpl_info_handler.h:125
Definition: rpl_info_factory.h:42
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3987
virtual char * do_get_description_info()=0
ulong w_rr
Definition: rpl_rli_pdb.cc:76
virtual bool do_get_info(const int pos, char *value, const size_t size, const char *default_value)=0
bool update_is_transactional()
Updates the value returned by the member function is_transactional() because it may be expensive to c...
Definition: rpl_info_handler.h:327
Definition: rpl_info_handler.h:36
Definition: rpl_info_handler.h:50
virtual int do_prepare_info_for_read()=0
Rpl_info_handler(const int nparam)
Definition: rpl_info_handler.cc:28
Rpl_info_values * field_values
Definition: rpl_info_handler.h:334
bool get_info(TypeHandler value, const size_t size, std::add_const_t< std::remove_pointer_t< TypeHandler >> *default_value)
Returns the value of a string field.
Definition: rpl_info_handler.h:247
int ninfo
Definition: rpl_info_handler.h:340
bool prv_error
Definition: rpl_info_handler.h:346
Definition: rpl_info_handler.h:37
virtual int do_remove_info()=0
bool set_info(TypeHandler const value)
Sets the value of a field to value.
Definition: rpl_info_handler.h:168
Definition: rpl_info_values.h:28
unsigned int uint
Definition: uca-dump.cc:29
Definition: rpl_info_handler.h:52
void set_sync_period(uint period)
Configures the number of events after which the info (e.g.
Definition: rpl_info_handler.cc:48
virtual bool do_update_is_transactional()=0
enum_return_check check_info()
Checks the repository&#39;s status.
Definition: rpl_info_handler.h:80
uint mts_debug_concurrent_access
Definition: rpl_rli_pdb.cc:77
virtual bool do_is_transactional()=0
virtual enum_return_check do_check_info()=0
int remove_info()
Deletes any information in it and in some cases the repository.
Definition: rpl_info_handler.h:108
bool get_info(TypeHandlerPointer value, TypeHandler const default_value)
Returns the value of a field.
Definition: rpl_info_handler.h:218
uint get_rpl_info_type()
Gets the type of the repository that is used.
Definition: rpl_info_handler.h:150
virtual int do_clean_info()=0
virtual ~Rpl_info_handler()
Definition: rpl_info_handler.cc:46
char * get_description_info()
Returns a string describing the repository.
Definition: rpl_info_handler.h:302
enum_return_check
Definition: rpl_info_handler.h:49
virtual bool do_set_info(const int pos, const char *value)=0
int flush_info(const bool force)
Flushes and syncs in-memory information into a stable storage (i.e.
Definition: rpl_info_handler.h:98
enum_info_repository
Definition: rpl_info_handler.h:35
int clean_info()
Deletes any information in the repository.
Definition: rpl_info_handler.h:117
const char * get_rpl_info_type_str()
Returns a string corresponding to the type.
Definition: rpl_info_handler.cc:50
const string value("\alue\)
virtual void do_end_info()=0
virtual int do_flush_info(const bool force)=0
uint sync_period
Definition: rpl_info_handler.h:358
int prepare_info_for_write()
Enables the storage system to receive writes, i.e.
Definition: rpl_info_handler.h:143
unsigned long ulong
Definition: my_inttypes.h:48
Rpl_info_handler & operator=(const Rpl_info_handler &handler)
bool get_info(Server_ids *value, const Server_ids *default_value)
Returns the value of a Server_id field.
Definition: rpl_info_handler.h:271
virtual int do_init_info()=0
int cursor
Definition: rpl_info_handler.h:343
Definition: rpl_info_handler.h:43