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