MySQL 8.0.39
Source Code Documentation
group_event_observer.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 GROUP_EVENT_OBSERVER_INCLUDED
25#define GROUP_EVENT_OBSERVER_INCLUDED
26
28#include <list>
29#include <string>
30#include <vector>
34
35/**
36 @class Group_event_observer
37 Class that others can extend to receive notifications about views and
38 primary elections.
39*/
41 public:
42 virtual ~Group_event_observer() = 0;
43 /**
44 Executed after view install and before primary election
45 @param joining members joining the group
46 @param leaving members leaving the group
47 @param group members in the group
48 @param is_leaving is the member leaving
49 @param[out] skip_election skip primary election on view
50 @param[out] election_mode election mode
51 @param[out] suggested_primary what should be the next primary to elect
52 */
53 virtual int after_view_change(
54 const std::vector<Gcs_member_identifier> &joining,
55 const std::vector<Gcs_member_identifier> &leaving,
56 const std::vector<Gcs_member_identifier> &group, bool is_leaving,
57 bool *skip_election, enum_primary_election_mode *election_mode,
58 std::string &suggested_primary) = 0;
59
60 /**
61 Executed after primary election
62 @param primary_uuid the elected primary
63 @param primary_change_status if the primary changed after the election
64 @param election_mode what was the election mode
65 @param error if there was and error on the process
66 */
68 std::string primary_uuid,
70 enum_primary_election_mode election_mode, int error) = 0;
71
72 /**
73 Executed before the message is processed
74 @param message The GCS message
75 @param message_origin The member that sent this message (address)
76 @param[out] skip_message skip message handling if true
77 */
78 virtual int before_message_handling(const Plugin_gcs_message &message,
79 const std::string &message_origin,
80 bool *skip_message) = 0;
81};
82
83/**
84 @class Group_events_observation_manager
85 Class alerts listeners of group events like view changes and elections.
86*/
88 public:
89 /*
90 Initialize the Group_events_observation_manager class.
91 */
93
94 /*
95 Destructor.
96 Deletes all observers
97 */
99
100 /**
101 The method to register new observers
102 @param observer An observer class to register
103 */
105
106 /**
107 The method to unregister new observers
108 @param observer An observer class to unregister
109 */
111
112 /**
113 Executed after view install and before primary election
114 @param joining members joining the group
115 @param leaving members leaving the group
116 @param group members in the group
117 @param is_leaving is the member leaving
118 @param[out] skip_election skip primary election on view
119 @param[out] election_mode election mode
120 @param[out] suggested_primary what should be the next primary to elect
121 */
122 int after_view_change(const std::vector<Gcs_member_identifier> &joining,
123 const std::vector<Gcs_member_identifier> &leaving,
124 const std::vector<Gcs_member_identifier> &group,
125 bool is_leaving, bool *skip_election,
126 enum_primary_election_mode *election_mode,
127 std::string &suggested_primary);
128
129 /**
130 Executed after primary election
131 @param primary_uuid the elected primary
132 @param primary_change_status if the primary changed after the election
133 @param election_mode what was the election mode
134 @param error if there was and error on the process
135 */
137 std::string primary_uuid,
139 enum_primary_election_mode election_mode, int error = 0);
140
141 /**
142 Executed before the message is processed
143 @param message The GCS message
144 @param message_origin The member that sent this message (address)
145 @param[out] skip_message skip message handling if true
146 */
148 const std::string &message_origin,
149 bool *skip_message);
150
151 private:
152 /** Locks the observer list for reads */
154 /** Locks the observer list for writes */
156 /** Unlocks the observer list */
158
159 /**The group event observers*/
160 std::list<Group_event_observer *> group_events_observers;
161 /**The lock to control access to the list*/
163};
164
165#endif /* GROUP_EVENT_OBSERVER_INCLUDED */
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:309
Class that others can extend to receive notifications about views and primary elections.
Definition: group_event_observer.h:40
virtual ~Group_event_observer()=0
virtual 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)=0
Executed after primary election.
virtual int before_message_handling(const Plugin_gcs_message &message, const std::string &message_origin, bool *skip_message)=0
Executed before the message is processed.
virtual 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)=0
Executed after view install and before primary election.
Class alerts listeners of group events like view changes and elections.
Definition: group_event_observer.h:87
~Group_events_observation_manager()
Definition: group_event_observer.cc:38
int before_message_handling(const Plugin_gcs_message &message, const std::string &message_origin, bool *skip_message)
Executed before the message is processed.
Definition: group_event_observer.cc:130
std::list< Group_event_observer * > group_events_observers
The group event observers.
Definition: group_event_observer.h:160
Checkable_rwlock * observer_list_lock
The lock to control access to the list.
Definition: group_event_observer.h:162
Group_events_observation_manager()
Definition: group_event_observer.cc:30
void unregister_group_event_observer(Group_event_observer *observer)
The method to unregister new observers.
Definition: group_event_observer.cc:61
void register_group_event_observer(Group_event_observer *observer)
The method to register new observers.
Definition: group_event_observer.cc:53
void read_lock_observer_list()
Locks the observer list for reads.
Definition: group_event_observer.cc:69
void write_lock_observer_list()
Locks the observer list for writes.
Definition: group_event_observer.cc:73
void unlock_observer_list()
Unlocks the observer list.
Definition: group_event_observer.cc:77
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=0)
Executed after primary election.
Definition: group_event_observer.cc:102
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)
Executed after view install and before primary election.
Definition: group_event_observer.cc:81
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