File: member_actions_handler.h

package info (click to toggle)
mysql-8.0 8.0.45-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,048 kB
  • sloc: cpp: 4,685,434; ansic: 412,712; pascal: 108,396; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; python: 21,816; sh: 17,285; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,083; makefile: 1,793; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (304 lines) | stat: -rw-r--r-- 8,946 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
/* 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 MEMBER_ACTIONS_HANDLER_INCLUDED
#define MEMBER_ACTIONS_HANDLER_INCLUDED

#include <mysql/components/my_service.h>
#include <mysql/components/services/group_replication_message_service.h>
#include <string>
#include <utility>
#include "plugin/group_replication/generated/protobuf_lite/replication_group_member_actions.pb.h"
#include "plugin/group_replication/include/configuration_propagation.h"
#include "plugin/group_replication/include/thread/mysql_thread.h"

class Member_actions_handler_configuration;

/**
  @class Member_actions

  The list of events on which a member action can be triggered.
*/
class Member_actions {
 public:
  virtual ~Member_actions() {}

  enum enum_action_event { AFTER_PRIMARY_ELECTION = 0 };

  /**
    Return a string representation of a member action event.

    @return string representation
      @retval !=""   Successful
      @retval ""     invalid event
  */
  static const std::string get_event_name(enum_action_event event) {
    switch (event) {
      case AFTER_PRIMARY_ELECTION:
        return "AFTER_PRIMARY_ELECTION";
      default:
        /* purecov: begin inspected */
        assert(0);
        return "";
        /* purecov: end */
    }
  }
};

/**
  @class Member_actions_trigger_parameters

  The event on which a member action is triggered, which will be
  a trigger parameter.
*/
class Member_actions_trigger_parameters : public Mysql_thread_body_parameters {
 public:
  Member_actions_trigger_parameters(Member_actions::enum_action_event event)
      : m_event(event) {}

  Member_actions_trigger_parameters(const Member_actions_trigger_parameters &o)
      : m_event(o.m_event) {}

  virtual ~Member_actions_trigger_parameters() {}

  Member_actions::enum_action_event get_event() { return m_event; }

 private:
  Member_actions::enum_action_event m_event;
};

/**
  @class Member_actions_handler

  Handles member actions configuration and trigger.
*/
class Member_actions_handler : public Mysql_thread_body,
                               public Configuration_propagation {
 public:
  Member_actions_handler();

  virtual ~Member_actions_handler() override;

  /**
    Initialize the handler.

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool init();

  /**
    De-initialize the handler.

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool deinit();

  /**
    Acquires a reference to the
    `group_replication_message_service_send` service.

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool acquire_send_service();

  /**
    Releases the reference to the
    `group_replication_message_service_send` service.

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool release_send_service();

  /**
    Delivery method for the `group_replication_message_service_recv`
    service.
    A error on this method will move the member into ERROR state and
    follow the --group_replication_exit_state_action option.

    @param[in]  tag         the message tag
    @param[in]  data        the message data
    @param[in]  data_length the message data length

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool receive(const char *tag, const unsigned char *data, size_t data_length);

  /**
    Enable a member action for a given event.

    @param[in]  name        the action name
    @param[in]  event       the event on which the action will be triggered

    @return std::pair<bool, std::string> where each element has the
            following meaning:
              first element of the pair is the function error value:
                false  Successful
                true   Error
              second element of the pair is the error message.
  */
  std::pair<bool, std::string> enable_action(const std::string &name,
                                             const std::string &event);

  /**
    Disable a member action for a given event.

    @param[in]  name        the action name
    @param[in]  event       the event on which the action will be triggered

    @return std::pair<bool, std::string> where each element has the
            following meaning:
              first element of the pair is the function error value:
                false  Successful
                true   Error
              second element of the pair is the error message.
  */
  std::pair<bool, std::string> disable_action(const std::string &name,
                                              const std::string &event);

  /**
    Reset member actions to the default configuration.

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool reset_to_default_actions_configuration();

  /**
    Replace member actions configuration with the given one.

    @param[in]  exchanged_members_actions_serialized_configuration
                            the serialized configuration

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool replace_all_actions(
      const std::vector<std::string>
          &exchanged_members_actions_serialized_configuration);

  /**
    Retrieve member actions configuration in the serialized
    format.

    @param[out] serialized_configuration
                            the serialized configuration

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool get_all_actions(std::string &serialized_configuration);

  /**
    Propagate the local member actions configuration to the group,
    enabling the force_update flag, which will make the sent
    configuration to override other members configuration.

    @return Operation status
      @retval false  Successful
      @retval true   Error
  */
  bool force_my_actions_configuration_on_all_members();

  /**
    Trigger the actions configured to run on the given event.

    @param[in] event  the event that did trigger the member actions
  */
  void trigger_actions(Member_actions::enum_action_event event);

  /**
    Run the actions that were triggered.

    @param[in] parameters  the actions parameters
  */
  void run(Mysql_thread_body_parameters *parameters) override;

 private:
  /**
    Propagate the serialized configuration to the group.

    @param[in] serialized_configuration
                            the serialized configuration

    @return the operation status
      @retval false  Successful
      @retval true   Error
  */
  bool propagate_serialized_configuration(
      const std::string &serialized_configuration) override;

  /**
    Run a INTERNAL action.

    @param[in] action      action configuration

    @return the operation status
      @retval false  Successful
      @retval true   Error
  */
  int run_internal_action(
      const protobuf_replication_group_member_actions::Action &action);

  /**
    The tag used on the messages sent by this class.
  */
  const char *m_message_tag{"mysql_replication_group_member_actions"};

  /**
    The name of the message service listener.
  */
  const char *m_message_service_listener_name{
      "group_replication_message_service_recv.replication_group_member_"
      "actions"};

  /**
    The table configuration abstraction layer.
  */
  Member_actions_handler_configuration *m_configuration{nullptr};

  /**
    Single thread executor.
  */
  Mysql_thread *m_mysql_thread{nullptr};

  /**
    Pointer to the `group_replication_message_service_send` service.
  */
  SERVICE_TYPE_NO_CONST(group_replication_message_service_send) *
      m_group_replication_message_service_send{nullptr};
};

#endif /* MEMBER_ACTIONS_HANDLER_INCLUDED */