MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_info_handler.h
1 /* Copyright (c) 2010, 2011, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef RPL_INFO_HANDLER_H
17 #define RPL_INFO_HANDLER_H
18 
19 #include <my_global.h>
20 #include <dynamic_ids.h>
21 #include "rpl_info_values.h"
22 
23 enum enum_info_repository
24 {
25  INFO_REPOSITORY_FILE= 0,
26  INFO_REPOSITORY_TABLE,
27  INFO_REPOSITORY_DUMMY,
28  /*
29  Add new types of repository before this
30  entry.
31  */
32  INVALID_INFO_REPOSITORY
33 };
34 
35 /*
36  Defines status on the repository.
37 */
38 enum enum_return_check { REPOSITORY_DOES_NOT_EXIST= 1, REPOSITORY_EXISTS, ERROR_CHECKING_REPOSITORY };
39 
40 class Rpl_info_handler
41 {
42  friend class Rpl_info_factory;
43 
44 public:
54  int init_info()
55  {
56  return do_init_info();
57  }
58 
69  enum_return_check check_info()
70  {
71  return do_check_info();
72  }
73 
90  int flush_info(const bool force)
91  {
92  return do_flush_info(force);
93  }
94 
103  int remove_info()
104  {
105  return do_remove_info();
106  }
107 
115  int clean_info()
116  {
117  return do_clean_info();
118  }
119 
126  void end_info()
127  {
128  do_end_info();
129  }
130 
138  int prepare_info_for_read()
139  {
140  return (do_prepare_info_for_read());
141  }
142 
150  int prepare_info_for_write()
151  {
152  return (do_prepare_info_for_write());
153  }
154 
160  uint get_rpl_info_type()
161  {
162  return (do_get_rpl_info_type());
163  }
167  const char* get_rpl_info_type_str();
168 
180  template <class TypeHandler>
181  bool set_info(TypeHandler const value)
182  {
183  if (cursor >= ninfo || prv_error)
184  return TRUE;
185 
186  if (!(prv_error= do_set_info(cursor, value)))
187  cursor++;
188 
189  return(prv_error);
190  }
191 
192  template <class TypeHandler>
193  bool set_info(TypeHandler const value, const size_t size)
194  {
195  if (cursor >= ninfo || prv_error)
196  return TRUE;
197 
198  if (!(prv_error= do_set_info(cursor, value, size)))
199  cursor++;
200 
201  return(prv_error);
202  }
203 
217  template <class TypeHandlerPointer, class TypeHandler>
218  bool get_info(TypeHandlerPointer value,
219  TypeHandler const default_value)
220  {
221  if (cursor >= ninfo || prv_error)
222  return TRUE;
223 
224  if (!(prv_error= do_get_info(cursor, value, default_value)))
225  cursor++;
226 
227  return(prv_error);
228  }
229 
245  template <class TypeHandler>
246  bool get_info(TypeHandler value, const size_t size,
247  TypeHandler const default_value)
248  {
249  if (cursor >= ninfo || prv_error)
250  return TRUE;
251 
252  if (!(prv_error= do_get_info(cursor, value, size, default_value)))
253  cursor++;
254 
255  return(prv_error);
256  }
257 
271  bool get_info(Dynamic_ids *value,
272  const Dynamic_ids *default_value)
273  {
274  if (cursor >= ninfo || prv_error)
275  return TRUE;
276 
277  if (!(prv_error= do_get_info(cursor, value, default_value)))
278  cursor++;
279 
280  return(prv_error);
281  }
282 
288  int get_number_info() { return ninfo; }
289 
297  void set_sync_period(uint period);
298 
306  char *get_description_info()
307  {
308  return (do_get_description_info());
309  }
310 
319  bool is_transactional() { return do_is_transactional(); }
320 
334  bool update_is_transactional() { return do_update_is_transactional(); }
335 
336  /*
337  Pre-store information before writing it to the repository and if
338  necessary after reading it from the repository. The decision is
339  delegated to the sub-classes.
340  */
341  Rpl_info_values *field_values;
342 
343  virtual ~Rpl_info_handler();
344 
345 protected:
346  /* Number of fields to be stored in the repository. */
347  int ninfo;
348 
349  /* From/To where we should start reading/writing. */
350  int cursor;
351 
352  /* Registers if there was failure while accessing a field/information. */
353  bool prv_error;
354 
355  /*
356  Keeps track of the number of events before fsyncing. The option
357  --sync-master-info and --sync-relay-log-info determine how many
358  events should be processed before fsyncing.
359  */
360  uint sync_counter;
361 
362  /*
363  The number of events after which we should fsync.
364  */
365  uint sync_period;
366 
367  Rpl_info_handler(const int nparam);
368 
369 private:
370  virtual int do_init_info()= 0;
371  virtual int do_init_info(uint instance)= 0;
372  virtual enum_return_check do_check_info()= 0;
373  virtual enum_return_check do_check_info(uint instance)= 0;
374  virtual int do_flush_info(const bool force)= 0;
375  virtual int do_remove_info()= 0;
376  virtual int do_clean_info()= 0;
377  virtual void do_end_info()= 0;
378  virtual int do_prepare_info_for_read()= 0;
379  virtual int do_prepare_info_for_write()= 0;
380 
381  virtual bool do_set_info(const int pos, const char *value)= 0;
382  virtual bool do_set_info(const int pos, const uchar *value,
383  const size_t size)= 0;
384  virtual bool do_set_info(const int pos, const ulong value)= 0;
385  virtual bool do_set_info(const int pos, const int value)= 0;
386  virtual bool do_set_info(const int pos, const float value)= 0;
387  virtual bool do_set_info(const int pos, const Dynamic_ids *value)= 0;
388  virtual bool do_get_info(const int pos, char *value,
389  const size_t size,
390  const char *default_value)= 0;
391  virtual bool do_get_info(const int pos, uchar *value,
392  const size_t size,
393  const uchar *default_value)= 0;
394  virtual bool do_get_info(const int pos, ulong *value,
395  const ulong default_value)= 0;
396  virtual bool do_get_info(const int pos, int *value,
397  const int default_value)= 0;
398  virtual bool do_get_info(const int pos, float *value,
399  const float default_value)= 0;
400  virtual bool do_get_info(const int pos, Dynamic_ids *value,
401  const Dynamic_ids *default_value)= 0;
402  virtual char* do_get_description_info()= 0;
403  virtual bool do_is_transactional()= 0;
404  virtual bool do_update_is_transactional()= 0;
405  virtual uint do_get_rpl_info_type()= 0;
406 
407  Rpl_info_handler(const Rpl_info_handler& handler);
408 
409  Rpl_info_handler& operator=(const Rpl_info_handler& handler);
410 };
411 #ifndef DBUG_OFF
412  extern ulong w_rr;
413  extern uint mts_debug_concurrent_access;
414 #endif
415 #endif /* RPL_INFO_HANDLER_H */