MySQL 8.4.2
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 */
45 Group_events_observation_manager &group_events_manager);
46
47 /**
48 * Unregister as a group event observer from @c m_group_events_manager.
49 */
51
52 int after_view_change(const std::vector<Gcs_member_identifier> &joining,
53 const std::vector<Gcs_member_identifier> &leaving,
54 const std::vector<Gcs_member_identifier> &group,
55 bool is_leaving, bool *skip_election,
56 enum_primary_election_mode *election_mode,
57 std::string &suggested_primary) override;
58
59 /**
60 * @brief Sets the newly elected primary as the single preferred "consensus
61 * leader" in GCS.
62 *
63 * @param primary_uuid the elected primary
64 * @param primary_change_status if the primary changed after the election
65 * @param election_mode what was the election mode
66 * @param error if there was and error on the process
67 * @return int 0 on success
68 */
70 std::string primary_uuid,
72 enum_primary_election_mode election_mode, int error) override;
73
75 const std::string &message_origin,
76 bool *skip_message) override;
77
78 /**
79 * @brief Set the appropriate "consensus leaders" in GCS.
80 *
81 * The "consensus leaders" are set according to the following rules:
82 * 0) If the the return result of allow_single_leader_getter lambda is false
83 * :do nothing
84 * a) @c communication_protocol is < 8.0.27: do nothing
85 * b) @c communication_protocol is >= 8.0.27:
86 * b1) @c primary_mode is SINGLE and @c my_role is PRIMARY: set myself,
87 * @c my_gcs_id, as the single preferred "consensus leader"
88 * b2) @c primary_mode is SINGLE and @c my_role is SECONDARY: do nothing
89 * b3) @c primary_mode is MULTI: set everyone as "consensus leader"
90 */
91 void set_consensus_leaders(Member_version const &communication_protocol,
92 bool is_single_primary_mode,
94 Gcs_member_identifier const &my_gcs_id,
95 std::function<bool()> allow_single_leader_getter);
96
97 /**
98 * @brief Set the appropriate "consensus leaders" in GCS.
99 *
100 * The "consensus leaders" are set according to the following rules:
101 * a) @c communication_protocol is < 8.0.27: do nothing
102 * b) @c communication_protocol is >= 8.0.27:
103 * b1) @c primary_mode is SINGLE and @c my_role is PRIMARY: set myself,
104 * @c my_gcs_id, as the single preferred "consensus leader"
105 * b2) @c primary_mode is SINGLE and @c my_role is SECONDARY: do nothing
106 * b3) @c primary_mode is MULTI: set everyone as "consensus leader"
107 *
108 * It inserts a default implementation of allow_single_leader_getter that
109 * verifies the current value of group_replication_paxos_single_leader var
110 */
111 void set_consensus_leaders(Member_version const &communication_protocol,
112 bool is_single_primary_mode,
114 Gcs_member_identifier const &my_gcs_id);
115
116 private:
118 Gcs_member_identifier const &leader) const;
120
121 static Member_version const
124};
125
126#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:123
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:122
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:187
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