MySQL 8.4.2
Source Code Documentation
member_actions_handler.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 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 MEMBER_ACTIONS_HANDLER_INCLUDED
25#define MEMBER_ACTIONS_HANDLER_INCLUDED
26
29#include <string>
30#include <utility>
31#include "plugin/group_replication/generated/protobuf_lite/replication_group_member_actions.pb.h"
34
36
37/**
38 @class Member_actions
39
40 The list of events on which a member action can be triggered.
41*/
43 public:
44 virtual ~Member_actions() {}
45
47
48 /**
49 Return a string representation of a member action event.
50
51 @return string representation
52 @retval !="" Successful
53 @retval "" invalid event
54 */
55 static const std::string get_event_name(enum_action_event event) {
56 switch (event) {
58 return "AFTER_PRIMARY_ELECTION";
59 default:
60 /* purecov: begin inspected */
61 assert(0);
62 return "";
63 /* purecov: end */
64 }
65 }
66};
67
68/**
69 @class Member_actions_trigger_parameters
70
71 The event on which a member action is triggered, which will be
72 a trigger parameter.
73*/
75 public:
77 : m_event(event) {}
78
80 : m_event(o.m_event) {}
81
83
85
86 private:
88};
89
90/**
91 @class Member_actions_handler
92
93 Handles member actions configuration and trigger.
94*/
97 public:
99
100 virtual ~Member_actions_handler() override;
101
102 /**
103 Initialize the handler.
104
105 @return Operation status
106 @retval false Successful
107 @retval true Error
108 */
109 bool init();
110
111 /**
112 De-initialize the handler.
113
114 @return Operation status
115 @retval false Successful
116 @retval true Error
117 */
118 bool deinit();
119
120 /**
121 Acquires a reference to the
122 `group_replication_message_service_send` service.
123
124 @return Operation status
125 @retval false Successful
126 @retval true Error
127 */
129
130 /**
131 Releases the reference to the
132 `group_replication_message_service_send` service.
133
134 @return Operation status
135 @retval false Successful
136 @retval true Error
137 */
139
140 /**
141 Delivery method for the `group_replication_message_service_recv`
142 service.
143 A error on this method will move the member into ERROR state and
144 follow the --group_replication_exit_state_action option.
145
146 @param[in] tag the message tag
147 @param[in] data the message data
148 @param[in] data_length the message data length
149
150 @return Operation status
151 @retval false Successful
152 @retval true Error
153 */
154 bool receive(const char *tag, const unsigned char *data, size_t data_length);
155
156 /**
157 Enable a member action for a given event.
158
159 @param[in] name the action name
160 @param[in] event the event on which the action will be triggered
161
162 @return std::pair<bool, std::string> where each element has the
163 following meaning:
164 first element of the pair is the function error value:
165 false Successful
166 true Error
167 second element of the pair is the error message.
168 */
169 std::pair<bool, std::string> enable_action(const std::string &name,
170 const std::string &event);
171
172 /**
173 Disable a member action for a given event.
174
175 @param[in] name the action name
176 @param[in] event the event on which the action will be triggered
177
178 @return std::pair<bool, std::string> where each element has the
179 following meaning:
180 first element of the pair is the function error value:
181 false Successful
182 true Error
183 second element of the pair is the error message.
184 */
185 std::pair<bool, std::string> disable_action(const std::string &name,
186 const std::string &event);
187
188 /**
189 Reset member actions to the default configuration.
190
191 @return Operation status
192 @retval false Successful
193 @retval true Error
194 */
196
197 /**
198 Replace member actions configuration with the given one.
199
200 @param[in] exchanged_members_actions_serialized_configuration
201 the serialized configuration
202
203 @return Operation status
204 @retval false Successful
205 @retval true Error
206 */
208 const std::vector<std::string>
209 &exchanged_members_actions_serialized_configuration);
210
211 /**
212 Retrieve member actions configuration in the serialized
213 format.
214
215 @param[out] serialized_configuration
216 the serialized configuration
217
218 @return Operation status
219 @retval false Successful
220 @retval true Error
221 */
222 bool get_all_actions(std::string &serialized_configuration);
223
224 /**
225 Propagate the local member actions configuration to the group,
226 enabling the force_update flag, which will make the sent
227 configuration to override other members configuration.
228
229 @return Operation status
230 @retval false Successful
231 @retval true Error
232 */
234
235 /**
236 Trigger the actions configured to run on the given event.
237
238 @param[in] event the event that did trigger the member actions
239 */
241
242 /**
243 Run the actions that were triggered.
244
245 @param[in] parameters the actions parameters
246 */
247 void run(Mysql_thread_body_parameters *parameters) override;
248
249 private:
250 /**
251 Propagate the serialized configuration to the group.
252
253 @param[in] serialized_configuration
254 the serialized configuration
255
256 @return the operation status
257 @retval false Successful
258 @retval true Error
259 */
261 const std::string &serialized_configuration) override;
262
263 /**
264 Run a INTERNAL action.
265
266 @param[in] action action configuration
267
268 @return the operation status
269 @retval false Successful
270 @retval true Error
271 */
274
275 /**
276 The tag used on the messages sent by this class.
277 */
278 const char *m_message_tag{"mysql_replication_group_member_actions"};
279
280 /**
281 The name of the message service listener.
282 */
284 "group_replication_message_service_recv.replication_group_member_"
285 "actions"};
286
287 /**
288 The table configuration abstraction layer.
289 */
291
292 /**
293 Single thread executor.
294 */
296
297 /**
298 Pointer to the `group_replication_message_service_send` service.
299 */
300 SERVICE_TYPE_NO_CONST(group_replication_message_service_send) *
302};
303
304#endif /* MEMBER_ACTIONS_HANDLER_INCLUDED */
Interface for configuration propagation through Member_actions_handler.
Definition: configuration_propagation.h:33
The member actions table configuration abstraction layer.
Definition: member_actions_handler_configuration.h:36
Handles member actions configuration and trigger.
Definition: member_actions_handler.h:96
Member_actions_handler()
Definition: member_actions_handler.cc:45
int run_internal_action(const protobuf_replication_group_member_actions::Action &action)
Run a INTERNAL action.
Definition: member_actions_handler.cc:366
bool acquire_send_service()
Acquires a reference to the group_replication_message_service_send service.
Definition: member_actions_handler.cc:100
std::pair< bool, std::string > disable_action(const std::string &name, const std::string &event)
Disable a member action for a given event.
Definition: member_actions_handler.cc:288
std::pair< bool, std::string > enable_action(const std::string &name, const std::string &event)
Enable a member action for a given event.
Definition: member_actions_handler.cc:282
bool release_send_service()
Releases the reference to the group_replication_message_service_send service.
Definition: member_actions_handler.cc:127
bool propagate_serialized_configuration(const std::string &serialized_configuration) override
Propagate the serialized configuration to the group.
Definition: member_actions_handler.cc:261
void run(Mysql_thread_body_parameters *parameters) override
Run the actions that were triggered.
Definition: member_actions_handler.cc:305
bool force_my_actions_configuration_on_all_members()
Propagate the local member actions configuration to the group, enabling the force_update flag,...
Definition: member_actions_handler.cc:250
bool reset_to_default_actions_configuration()
Reset member actions to the default configuration.
Definition: member_actions_handler.cc:171
bool init()
Initialize the handler.
Definition: member_actions_handler.cc:51
Mysql_thread * m_mysql_thread
Single thread executor.
Definition: member_actions_handler.h:295
const char * m_message_service_listener_name
The name of the message service listener.
Definition: member_actions_handler.h:283
virtual ~Member_actions_handler() override
Definition: member_actions_handler.cc:49
mysql_service_group_replication_message_service_send_t * m_group_replication_message_service_send
Pointer to the group_replication_message_service_send service.
Definition: member_actions_handler.h:301
const char * m_message_tag
The tag used on the messages sent by this class.
Definition: member_actions_handler.h:278
bool receive(const char *tag, const unsigned char *data, size_t data_length)
Delivery method for the group_replication_message_service_recv service.
Definition: member_actions_handler.cc:144
bool replace_all_actions(const std::vector< std::string > &exchanged_members_actions_serialized_configuration)
Replace member actions configuration with the given one.
Definition: member_actions_handler.cc:182
void trigger_actions(Member_actions::enum_action_event event)
Trigger the actions configured to run on the given event.
Definition: member_actions_handler.cc:294
Member_actions_handler_configuration * m_configuration
The table configuration abstraction layer.
Definition: member_actions_handler.h:290
bool deinit()
De-initialize the handler.
Definition: member_actions_handler.cc:82
bool get_all_actions(std::string &serialized_configuration)
Retrieve member actions configuration in the serialized format.
Definition: member_actions_handler.cc:243
The event on which a member action is triggered, which will be a trigger parameter.
Definition: member_actions_handler.h:74
Member_actions::enum_action_event get_event()
Definition: member_actions_handler.h:84
Member_actions::enum_action_event m_event
Definition: member_actions_handler.h:87
Member_actions_trigger_parameters(const Member_actions_trigger_parameters &o)
Definition: member_actions_handler.h:79
virtual ~Member_actions_trigger_parameters()
Definition: member_actions_handler.h:82
Member_actions_trigger_parameters(Member_actions::enum_action_event event)
Definition: member_actions_handler.h:76
The list of events on which a member action can be triggered.
Definition: member_actions_handler.h:42
static const std::string get_event_name(enum_action_event event)
Return a string representation of a member action event.
Definition: member_actions_handler.h:55
enum_action_event
Definition: member_actions_handler.h:46
@ AFTER_PRIMARY_ELECTION
Definition: member_actions_handler.h:46
virtual ~Member_actions()
Definition: member_actions_handler.h:44
Interface for Mysql_thread_body parameters.
Definition: mysql_thread.h:39
Interface for Mysql_thread_body, the task of a Mysql_thread.
Definition: mysql_thread.h:108
A generic single thread executor.
Definition: mysql_thread.h:208
message Action
Definition: replication_group_member_actions.proto:30
repeated Action action
Definition: replication_group_member_actions.proto:43
required string event
Definition: replication_group_member_actions.proto:32
#define SERVICE_TYPE_NO_CONST(name)
Generates the standard Service type name.
Definition: service.h:71
case opt name
Definition: sslopt-case.h:29