MySQL 9.1.0
Source Code Documentation
primary_election_primary_process.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_PRIMARY_PROCESS_INCLUDED
25#define PRIMARY_ELECTION_PRIMARY_PROCESS_INCLUDED
26
27#include <list>
28#include <string>
29
36
37/**
38 @class Primary_election_primary_process
39 Class that contains the primary election process logic for the elected primary
40*/
42 public:
43 /**
44 Class constructor for primary election process
45 */
47
48 /**
49 Class destructor for primary election process
50 */
52
53 /**
54 Launch the local process on the primary member for primary election
55
56 @param election_mode the context on which election is occurring
57 @param primary_to_elect the uuid of the primary to elect
58 @param group_members_info the member info about group members
59
60 @returns 0 in case of success, or 1 otherwise
61 */
63 enum_primary_election_mode election_mode, std::string &primary_to_elect,
64 Group_member_info_list *group_members_info);
65
66 /**
67 Is the election process running?
68 @returns election_process_running
69 */
71
72 /**
73 Is the process already terminating?
74 @returns election_process_ending
75 */
77
78 /**
79 Terminate the election process on shutdown
80 @param wait should it wait for the process to finish (default true).
81 */
82 int terminate_election_process(bool wait = true);
83
84 /**
85 Waits for the election thread process to finish
86 */
88
89 /*
90 Internal thread execution method with the election process
91 */
93
94 /**
95 Sets the component stop timeout.
96
97 @param[in] timeout the timeout
98 */
100
101 private:
102 // The listeners for group events
103
104 int after_view_change(const std::vector<Gcs_member_identifier> &joining,
105 const std::vector<Gcs_member_identifier> &leaving,
106 const std::vector<Gcs_member_identifier> &group,
107 bool is_leaving, bool *skip_election,
109 std::string &suggested_primary) override;
111 std::string primary_uuid,
115 const std::string &message_origin,
116 bool *skip_message) override;
117
118 /**
119 Signal that the read mode is ready on this member
120 @returns false in case of success, or true otherwise
121 */
123
124 /** Continuation object to wait on the applier queue consumption*/
125 std::shared_ptr<Continuation> applier_checkpoint_condition;
126
127 /** The election thread status */
129 /** Is the process aborted */
131
132 /* Is the primary ready? */
134 /** Are all group members in read mode */
136 /** Waiting for old primary transaction execution */
138 /** Are the main stages of the election process finished*/
140 /** The election invocation context */
142
143 /** The primary to be elected */
144 std::string primary_uuid;
145
146 /** The number of known members when the election started */
148 /** The members known for the current action */
149 std::list<std::string> known_members_addresses;
150
151 /** The stage handler for progress reporting */
153
154 /* Component stop timeout on shutdown */
156
157 // Run thread locks and conditions
158
159 /** The thread run lock*/
161 /** The thread run condition*/
163 /** The thread handle*/
165};
166
167#endif /* PRIMARY_ELECTION_PRIMARY_PROCESS_INCLUDED */
Class that others can extend to receive notifications about views and primary elections.
Definition: group_event_observer.h:40
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
Definition: stage_monitor_handler.h:30
Class that contains the primary election process logic for the elected primary.
Definition: primary_election_primary_process.h:41
bool waiting_on_queue_applied_message
Waiting for old primary transaction execution.
Definition: primary_election_primary_process.h:137
std::shared_ptr< Continuation > applier_checkpoint_condition
Continuation object to wait on the applier queue consumption.
Definition: primary_election_primary_process.h:125
mysql_cond_t election_cond
The thread run condition.
Definition: primary_election_primary_process.h:162
ulong stop_wait_timeout
Definition: primary_election_primary_process.h:155
int before_message_handling(const Plugin_gcs_message &message, const std::string &message_origin, bool *skip_message) override
Executed before the message is processed.
Definition: primary_election_primary_process.cc:434
std::string primary_uuid
The primary to be elected.
Definition: primary_election_primary_process.h:144
bool election_process_aborted
Is the process aborted.
Definition: primary_election_primary_process.h:130
thread_state election_process_thd_state
The election thread status.
Definition: primary_election_primary_process.h:128
int terminate_election_process(bool wait=true)
Terminate the election process on shutdown.
Definition: primary_election_primary_process.cc:494
bool is_election_process_terminating()
Is the process already terminating?
Definition: primary_election_primary_process.cc:63
void set_stop_wait_timeout(ulong timeout)
Sets the component stop timeout.
Definition: primary_election_primary_process.cc:55
int after_view_change(const std::vector< Gcs_member_identifier > &joining, const std::vector< Gcs_member_identifier > &leaving, const std::vector< Gcs_member_identifier > &group, bool is_leaving, bool *skip_election, enum_primary_election_mode *election_mode, std::string &suggested_primary) override
Executed after view install and before primary election.
Definition: primary_election_primary_process.cc:396
enum_primary_election_mode election_mode
The election invocation context.
Definition: primary_election_primary_process.h:141
ulong number_of_know_members
The number of known members when the election started.
Definition: primary_election_primary_process.h:147
std::list< std::string > known_members_addresses
The members known for the current action.
Definition: primary_election_primary_process.h:149
bool is_election_process_running()
Is the election process running?
Definition: primary_election_primary_process.cc:59
bool primary_ready
Definition: primary_election_primary_process.h:133
Primary_election_primary_process()
Class constructor for primary election process.
Definition: primary_election_primary_process.cc:36
int launch_primary_election_process(enum_primary_election_mode election_mode, std::string &primary_to_elect, Group_member_info_list *group_members_info)
Launch the local process on the primary member for primary election.
Definition: primary_election_primary_process.cc:70
my_thread_handle primary_election_pthd
The thread handle.
Definition: primary_election_primary_process.h:164
bool signal_read_mode_ready()
Signal that the read mode is ready on this member.
Definition: primary_election_primary_process.cc:488
int primary_election_process_handler()
Definition: primary_election_primary_process.cc:134
Plugin_stage_monitor_handler * stage_handler
The stage handler for progress reporting.
Definition: primary_election_primary_process.h:152
bool group_in_read_mode
Are all group members in read mode.
Definition: primary_election_primary_process.h:135
~Primary_election_primary_process() override
Class destructor for primary election process.
Definition: primary_election_primary_process.cc:50
int after_primary_election(std::string primary_uuid, enum_primary_election_primary_change_status primary_change_status, enum_primary_election_mode election_mode, int error) override
Executed after primary election.
Definition: primary_election_primary_process.cc:428
mysql_mutex_t election_lock
The thread run lock.
Definition: primary_election_primary_process.h:160
bool election_process_ending
Are the main stages of the election process finished.
Definition: primary_election_primary_process.h:139
void wait_on_election_process_termination()
Waits for the election thread process to finish.
Definition: primary_election_primary_process.cc:524
std::vector< Group_member_info *, Malloc_allocator< Group_member_info * > > Group_member_info_list
Definition: member_info.h:771
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
static int wait(mysql_cond_t *that, mysql_mutex_t *mutex_arg, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:63
enum_primary_election_mode
Enum for election types.
Definition: primary_election_include.h:33
enum_primary_election_primary_change_status
Enum for primary change status.
Definition: primary_election_include.h:50
Definition: my_thread_bits.h:58
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: plugin_utils.h:48