MySQL 8.0.40
Source Code Documentation
primary_election_invocation_handler.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 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 PRIMARY_ELECTION_INVOCATION_HANDLER_INCLUDED
25#define PRIMARY_ELECTION_INVOCATION_HANDLER_INCLUDED
26
27#include <string>
28#include <vector>
29
36
37/**
38 @class Primary_election_handler
39 The base class to request and execute an election
40*/
42 public:
43 /**
44 Instantiate a new election handler
45 @param[in] components_stop_timeout the timeout when waiting on shutdown
46 */
47 Primary_election_handler(ulong components_stop_timeout);
48
49 /** Class destructor */
51
52 /**
53 Send a message to all members requesting an election
54
55 @param primary_uuid the primary member to elect
56 @param mode the election mode to use
57 */
58 int request_group_primary_election(std::string primary_uuid,
60
61 /**
62 Handle new received primary message of type SINGLE_PRIMARY_PRIMARY_ELECTION
63 @param message The received primary message
64 @param notification_ctx the notification object to report changes
65 @return !=0 in case of error
66 */
68 Notification_context *notification_ctx);
69
70 /**
71 Execute the primary member selection if needed and the election algorithm
72 invocation.
73
74 @param primary_uuid the primary member to elect
75 @param mode the election mode to use
76 @param notification_ctx the notification object to report changes
77
78 @return !=0 in case of error
79 */
80 int execute_primary_election(std::string &primary_uuid,
82 Notification_context *notification_ctx);
83
84 /**
85 Print server executed GTID and applier retrieved GTID in logs.
86 */
88
89 /**
90 Is an election process running?
91 @return true if yes, false if no
92 */
94
95 /**
96 Sets if the election process is running or not
97 @param election_running is the election running or not
98 */
99 void set_election_running(bool election_running);
100
101 /**
102 End any running election process.
103 @return !=0 in case of error
104 */
106
107 // Consistency transaction manager notifiers
108 /**
109 Notify transaction consistency manager that election is running
110 */
112
113 /**
114 Notify transaction consistency manager that election ended
115 */
116 void notify_election_end();
117
118 /**
119 Sets the component stop timeout.
120
121 @param[in] timeout the timeout
122 */
123 void set_stop_wait_timeout(ulong timeout);
124
125 private:
126 /**
127 Get the member to elect from all group members.
128 This method returns the current primary if one exists
129 If no primary exists this method returns one of the lowest version present
130 in the group according to a weight or uuid criteria.
131
132 @param[out] primary_uuid the primary member to elect
133 @param[in] all_members_info The members currently in the group
134
135 @return true if a primary is found, false otherwise
136 */
137 bool pick_primary_member(std::string &primary_uuid,
138 Group_member_info_list *all_members_info);
139
140 /**
141 Execute the standard primary election algorithm (that supports primary
142 appointments)
143
144 @param primary_uuid the primary member to elect
145 @param mode the election mode to use
146 */
147 int internal_primary_election(std::string &primary_uuid,
149
150 /**
151 Execute the legacy (<8.0.12) primary election algorithm
152
153 @param primary_uuid the primary member to elect
154 */
155 int legacy_primary_election(std::string &primary_uuid);
156
157 /** The handler to handle the election on the primary member */
159
160 /** The handler to handle the election in the secondary members */
162
163 /** Is an election running? */
165
166 /** The lock for the running flag*/
168};
169
170/**
171 Sort lower version members based on member weight if member version
172 is greater than equal to PRIMARY_ELECTION_MEMBER_WEIGHT_VERSION or uuid.
173
174 @param all_members_info the vector with members info
175 @param lowest_version_end first iterator position where members version
176 increases.
177*/
179 Group_member_info_list *all_members_info,
180 Group_member_info_list_iterator lowest_version_end);
181
182/**
183 Sort members based on member_version and get first iterator position
184 where member version differs.
185
186 @param all_members_info the vector with members info
187
188 @return the first iterator position where members version increase.
189
190 @note from the start of the list to the returned iterator, all members have
191 the lowest version in the group.
192 */
194 Group_member_info_list *all_members_info);
195
196#endif /* PRIMARY_ELECTION_INVOCATION_HANDLER_INCLUDED */
A convenience context class used to share information between the event handlers and the notifier.
Definition: notification.h:35
The base class to request and execute an election.
Definition: primary_election_invocation_handler.h:41
~Primary_election_handler()
Class destructor.
Definition: primary_election_invocation_handler.cc:39
Primary_election_primary_process primary_election_handler
The handler to handle the election on the primary member.
Definition: primary_election_invocation_handler.h:158
int execute_primary_election(std::string &primary_uuid, enum_primary_election_mode mode, Notification_context *notification_ctx)
Execute the primary member selection if needed and the election algorithm invocation.
Definition: primary_election_invocation_handler.cc:88
bool election_process_running
Is an election running?
Definition: primary_election_invocation_handler.h:164
int internal_primary_election(std::string &primary_uuid, enum_primary_election_mode mode)
Execute the standard primary election algorithm (that supports primary appointments)
Definition: primary_election_invocation_handler.cc:251
void notify_election_end()
Notify transaction consistency manager that election ended.
Definition: primary_election_invocation_handler.cc:513
Primary_election_secondary_process secondary_election_handler
The handler to handle the election in the secondary members.
Definition: primary_election_invocation_handler.h:161
Primary_election_handler(ulong components_stop_timeout)
Instantiate a new election handler.
Definition: primary_election_invocation_handler.cc:30
mysql_mutex_t flag_lock
The lock for the running flag.
Definition: primary_election_invocation_handler.h:167
int handle_primary_election_message(Single_primary_message *message, Notification_context *notification_ctx)
Handle new received primary message of type SINGLE_PRIMARY_PRIMARY_ELECTION.
Definition: primary_election_invocation_handler.cc:68
bool is_an_election_running()
Is an election process running?
Definition: primary_election_invocation_handler.cc:48
int terminate_election_process()
End any running election process.
Definition: primary_election_invocation_handler.cc:75
void print_gtid_info_in_log()
Print server executed GTID and applier retrieved GTID in logs.
Definition: primary_election_invocation_handler.cc:223
int legacy_primary_election(std::string &primary_uuid)
Execute the legacy (<8.0.12) primary election algorithm.
Definition: primary_election_invocation_handler.cc:288
bool pick_primary_member(std::string &primary_uuid, Group_member_info_list *all_members_info)
Get the member to elect from all group members.
Definition: primary_election_invocation_handler.cc:346
int request_group_primary_election(std::string primary_uuid, enum_primary_election_mode mode)
Send a message to all members requesting an election.
Definition: primary_election_invocation_handler.cc:61
void set_election_running(bool election_running)
Sets if the election process is running or not.
Definition: primary_election_invocation_handler.cc:55
void notify_election_running()
Notify transaction consistency manager that election is running.
Definition: primary_election_invocation_handler.cc:509
void set_stop_wait_timeout(ulong timeout)
Sets the component stop timeout.
Definition: primary_election_invocation_handler.cc:43
Class that contains the primary election process logic for the elected primary.
Definition: primary_election_primary_process.h:41
Class that contains the primary election process logic for secondary members.
Definition: primary_election_secondary_process.h:40
Definition: single_primary_message.h:35
Group_member_info_list::iterator Group_member_info_list_iterator
Definition: member_info.h:736
std::vector< Group_member_info *, Malloc_allocator< Group_member_info * > > Group_member_info_list
Definition: member_info.h:735
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:496
mode
Definition: file_handle.h:60
enum_primary_election_mode
Enum for election types.
Definition: primary_election_include.h:33
void sort_members_for_election(Group_member_info_list *all_members_info, Group_member_info_list_iterator lowest_version_end)
Sort lower version members based on member weight if member version is greater than equal to PRIMARY_...
Definition: primary_election_invocation_handler.cc:494
Group_member_info_list_iterator sort_and_get_lowest_version_member_position(Group_member_info_list *all_members_info)
Sort members based on member_version and get first iterator position where member version differs.
Definition: primary_election_invocation_handler.cc:429
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50