MySQL 8.4.0
Source Code Documentation
rpl_async_conn_failover_table_operations.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 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_ASYNC_CONN_FAILOVER_TABLE_OPERATIONS_H
25#define RPL_ASYNC_CONN_FAILOVER_TABLE_OPERATIONS_H
26
27#include <functional>
28#include <tuple>
29#include "sql/field.h"
30#include "sql/table.h"
32#include "string_with_len.h"
33
35class Json_wrapper;
36
38class SourceAndManagedList;
39}
40
41/* <channel, host, port, network_namespace, weight, managed_name> */
43 std::tuple<std::string, std::string, uint, std::string, uint, std::string>;
44
45/* <channel, managed_name, managed_type, configuration> */
47 std::tuple<std::string, std::string, std::string, Json_wrapper>;
48
49/* <channel, managed_name, managed_type, primary_weight, secondary_weight> */
51 std::tuple<std::string, std::string, std::string, uint, uint>;
52
53using RPL_FAILOVER_SOURCE_LIST = std::vector<RPL_FAILOVER_SOURCE_TUPLE>;
54
55/*
56 Class provides read, write and delete function to
57 replication_asynchronous_connection_failover and
58 replication_asynchronous_connection_failover_managed
59 tables.
60*/
62 public:
63 /**
64 Construction.
65
66 @param[in] lock_type How to lock the table
67 */
69 enum thr_lock_type lock_type = TL_WRITE)
70 : m_lock_type(lock_type) {}
71
73
74 /**
75 Insert row for a unmanaged sender on
76 replication_asynchronous_connection_failover table, and
77 send stored table data to its group replication group members.
78
79 @param[in] channel channel
80 @param[in] host sender host
81 @param[in] port sender port
82 @param[in] network_namespace sender network_namespace
83 @param[in] weight sender weight
84 @param[in] managed_name The name of the group which this server
85 belongs to.
86
87 @returns std::tuple<bool, std::string> where each element has
88 following meaning:
89
90 first element of tuple is function return value and determines:
91 false Successful
92 true Error
93
94 second element of tuple is error message.
95 */
96 std::tuple<bool, std::string> add_source(const std::string &channel,
97 const std::string &host, uint port,
98 const std::string &network_namespace,
99 uint weight,
100 const std::string &managed_name);
101
102 /**
103 Insert row for a unmanaged sender on
104 replication_asynchronous_connection_failover table.
105
106 @param[in] channel channel
107 @param[in] host sender host
108 @param[in] port sender port
109 @param[in] network_namespace sender network_namespace
110 @param[in] weight sender weight
111 @param[in] managed_name The name of the group which this server
112 belongs to.
113 @param[in] table_op Rpl_sys_table_access class object.
114
115 @returns std::tuple<bool, std::string> where each element has
116 following meaning:
117
118 first element of tuple is function return value and determines:
119 false Successful
120 true Error
121
122 second element of tuple is error message.
123 */
124 static std::tuple<bool, std::string> add_source_skip_send(
125 const std::string &channel, const std::string &host, uint port,
126 const std::string &network_namespace, uint weight,
127 const std::string &managed_name, Rpl_sys_table_access &table_op);
128
129 /**
130 Insert row on replication_asynchronous_connection_failover_managed
131 and replication_asynchronous_connection_failover tables, and
132 send stored table data to its group replication group members.
133
134 @param[in] channel channel
135 @param[in] host sender host
136 @param[in] port sender port
137 @param[in] network_namespace sender network_namespace
138 @param[in] managed_type Determines the manged group type.
139 @param[in] managed_name The name of the group which this server
140 belongs to
141 @param[in] primary_weight weight assigned to the primary
142 @param[in] secondary_weight weight assigned to the secondary
143
144 @returns std::tuple<bool, std::string> where each element has
145 following meaning:
146
147 first element of tuple is function return value and determines:
148 false Successful
149 true Error
150
151 second element of tuple is error message.
152 */
153 std::tuple<bool, std::string> add_managed(
154 const std::string &channel, const std::string &host, uint port,
155 const std::string &network_namespace, const std::string &managed_type,
156 const std::string &managed_name, uint primary_weight,
157 uint secondary_weight);
158
159 /**
160 Insert row on replication_asynchronous_connection_failover_managed
161 table.
162
163 @param[in] channel channel
164 @param[in] managed_type Determines the manged group type.
165 @param[in] managed_name The name of the group which this server
166 belongs to.
167 @param[in] wrapper contains weight assigned to the primary
168 and secondary member in Json format.
169 @param[in] table_op Rpl_sys_table_access class object.
170
171 @returns std::tuple<bool, std::string> where each element has
172 following meaning:
173
174 first element of tuple is function return value and determines:
175 false Successful
176 true Error
177
178 second element of tuple is error message.
179 */
180 static std::tuple<bool, std::string> add_managed_skip_send(
181 const std::string &channel, const std::string &managed_type,
182 const std::string &managed_name, const Json_wrapper &wrapper,
183 Rpl_sys_table_access &table_op);
184
185 /**
186 Delete row for a unmanaged sender on
187 replication_asynchronous_connection_failover table.
188
189 @param[in] channel channel
190 @param[in] host sender host
191 @param[in] port sender port
192 @param[in] network_namespace sender network_namespace
193
194 @returns std::tuple<bool, std::string> where each element has
195 following meaning:
196
197 first element of tuple is function return value and determines:
198 false Successful
199 true Error
200
201 second element of tuple is error message.
202 */
203 std::tuple<bool, std::string> delete_source(
204 const std::string &channel, const std::string &host, uint port,
205 const std::string &network_namespace);
206
207 /**
208 Delete row on replication_asynchronous_connection_failover_managed table
209 and all its sources on replication_asynchronous_connection_failover table.
210
211 @param[in] channel The asynchronous replication channel name
212 @param[in] managed_name The name of the group which this server
213 belongs to.
214
215 @returns std::tuple<bool, std::string> where each element has
216 following meaning:
217
218 first element of tuple is function return value and determines:
219 false Successful
220 true Error
221
222 second element of tuple is error message.
223 */
224 std::tuple<bool, std::string> delete_managed(const std::string &channel,
225 const std::string &managed_name);
226
227 /**
228 Delete all rows on replication_asynchronous_connection_failover_managed
229 and replication_asynchronous_connection_failover tables, and delete
230 its respective rows on replication_group_configuration_version table.
231
232 @return operation status:
233 false Successful
234 true Error
235 */
236 bool reset();
237
238 /**
239 Read all sources for a channel.
240 It uses index scan (ha_index_read_idx_map) to fetch rows for the channel
241 name.
242
243 @param[in] channel_name The channel name
244
245 @returns std::tuple<bool, List_of_Tuple> where each element has
246 following meaning:
247
248 first element of tuple is function return value and determines:
249 false Successful
250 true Error
251
252 second element of the tuple is list of return details based on
253 open table and template provided.
254 */
255 std::tuple<bool, std::vector<RPL_FAILOVER_SOURCE_TUPLE>>
256 read_source_rows_for_channel(std::string channel_name);
257
258 /**
259 Real all sources for a channel and a managed name.
260 It uses index scan (ha_index_read_idx_map) to fetch rows for the channel
261 name and manged name.
262
263 @param[in] channel_name The channel name
264 @param[in] managed_name The name of the group which this server
265 belongs to.
266
267 @returns std::tuple<bool, List_of_Tuple> where each element has
268 following meaning:
269
270 first element of tuple is function return value and determines:
271 false Successful
272 true Error
273
274 second element of the tuple is list of return details based on
275 open table and template provided.
276 */
277 std::tuple<bool, std::vector<RPL_FAILOVER_SOURCE_TUPLE>>
278 read_source_rows_for_channel_and_managed_name(std::string channel_name,
279 std::string managed_name);
280
281 /**
282 Read rows and fields from
283 replication_asynchronous_connection_failover_managed table and returns its
284 details in provided RPL_FAILOVER_MANAGED_TUPLE tuple. It uses index scan
285 (ha_index_read_idx_map) to fetch rows for the channel name.
286
287 @param[in] channel_name The channel name
288 @param[out] rows return rows read from
289 replication_asynchronous_connection_failover_managed
290
291 @return function return value which determines if read was:
292 false Successful
293 true Error
294 */
296 std::string channel_name, std::vector<RPL_FAILOVER_MANAGED_TUPLE> &rows);
297
298 /**
299 Read all sources.
300 It uses index scan (ha_index_first) to fetch all the rows.
301
302 @param[in] table_op Rpl_sys_table_access class object.
303
304 @returns std::tuple<bool, List_of_Tuple> where each element has
305 following meaning:
306
307 first element of tuple is function return value and determines:
308 false Successful
309 true Error
310
311 second element of the tuple is list of return details based on
312 open table and template provided.
313 */
314 static std::tuple<bool, std::vector<RPL_FAILOVER_SOURCE_TUPLE>>
316
317 /**
318 Read all sources.
319 It uses index scan (ha_index_first) to fetch all the rows.
320
321 @returns std::tuple<bool, List_of_Tuple> where each element has
322 following meaning:
323
324 first element of tuple is function return value and determines:
325 false Successful
326 true Error
327
328 second element of the tuple is list of return details based on
329 open table and template provided.
330 */
331 std::tuple<bool, std::vector<RPL_FAILOVER_SOURCE_TUPLE>>
333
334 /**
335 Get all sources using random scan (ha_rnd_next) to fetch all the rows.
336
337 @returns std::tuple<bool, List_of_Tuple> where each element has
338 following meaning:
339
340 first element of tuple is function return value and determines:
341 false Successful
342 true Error
343
344 second element of the tuple is list of return details based on
345 open table and template provided.
346 */
347 std::tuple<bool, std::vector<RPL_FAILOVER_SOURCE_TUPLE>>
349
350 /**
351 Read rows and fields from
352 replication_asynchronous_connection_failover_managed table and returns its
353 details in provided RPL_FAILOVER_MANAGED_JSON_TUPLE tuple. It uses random
354 scan (ha_rnd_next) to fetch all the rows.
355
356 @param[in] table_op Rpl_sys_table_access class object.
357 @param[out] rows return rows read from
358 replication_asynchronous_connection_failover_managed
359
360 @return function return value which determines if read was:
361 false Successful
362 true Error
363 */
365 Rpl_sys_table_access &table_op,
366 std::vector<RPL_FAILOVER_MANAGED_JSON_TUPLE> &rows);
367
368 /**
369 Read rows and fields from
370 replication_asynchronous_connection_failover_managed table and returns its
371 details in provided RPL_FAILOVER_MANAGED_TUPLE tuple. It uses random
372 scan (ha_rnd_next) to fetch all the rows.
373
374 @param[in] table_op Rpl_sys_table_access class object.
375 @param[out] rows return rows read from
376 replication_asynchronous_connection_failover_managed
377
378 @return function return value which determines if read was:
379 false Successful
380 true Error
381 */
383 Rpl_sys_table_access &table_op,
384 std::vector<RPL_FAILOVER_MANAGED_TUPLE> &rows);
385
386 /**
387 Read rows and fields from
388 replication_asynchronous_connection_failover_managed table and returns its
389 details in provided RPL_FAILOVER_MANAGED_TUPLE tuple. It uses random scan
390 (ha_rnd_next) to fetch all the rows.
391
392 @param[out] rows return rows read from
393 replication_asynchronous_connection_failover_managed
394
395 @return function return value which determines if read was:
396 false Successful
397 true Error
398 */
399 bool read_managed_random_rows(std::vector<RPL_FAILOVER_MANAGED_TUPLE> &rows);
400
401 /**
402 Get stored data in table.
403
404 @param[in] table_op Rpl_sys_table_access class object.
405 @param[out] rows Fetch and store read rows in the tuple.
406 */
407 template <class TUP>
408 static void get_data(Rpl_sys_table_access &table_op, TUP &rows);
409
410 /* Configuration column primary key name */
412
413 /* Configuration column secondary key name */
415
416 private:
417 enum thr_lock_type m_lock_type; // table lock type
418 const std::string m_db{"mysql"}; // the database table belongs to
419
420 const std::string m_table_failover{
421 "replication_asynchronous_connection_failover"};
423
424 const std::string m_table_managed{
425 "replication_asynchronous_connection_failover_managed"};
427
428 /**
429 A wrapper template function to save/delete data to given table.
430
431 @param[in] field_index The list of field's position to be written or match
432 while querying for delete operations.
433 @param[in] field_name The list of field names of the table.
434 @param[in] field_value The field values to be written or match while
435 querying for delete operations.
436 @param[in] func The handler class function to write/delete data.
437 @param[in] table_index The table index/key position (by default i.e. on
438 position 0, if primary key present is used).
439 @param[in] keypart_map Which part of key to use.
440 @param[in] table_op Rpl_sys_table_access class object.
441
442 @returns std::tuple<bool, std::string> where each element has
443 following meaning:
444
445 first element of tuple is function return value and determines:
446 false Successful
447 true Error
448
449 second element of tuple is error message.
450 */
451 template <class T>
452 static std::tuple<bool, std::string> execute_handler_func_skip_send(
453 const std::vector<uint> &field_index,
454 const std::vector<std::string> &field_name, const T &field_value,
455 std::function<void(Rpl_sys_table_access &, bool &, std::string &, uint &,
456 key_part_map &)>
457 func,
458 uint table_index, key_part_map keypart_map,
459 Rpl_sys_table_access &table_op);
460
461 /**
462 A wrapper template function to save/delete data to given table,
463 and send stored table data to its group replication group members.
464
465
466 @param[in] db_name The database whose table will be used to
467 write/delete data.
468 @param[in] table_name The table to which data will be written or deleted.
469 @param[in] num_field The number of fields to be written or match while
470 querying for delete operations.
471 @param[in] lock_type How to lock the table
472 @param[in] field_index The list of field's position to be written or match
473 while querying for delete operations.
474 @param[in] field_name The list of field names of the table.
475 @param[in] field_value The field values to be written or match while
476 querying for delete operations.
477 @param[in] func The handler class function to write/delete data.
478 @param[in] table_index The table index/key position (by default i.e. on
479 position 0, if primary key present is used).
480 @param[in] keypart_map Which part of key to use.
481
482 @returns std::tuple<bool, std::string> where each element has
483 following meaning:
484
485 first element of tuple is function return value and determines:
486 false Successful
487 true Error
488
489 second element of tuple is error message.
490 */
491 template <class T>
492 static std::tuple<bool, std::string> execute_handler_func_send(
493 const std::string &db_name, const std::string &table_name, uint num_field,
494 enum thr_lock_type lock_type, const std::vector<uint> &field_index,
495 const std::vector<std::string> &field_name, const T &field_value,
496 std::function<void(Rpl_sys_table_access &, bool &, std::string &, uint &,
497 key_part_map &)>
498 func,
499 uint table_index, key_part_map keypart_map);
500};
501
502#endif /* RPL_ASYNC_CONN_FAILOVER_TABLE_OPERATIONS_H */
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1153
Definition: rpl_async_conn_failover_table_operations.h:61
static bool read_managed_random_rows_internal(Rpl_sys_table_access &table_op, std::vector< RPL_FAILOVER_MANAGED_JSON_TUPLE > &rows)
Read rows and fields from replication_asynchronous_connection_failover_managed table and returns its ...
Definition: rpl_async_conn_failover_table_operations.cc:498
enum thr_lock_type m_lock_type
Definition: rpl_async_conn_failover_table_operations.h:417
bool read_managed_random_rows(std::vector< RPL_FAILOVER_MANAGED_TUPLE > &rows)
Read rows and fields from replication_asynchronous_connection_failover_managed table and returns its ...
Definition: rpl_async_conn_failover_table_operations.cc:518
std::tuple< bool, std::vector< RPL_FAILOVER_SOURCE_TUPLE > > read_source_rows_for_channel_and_managed_name(std::string channel_name, std::string managed_name)
Real all sources for a channel and a managed name.
Definition: rpl_async_conn_failover_table_operations.cc:357
static const MYSQL_LEX_CSTRING Primary_weight_key
Definition: rpl_async_conn_failover_table_operations.h:411
static std::tuple< bool, std::string > execute_handler_func_skip_send(const std::vector< uint > &field_index, const std::vector< std::string > &field_name, const T &field_value, std::function< void(Rpl_sys_table_access &, bool &, std::string &, uint &, key_part_map &)> func, uint table_index, key_part_map keypart_map, Rpl_sys_table_access &table_op)
A wrapper template function to save/delete data to given table.
Definition: rpl_async_conn_failover_table_operations.cc:548
std::tuple< bool, std::string > delete_source(const std::string &channel, const std::string &host, uint port, const std::string &network_namespace)
Delete row for a unmanaged sender on replication_asynchronous_connection_failover table.
Definition: rpl_async_conn_failover_table_operations.cc:197
const uint m_table_failover_num_field
Definition: rpl_async_conn_failover_table_operations.h:422
bool read_managed_rows_for_channel(std::string channel_name, std::vector< RPL_FAILOVER_MANAGED_TUPLE > &rows)
Read rows and fields from replication_asynchronous_connection_failover_managed table and returns its ...
Definition: rpl_async_conn_failover_table_operations.cc:275
static std::tuple< bool, std::string > execute_handler_func_send(const std::string &db_name, const std::string &table_name, uint num_field, enum thr_lock_type lock_type, const std::vector< uint > &field_index, const std::vector< std::string > &field_name, const T &field_value, std::function< void(Rpl_sys_table_access &, bool &, std::string &, uint &, key_part_map &)> func, uint table_index, key_part_map keypart_map)
A wrapper template function to save/delete data to given table, and send stored table data to its gro...
Definition: rpl_async_conn_failover_table_operations.cc:588
Rpl_async_conn_failover_table_operations(enum thr_lock_type lock_type=TL_WRITE)
Construction.
Definition: rpl_async_conn_failover_table_operations.h:68
static std::tuple< bool, std::vector< RPL_FAILOVER_SOURCE_TUPLE > > read_source_all_rows_internal(Rpl_sys_table_access &table_op)
Read all sources.
Definition: rpl_async_conn_failover_table_operations.cc:396
const std::string m_table_failover
Definition: rpl_async_conn_failover_table_operations.h:420
std::tuple< bool, std::vector< RPL_FAILOVER_SOURCE_TUPLE > > read_source_random_rows()
Get all sources using random scan (ha_rnd_next) to fetch all the rows.
Definition: rpl_async_conn_failover_table_operations.cc:434
bool reset()
Delete all rows on replication_asynchronous_connection_failover_managed and replication_asynchronous_...
Definition: rpl_async_conn_failover_table_operations.cc:247
const std::string m_db
Definition: rpl_async_conn_failover_table_operations.h:418
static void get_data(Rpl_sys_table_access &table_op, TUP &rows)
Get stored data in table.
Definition: rpl_async_conn_failover_table_operations.cc:536
std::tuple< bool, std::vector< RPL_FAILOVER_SOURCE_TUPLE > > read_source_rows_for_channel(std::string channel_name)
Read all sources for a channel.
Definition: rpl_async_conn_failover_table_operations.cc:323
std::tuple< bool, std::string > add_managed(const std::string &channel, const std::string &host, uint port, const std::string &network_namespace, const std::string &managed_type, const std::string &managed_name, uint primary_weight, uint secondary_weight)
Insert row on replication_asynchronous_connection_failover_managed and replication_asynchronous_conne...
Definition: rpl_async_conn_failover_table_operations.cc:103
std::tuple< bool, std::string > add_source(const std::string &channel, const std::string &host, uint port, const std::string &network_namespace, uint weight, const std::string &managed_name)
Insert row for a unmanaged sender on replication_asynchronous_connection_failover table,...
Definition: rpl_async_conn_failover_table_operations.cc:62
static const MYSQL_LEX_CSTRING Secondary_weight_key
Definition: rpl_async_conn_failover_table_operations.h:414
std::tuple< bool, std::vector< RPL_FAILOVER_SOURCE_TUPLE > > read_source_all_rows()
Read all sources.
Definition: rpl_async_conn_failover_table_operations.cc:417
std::tuple< bool, std::string > delete_managed(const std::string &channel, const std::string &managed_name)
Delete row on replication_asynchronous_connection_failover_managed table and all its sources on repli...
Definition: rpl_async_conn_failover_table_operations.cc:216
static std::tuple< bool, std::string > add_source_skip_send(const std::string &channel, const std::string &host, uint port, const std::string &network_namespace, uint weight, const std::string &managed_name, Rpl_sys_table_access &table_op)
Insert row for a unmanaged sender on replication_asynchronous_connection_failover table.
Definition: rpl_async_conn_failover_table_operations.cc:83
const uint m_table_managed_num_field
Definition: rpl_async_conn_failover_table_operations.h:426
static std::tuple< bool, std::string > add_managed_skip_send(const std::string &channel, const std::string &managed_type, const std::string &managed_name, const Json_wrapper &wrapper, Rpl_sys_table_access &table_op)
Insert row on replication_asynchronous_connection_failover_managed table.
Definition: rpl_async_conn_failover_table_operations.cc:170
virtual ~Rpl_async_conn_failover_table_operations()=default
const std::string m_table_managed
Definition: rpl_async_conn_failover_table_operations.h:424
The class are wrappers for handler index and random scan functions to simplify their usage.
Definition: rpl_sys_table_access.h:45
ulong key_part_map
Definition: my_base.h:1008
const char * host
Definition: mysqladmin.cc:65
Definition: rpl_async_conn_failover_table_operations.h:37
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
required string managed_type
Definition: replication_asynchronous_connection_failover.proto:48
required string managed_name
Definition: replication_asynchronous_connection_failover.proto:36
required string network_namespace
Definition: replication_asynchronous_connection_failover.proto:34
required uint64 weight
Definition: replication_asynchronous_connection_failover.proto:35
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
std::vector< RPL_FAILOVER_SOURCE_TUPLE > RPL_FAILOVER_SOURCE_LIST
Definition: rpl_async_conn_failover_table_operations.h:53
std::tuple< std::string, std::string, std::string, Json_wrapper > RPL_FAILOVER_MANAGED_JSON_TUPLE
Definition: rpl_async_conn_failover_table_operations.h:47
std::tuple< std::string, std::string, uint, std::string, uint, std::string > RPL_FAILOVER_SOURCE_TUPLE
Definition: rpl_async_conn_failover_table_operations.h:43
std::tuple< std::string, std::string, std::string, uint, uint > RPL_FAILOVER_MANAGED_TUPLE
Definition: rpl_async_conn_failover_table_operations.h:51
Definition: mysql_lex_string.h:40
Definition: task.h:427
thr_lock_type
Definition: thr_lock.h:51
@ TL_WRITE
Definition: thr_lock.h:92