MySQL 8.0.39
Source Code Documentation
consensus_leaders_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 CONSENSUS_LEADERS_HANDLER_INCLUDED
25#define CONSENSUS_LEADERS_HANDLER_INCLUDED
26
31
32/**
33 * @brief Deals with the orchestration necessary to set the appropriate
34 * "consensus leaders" on GCS.
35 *
36 * Reacts to successful primary elections by setting the newly elected primary
37 * as the single preferred "consensus leader" in GCS.
38 */
40 public:
41 /**
42 * Register as a group event observer in @c group_events_manager.
43 *
44 * @param group_events_manager
45 */
47 Group_events_observation_manager &group_events_manager);
48
49 /**
50 * Unregister as a group event observer from @c m_group_events_manager.
51 */
53
54 int after_view_change(const std::vector<Gcs_member_identifier> &joining,
55 const std::vector<Gcs_member_identifier> &leaving,
56 const std::vector<Gcs_member_identifier> &group,
57 bool is_leaving, bool *skip_election,
58 enum_primary_election_mode *election_mode,
59 std::string &suggested_primary) override;
60
61 /**
62 * @brief Sets the newly elected primary as the single preferred "consensus
63 * leader" in GCS.
64 *
65 * @param primary_uuid the elected primary
66 * @param primary_change_status if the primary changed after the election
67 * @param election_mode what was the election mode
68 * @param error if there was and error on the process
69 * @return int 0 on success
70 */
72 std::string primary_uuid,
74 enum_primary_election_mode election_mode, int error) override;
75
77 const std::string &message_origin,
78 bool *skip_message) override;
79
80 /**
81 * @brief Set the appropriate "consensus leaders" in GCS.
82 *
83 * The "consensus leaders" are set according to the following rules:
84 * 0) If the the return result of allow_single_leader_getter lambda is false
85 * :do nothing
86 * a) @c communication_protocol is < 8.0.27: do nothing
87 * b) @c communication_protocol is >= 8.0.27:
88 * b1) @c primary_mode is SINGLE and @c my_role is PRIMARY: set myself,
89 * @c my_gcs_id, as the single preferred "consensus leader"
90 * b2) @c primary_mode is SINGLE and @c my_role is SECONDARY: do nothing
91 * b3) @c primary_mode is MULTI: set everyone as "consensus leader"
92 *
93 * @param communication_protocol
94 * @param is_single_primary_mode
95 * @param role
96 * @param my_gcs_id
97 * @param allow_single_leader_getter
98 */
99 void set_consensus_leaders(Member_version const &communication_protocol,
100 bool is_single_primary_mode,
102 Gcs_member_identifier const &my_gcs_id,
103 std::function<bool()> allow_single_leader_getter);
104
105 /**
106 * @brief Set the appropriate "consensus leaders" in GCS.
107 *
108 * The "consensus leaders" are set according to the following rules:
109 * a) @c communication_protocol is < 8.0.27: do nothing
110 * b) @c communication_protocol is >= 8.0.27:
111 * b1) @c primary_mode is SINGLE and @c my_role is PRIMARY: set myself,
112 * @c my_gcs_id, as the single preferred "consensus leader"
113 * b2) @c primary_mode is SINGLE and @c my_role is SECONDARY: do nothing
114 * b3) @c primary_mode is MULTI: set everyone as "consensus leader"
115 *
116 * It inserts a default implementation of allow_single_leader_getter that
117 * verifies the current value of group_replication_paxos_single_leader var
118 *
119 * @param communication_protocol
120 * @param is_single_primary_mode
121 * @param role
122 * @param my_gcs_id
123 */
124 void set_consensus_leaders(Member_version const &communication_protocol,
125 bool is_single_primary_mode,
127 Gcs_member_identifier const &my_gcs_id);
128
129 private:
131 Gcs_member_identifier const &leader) const;
133
134 static Member_version const
137};
138
139#endif /* CONSENSUS_LEADERS_HANDLER_INCLUDED */
Deals with the orchestration necessary to set the appropriate "consensus leaders" on GCS.
Definition: consensus_leaders_handler.h:39
~Consensus_leaders_handler() override
Unregister as a group event observer from m_group_events_manager.
Definition: consensus_leaders_handler.cc:46
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: consensus_leaders_handler.cc:50
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: consensus_leaders_handler.cc:93
Consensus_leaders_handler(Group_events_observation_manager &group_events_manager)
Register as a group event observer in group_events_manager.
Definition: consensus_leaders_handler.cc:40
Group_events_observation_manager & m_group_events_manager
Definition: consensus_leaders_handler.h:136
void set_consensus_leaders(Member_version const &communication_protocol, bool is_single_primary_mode, Group_member_info::Group_member_role role, Gcs_member_identifier const &my_gcs_id, std::function< bool()> allow_single_leader_getter)
Set the appropriate "consensus leaders" in GCS.
Definition: consensus_leaders_handler.cc:108
void set_as_single_consensus_leader(Gcs_member_identifier const &leader) const
Definition: consensus_leaders_handler.cc:128
void set_everyone_as_consensus_leader() const
Definition: consensus_leaders_handler.cc:154
static Member_version const s_first_protocol_with_support_for_consensus_leaders
Definition: consensus_leaders_handler.h:135
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
Sets the newly elected primary as the single preferred "consensus leader" in GCS.
Definition: consensus_leaders_handler.cc:59
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
Class that others can extend to receive notifications about views and primary elections.
Definition: group_event_observer.h:40
Class alerts listeners of group events like view changes and elections.
Definition: group_event_observer.h:87
Group_member_role
Definition: member_info.h:183
represent the MySQL version of a Member within the Group Replication group.
Definition: member_version.h:35
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
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