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