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