MySQL 9.1.0
Source Code Documentation
gcs_control_interface.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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 GCS_CONTROL_INTERFACE_INCLUDED
25#define GCS_CONTROL_INTERFACE_INCLUDED
26
27#include <vector>
28
32
33/**
34 @class Gcs_control_interface
35
36 This interface represents all the control functionalities that a binding
37 implementation must provide. Like all interfaces in this API, it is
38 group-oriented, meaning that a single instance shall exist per group,
39 as it was returned by the class Gcs_interface::get_control_session.
40
41 It contains methods for:
42 - View Membership;
43 - Control Events;
44 - Generic Data Exchange.
45
46 View Membership contain operations that will conduct one to:
47 - Belong to a group: join() and leave();
48 - Information about its status: belongs_to_group() and
49 get_current_view() that shall return the active Gcs_view.
50
51 Due to the asynchronous nature of this interface, the results of
52 join() and leave() operations, in local or remote members, shall come
53 via an event. Those events shall be delivered in form of callbacks
54 defined in Gcs_control_event_listener, that should be implemented by a
55 client of this interface interested in receiving those notifications.
56
57 Regarding Generic Data Exchange, it is a functionality that was created
58 to allow exchange of arbitrary data among members when one joins.
59 This generic data is retrieved via the callback get_exchangeable_data() each
60 time a View Change (VC) occurs. It states the data that one would like to
61 offer in exchange whenever a VC happens.
62
63 What must happen under the hood is that, when one receives a VC from
64 the underlying GCS, the binding implementation should start a round
65 of message exchange, in which members (one or all depending of the algorithm)
66 send the Exchangeable Data to the joining node.
67
68 That data is delivered when Gcs_control_event_listener::on_view_changed is
69 called, which hands-out all exchanged data in one point in time.
70
71 A typical usage for that interface would be:
72
73 @code{.cpp}
74 class my_Gcs_control_event_listener: Gcs_control_event_listener
75 {
76 void on_view_changed(const Gcs_view *new_view,
77 const Exchanged_data &exchanged_data)
78 {
79 // D something when view arrives...
80 // It will also deliver all data that nodes decided to offer at join()
81 // time
82 }
83
84 Gcs_message_data &get_exchangeable_data()
85 {
86 // Return whatever data we want to provide to a joining node
87 }
88 }
89
90 // Meanwhile in your client code...
91 Gcs_control_interface *gcs_control_interface_instance; // obtained
92 // previously
93
94 Gcs_control_event_listener *listener_instance=
95 new my_Gcs_control_event_listener();
96
97 int ref_handler=
98 gcs_control_interface_instance->add_event_listener(listener_instance);
99
100 // Normal program flow... join(), send_message(), leave()...
101
102 gcs_control_interface_instance->join();
103
104 gcs_control_interface_instance->leave();
105
106 // In the end...
107 gcs_control_interface_instance->remove_event_listener(ref_handler);
108
109 @endcode
110*/
112 public:
113 /**
114 Method that causes one to join the group that this
115 interface pertains.
116
117 The method is non-blocking, meaning that it shall only send the
118 request to an underlying GCS. The final result shall come via a
119 View Change event delivered through Gcs_control_event_listener.
120
121 @retval GCS_OK in case of everything goes well. Any other value of
122 gcs_error in case of error.
123 */
124
125 virtual enum_gcs_error join() = 0;
126
127 /**
128 Method that causes one to leave the group that this
129 interface pertains.
130
131 The method is non-blocking, meaning that it shall only send the
132 request to an underlying GCS. The final result shall come via a
133 View Change event delivered through Gcs_control_event_listener.
134
135 @retval GCS_OK in case of everything goes well. Any other value of
136 gcs_error in case of error
137 */
138
139 virtual enum_gcs_error leave() = 0;
140
141 /**
142 Reports if one has joined and belongs to a group.
143
144 @retval true if belonging to a group
145 */
146
147 virtual bool belongs_to_group() = 0;
148
149 /**
150 Returns the currently installed view.
151
152 @retval pointer to a Gcs_view object.
153 If one has left a group, this shall be the last
154 installed view. That view can be considered a best-effort
155 view since, in some GCSs, the one that leaves might not
156 have access to the exchanged information.
157 @retval NULL if one never joined a group.
158 */
159
161
162 /**
163 Retrieves the local identifier of this member on a group.
164
165 @retval reference to a valid Gcs_member_identifier instance
166 @retval NULL in case of error
167 */
168
170
171 /**
172 Registers an implementation of a Gcs_control_event_listener that will
173 receive Control Events. See the class header for more details on
174 implementations and usage.
175
176 Note that a binding implementation shall not offer the possibility of
177 changing listeners while the system is up and running. In that sense,
178 listeners must be added to it only when booting up the system.
179
180 @param[in] event_listener a class that implements Gcs_control_event_listener
181 @return an handle representing the registration of this object to
182 be used in remove_event_listener
183 */
184
186 const Gcs_control_event_listener &event_listener) = 0;
187
188 /**
189 Removes a previously registered event listener.
190
191 Note that a binding implementation shall not offer the possibility of
192 changing listeners while the system is up and running. In that sense
193 listeners must be removed from it only when shutting down the system.
194
195 @param[in] event_listener_handle the handle returned when the listener was
196 registered
197 */
198
199 virtual void remove_event_listener(int event_listener_handle) = 0;
200
201 /**
202 Sets a new value for the maximum size of the XCom cache.
203
204 @param[in] size the new maximum size of the XCom cache
205 @retval - GCS_OK if request was successfully scheduled in XCom,
206 GCS_NOK otherwise.
207 */
209
210 virtual ~Gcs_control_interface() = default;
211};
212
213#endif // GCS_CONTROL_INTERFACE_INCLUDED
This interface is implemented by those who wish to receive Control Interface notifications.
Definition: gcs_control_event_listener.h:52
This interface represents all the control functionalities that a binding implementation must provide.
Definition: gcs_control_interface.h:111
virtual enum_gcs_error leave()=0
Method that causes one to leave the group that this interface pertains.
virtual ~Gcs_control_interface()=default
virtual Gcs_view * get_current_view()=0
Returns the currently installed view.
virtual int add_event_listener(const Gcs_control_event_listener &event_listener)=0
Registers an implementation of a Gcs_control_event_listener that will receive Control Events.
virtual bool belongs_to_group()=0
Reports if one has joined and belongs to a group.
virtual const Gcs_member_identifier get_local_member_identifier() const =0
Retrieves the local identifier of this member on a group.
virtual void remove_event_listener(int event_listener_handle)=0
Removes a previously registered event listener.
virtual enum_gcs_error join()=0
Method that causes one to join the group that this interface pertains.
virtual enum_gcs_error set_xcom_cache_size(uint64_t size)=0
Sets a new value for the maximum size of the XCom cache.
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
This represents the membership view that a member has from a group.
Definition: gcs_view.h:55
enum_gcs_error
This enumeration describes errors which can occur during group communication operations.
Definition: gcs_types.h:41
size_t size(const char *const c)
Definition: base64.h:46