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