My Project
|
00001 /* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; version 2 of the License. 00006 00007 This program is distributed in the hope that it will be useful, 00008 but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 GNU General Public License for more details. 00011 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software 00014 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00015 00016 #ifndef RPL_INFO_HANDLER_H 00017 #define RPL_INFO_HANDLER_H 00018 00019 #include <my_global.h> 00020 #include <dynamic_ids.h> 00021 #include "rpl_info_values.h" 00022 00023 enum enum_info_repository 00024 { 00025 INFO_REPOSITORY_FILE= 0, 00026 INFO_REPOSITORY_TABLE, 00027 INFO_REPOSITORY_DUMMY, 00028 /* 00029 Add new types of repository before this 00030 entry. 00031 */ 00032 INVALID_INFO_REPOSITORY 00033 }; 00034 00035 /* 00036 Defines status on the repository. 00037 */ 00038 enum enum_return_check { REPOSITORY_DOES_NOT_EXIST= 1, REPOSITORY_EXISTS, ERROR_CHECKING_REPOSITORY }; 00039 00040 class Rpl_info_handler 00041 { 00042 friend class Rpl_info_factory; 00043 00044 public: 00054 int init_info() 00055 { 00056 return do_init_info(); 00057 } 00058 00069 enum_return_check check_info() 00070 { 00071 return do_check_info(); 00072 } 00073 00090 int flush_info(const bool force) 00091 { 00092 return do_flush_info(force); 00093 } 00094 00103 int remove_info() 00104 { 00105 return do_remove_info(); 00106 } 00107 00115 int clean_info() 00116 { 00117 return do_clean_info(); 00118 } 00119 00126 void end_info() 00127 { 00128 do_end_info(); 00129 } 00130 00138 int prepare_info_for_read() 00139 { 00140 return (do_prepare_info_for_read()); 00141 } 00142 00150 int prepare_info_for_write() 00151 { 00152 return (do_prepare_info_for_write()); 00153 } 00154 00160 uint get_rpl_info_type() 00161 { 00162 return (do_get_rpl_info_type()); 00163 } 00167 const char* get_rpl_info_type_str(); 00168 00180 template <class TypeHandler> 00181 bool set_info(TypeHandler const value) 00182 { 00183 if (cursor >= ninfo || prv_error) 00184 return TRUE; 00185 00186 if (!(prv_error= do_set_info(cursor, value))) 00187 cursor++; 00188 00189 return(prv_error); 00190 } 00191 00192 template <class TypeHandler> 00193 bool set_info(TypeHandler const value, const size_t size) 00194 { 00195 if (cursor >= ninfo || prv_error) 00196 return TRUE; 00197 00198 if (!(prv_error= do_set_info(cursor, value, size))) 00199 cursor++; 00200 00201 return(prv_error); 00202 } 00203 00217 template <class TypeHandlerPointer, class TypeHandler> 00218 bool get_info(TypeHandlerPointer value, 00219 TypeHandler const default_value) 00220 { 00221 if (cursor >= ninfo || prv_error) 00222 return TRUE; 00223 00224 if (!(prv_error= do_get_info(cursor, value, default_value))) 00225 cursor++; 00226 00227 return(prv_error); 00228 } 00229 00245 template <class TypeHandler> 00246 bool get_info(TypeHandler value, const size_t size, 00247 TypeHandler const default_value) 00248 { 00249 if (cursor >= ninfo || prv_error) 00250 return TRUE; 00251 00252 if (!(prv_error= do_get_info(cursor, value, size, default_value))) 00253 cursor++; 00254 00255 return(prv_error); 00256 } 00257 00271 bool get_info(Dynamic_ids *value, 00272 const Dynamic_ids *default_value) 00273 { 00274 if (cursor >= ninfo || prv_error) 00275 return TRUE; 00276 00277 if (!(prv_error= do_get_info(cursor, value, default_value))) 00278 cursor++; 00279 00280 return(prv_error); 00281 } 00282 00288 int get_number_info() { return ninfo; } 00289 00297 void set_sync_period(uint period); 00298 00306 char *get_description_info() 00307 { 00308 return (do_get_description_info()); 00309 } 00310 00319 bool is_transactional() { return do_is_transactional(); } 00320 00334 bool update_is_transactional() { return do_update_is_transactional(); } 00335 00336 /* 00337 Pre-store information before writing it to the repository and if 00338 necessary after reading it from the repository. The decision is 00339 delegated to the sub-classes. 00340 */ 00341 Rpl_info_values *field_values; 00342 00343 virtual ~Rpl_info_handler(); 00344 00345 protected: 00346 /* Number of fields to be stored in the repository. */ 00347 int ninfo; 00348 00349 /* From/To where we should start reading/writing. */ 00350 int cursor; 00351 00352 /* Registers if there was failure while accessing a field/information. */ 00353 bool prv_error; 00354 00355 /* 00356 Keeps track of the number of events before fsyncing. The option 00357 --sync-master-info and --sync-relay-log-info determine how many 00358 events should be processed before fsyncing. 00359 */ 00360 uint sync_counter; 00361 00362 /* 00363 The number of events after which we should fsync. 00364 */ 00365 uint sync_period; 00366 00367 Rpl_info_handler(const int nparam); 00368 00369 private: 00370 virtual int do_init_info()= 0; 00371 virtual int do_init_info(uint instance)= 0; 00372 virtual enum_return_check do_check_info()= 0; 00373 virtual enum_return_check do_check_info(uint instance)= 0; 00374 virtual int do_flush_info(const bool force)= 0; 00375 virtual int do_remove_info()= 0; 00376 virtual int do_clean_info()= 0; 00377 virtual void do_end_info()= 0; 00378 virtual int do_prepare_info_for_read()= 0; 00379 virtual int do_prepare_info_for_write()= 0; 00380 00381 virtual bool do_set_info(const int pos, const char *value)= 0; 00382 virtual bool do_set_info(const int pos, const uchar *value, 00383 const size_t size)= 0; 00384 virtual bool do_set_info(const int pos, const ulong value)= 0; 00385 virtual bool do_set_info(const int pos, const int value)= 0; 00386 virtual bool do_set_info(const int pos, const float value)= 0; 00387 virtual bool do_set_info(const int pos, const Dynamic_ids *value)= 0; 00388 virtual bool do_get_info(const int pos, char *value, 00389 const size_t size, 00390 const char *default_value)= 0; 00391 virtual bool do_get_info(const int pos, uchar *value, 00392 const size_t size, 00393 const uchar *default_value)= 0; 00394 virtual bool do_get_info(const int pos, ulong *value, 00395 const ulong default_value)= 0; 00396 virtual bool do_get_info(const int pos, int *value, 00397 const int default_value)= 0; 00398 virtual bool do_get_info(const int pos, float *value, 00399 const float default_value)= 0; 00400 virtual bool do_get_info(const int pos, Dynamic_ids *value, 00401 const Dynamic_ids *default_value)= 0; 00402 virtual char* do_get_description_info()= 0; 00403 virtual bool do_is_transactional()= 0; 00404 virtual bool do_update_is_transactional()= 0; 00405 virtual uint do_get_rpl_info_type()= 0; 00406 00407 Rpl_info_handler(const Rpl_info_handler& handler); 00408 00409 Rpl_info_handler& operator=(const Rpl_info_handler& handler); 00410 }; 00411 #ifndef DBUG_OFF 00412 extern ulong w_rr; 00413 extern uint mts_debug_concurrent_access; 00414 #endif 00415 #endif /* RPL_INFO_HANDLER_H */