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