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