File: rpl_async_conn_failover_configuration_propagation.h

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (472 lines) | stat: -rw-r--r-- 15,133 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/* Copyright (c) 2021, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef RPL_ASYNC_CONN_FAILOVER_CONFIGURATION_PROPAGATION_INCLUDED
#define RPL_ASYNC_CONN_FAILOVER_CONFIGURATION_PROPAGATION_INCLUDED

#include <map>
#include <string>
#include <vector>
#include "sql/protobuf/generated/protobuf_lite/replication_asynchronous_connection_failover.pb.h"
#include "sql/rpl_sys_table_access.h"

/**
  Memory storage of the replication failover channel status
  configuration propagated to Group Replication members.
*/
class Rpl_acf_status_configuration {
 public:
  Rpl_acf_status_configuration();

  virtual ~Rpl_acf_status_configuration();

  /**
    Status keys propagated with the group.
  */
  enum enum_key { SOURCE_CONNECTION_AUTO_FAILOVER = 0 };

  /**
    Clears the status configuration.

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool reset();

  /**
    Reloads the status configuration from runtime information.
  */
  void reload();

  /**
    Delete the status configuration value.

    @param[in] channel  the channel name.
    @param[in] key      the variable whose status to set and increment
                        version.
  */
  void delete_channel_status(const std::string &channel,
                             Rpl_acf_status_configuration::enum_key key);

  /**
    Sets the status configuration value and increment version value.

    @param[in] channel  the channel name.
    @param[in] key      the variable whose status to set and increment
                        version.
    @param[in] value    the variable status value to set.
    @param[in] configuration  the configuration in protobuf
  */
  void set_value_and_increment_version(
      const std::string &channel, Rpl_acf_status_configuration::enum_key key,
      int value,
      protobuf_replication_asynchronous_connection_failover::VariableStatusList
          &configuration);

  /**
    Sets the status configuration with the one received from the
    group.

    @param[in] configuration  the configuration in protobuf

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool set(const protobuf_replication_asynchronous_connection_failover::
               VariableStatusList &configuration);

  /**
    Sets the status configuration with the one received from the
    group.

    @param[in] configuration  the configuration in protobuf

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool set(const protobuf_replication_asynchronous_connection_failover::
               SourceAndManagedAndStatusList &configuration);

  /**
    Gets the status configuration to send to the group.

    @param[out] configuration  the configuration in protobuf
  */
  void get(protobuf_replication_asynchronous_connection_failover::
               SourceAndManagedAndStatusList &configuration);

 private:
  mysql_mutex_t m_lock;

  ulonglong m_version{0};

  /*
    Stores replication failover channel status propagated to Group
    Replication members.
    map(<channel,key>, value)
  */
  std::map<std::pair<std::string, std::string>, int> m_status;

  static const std::vector<std::string> m_key_names;

  static std::string get_key_name(Rpl_acf_status_configuration::enum_key key);
};

/*
  Class provides functions to send and receive
  replication_asynchronous_connection_failover and
  replication_asynchronous_connection_failover_managed table data, and
  SOURCE_CONNECTION_AUTO_FAILOVER value of CHANGE REPLICATION SOURCE command.
*/
class Rpl_acf_configuration_handler {
 public:
  /**
    Construction.
  */
  Rpl_acf_configuration_handler();

  /**
    Destruction.
  */
  virtual ~Rpl_acf_configuration_handler();

  /**
    Initialize and configure group_replication_message_service_recv service
    so member can receive and process data from group members.

    @return function return value which determines if was:
            false  Successful
            true   Error
  */
  bool init();

  /**
    Receive data sent by group replication group member.

    @param[in] tag    identifier which determine type of data received.
    @param[in] data   data received.
    @param[in] data_length   size of data received.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool receive(const char *tag, const unsigned char *data, size_t data_length);

  /**
    Send variable status to its group replication group members.

    @param[in] channel  the channel name.
    @param[in] key  the variable whose status to be send.
    @param[in] status  the variable status to be send.

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool send_channel_status_and_version_data(
      const std::string &channel, Rpl_acf_status_configuration::enum_key key,
      int status);

  /**
    Delete channel status.

    @param[in] channel  the channel name.
    @param[in] key  the variable whose status to be send.
  */
  void delete_channel_status(const std::string &channel,
                             Rpl_acf_status_configuration::enum_key key);

  /**
    Get stored data in
    mysql.replication_asynchronous_connection_failover or
    mysql.replication_asynchronous_connection_failover_managed table and send
    to its group replication group members.

    @param[in]  table_op  Rpl_sys_table_access class object.

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool send_table_data(Rpl_sys_table_access &table_op);

  /**
    Get stored data in
    mysql.replication_asynchronous_connection_failover table and send
    to its group replication group members.

    @param[in]  table_op  Rpl_sys_table_access class object.

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool send_failover_data(Rpl_sys_table_access &table_op);

  /**
    Reload the failover channel status from runtime information.
  */
  void reload_failover_channels_status();

  /**
    Get data stored in
    mysql.replication_asynchronous_connection_failover or
    mysql.replication_asynchronous_connection_failover_managed table
    in protobuf serialized string format.

    @param[out]  serialized_configuration  save in protobuf serialized string
                                           format.

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool get_configuration(std::string &serialized_configuration);

  /**
    Save data in
    mysql.replication_asynchronous_connection_failover or
    mysql.replication_asynchronous_connection_failover_managed table.

    @param[in] exchanged_replication_failover_channels_serialized_configuration
                 save data from serialized string format.

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool set_configuration(
      const std::vector<std::string>
          &exchanged_replication_failover_channels_serialized_configuration);

  /**
    Collect and broadcast the replication failover channels configuration
    in a serialized
    protobuf_replication_asynchronous_connection_failover::SourceAndManagedAndStatusList
    message, that will override the configuration on all group members.

    @return the operation status
      @retval false  OK
      @retval true   Error
   */
  bool force_my_replication_failover_channels_configuration_on_all_members();

 private:
  /* The list of tag identfiers which type of data sent. */
  const std::vector<std::string> m_message_tag{
      "mysql_replication_asynchronous_connection_failover",
      "mysql_replication_asynchronous_connection_managed",
      "mysql_replication_asynchronous_connection_variable_status",
      "mysql_replication_asynchronous_connection_failover_and_managed_and_"
      "status"};

  /*
    The database replication_asynchronous_connection_failover and
    replication_asynchronous_connection_failover_managed table belongs to.
  */
  const std::string m_db{"mysql"};

  /* replication_asynchronous_connection_failover table name */
  const std::string m_table_failover{
      "replication_asynchronous_connection_failover"};

  /* number of fields in replication_asynchronous_connection_failover table */
  const uint m_table_failover_num_field{6};

  /* replication_asynchronous_connection_failover_managed table name */
  const std::string m_table_managed{
      "replication_asynchronous_connection_failover_managed"};
  /*
    number of fields in replication_asynchronous_connection_failover_managed
    table
  */
  const uint m_table_managed_num_field{4};

  /*
    Stores replication failover channel status propagated to Group
    Replication members.
  */
  Rpl_acf_status_configuration m_rpl_failover_channels_status;

  /**
    Unregister group_replication_message_service_recv service.

    @return function return value which determines if was:
            false  Successful
            true   Error
  */
  bool deinit();

  /**
    Receive mysql.replication_asynchronous_connection_failover table data sent
    by group replication group member.

    @param[in] data   data received.
    @param[in] data_length   size of data received.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool receive_failover(const unsigned char *data, size_t data_length);

  /**
    Receive mysql.replication_asynchronous_connection_failover_managed table
    data sent by group replication group member.

    @param[in] data   data received.
    @param[in] data_length   size of data received.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool receive_managed(const unsigned char *data, size_t data_length);

  /**
    Receive SOURCE_CONNECTION_AUTO_FAILOVER value of CHANGE REPLICATION SOURCE
    command data sent by group replication group member.

    @param[in] data   data received.
    @param[in] data_length   size of data received.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool receive_channel_status(const unsigned char *data, size_t data_length);

  /**
    Receive mysql.replication_asynchronous_connection_failover and
    mysql.replication_asynchronous_connection_failover_managed table
    data sent by group replication group member.

    @param[in] data   data received.
    @param[in] data_length   size of data received.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool receive_failover_and_managed_and_status(const unsigned char *data,
                                               size_t data_length);

  /**
    Send data to all group replication group members.

    @param[in] tag    identifier which determine type of data.
    @param[in] data   data to be send
    @param[in] data_length   size of data to be send.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool send(const char *tag, const char *data, size_t data_length);

  /**
    Send mysql.replication_asynchronous_connection_failover table data
    to group replication group members.

    @param[in] data   data to be send
    @param[in] data_length   size of data to be send.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool send_failover(const char *data, size_t data_length);

  /**
    Send mysql.replication_asynchronous_connection_failover_managed table data
    to group replication group members.

    @param[in] data   data to be send
    @param[in] data_length   size of data to be send.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool send_managed(const char *data, size_t data_length);

  /**
    Get stored data in
    mysql.replication_asynchronous_connection_failover_managed table and send
    to its group replication group members.

    @param[in]  table_op  Rpl_sys_table_access class object.

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool send_managed_data(Rpl_sys_table_access &table_op);

  /**
    Send SOURCE_CONNECTION_AUTO_FAILOVER value of CHANGE REPLICATION SOURCE
    command data to group replication group members.

    @param[in] data   data to be send
    @param[in] data_length   size of data to be send.

    @return function return value which determines if read was:
            false  Successful
            true   Error
  */
  bool send_channel_status(const char *data, size_t data_length);

  /**
    Save data in
    mysql.replication_asynchronous_connection_failover table.

    @param[in] configuration  the configuration in protobuf

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool set_failover_sources_internal(
      const protobuf_replication_asynchronous_connection_failover::
          SourceAndManagedAndStatusList &configuration);

  /**
    Save data in
    mysql.replication_asynchronous_connection_failover_managed table.

    @param[in] configuration  the configuration in protobuf

    @return function return value which determines:
            false  Successful
            true   Error
  */
  bool set_failover_managed_internal(
      const protobuf_replication_asynchronous_connection_failover::
          SourceAndManagedAndStatusList &configuration);
};

#endif /* RPL_ASYNC_CONN_FAILOVER_CONFIGURATION_PROPAGATION_INCLUDED */