MySQL 9.1.0
Source Code Documentation
gcs_view.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_VIEW_INCLUDED
25#define GCS_VIEW_INCLUDED
26
27#include <string>
28#include <vector>
29
33
34/**
35 @class Gcs_view
36
37 This represents the membership view that a member has from a group.
38
39 This objects contains:
40 - A list of members that belong to this view.
41 - A Gcs_view_identifier identifier object, that uniquely identifies
42 this view in time.
43 - The members that were in the last view and that left. This shall
44 include the local member when it leaves the group.
45 - The members that joined, meaning that they were not present in the
46 previous view. This includes the local member when it joins a group,
47 meaning that a member can be in the list of members and joined.
48 - A Gcs_group_identifier to which this view pertains.
49
50 There are two ways to obtain this:
51 - In the Gcs_control_interface, one should call, at any moment, the
52 method Gcs_control_interface::get_current_view.
53 - Cache the value received via Gcs_control_event_listener::on_view_changed.
54*/
55class Gcs_view {
56 public:
57 /**
58 Define error codes associated to the view.
59 */
61
62 /**
63 Gcs_view constructor.
64
65 @param[in] members group members
66 @param[in] view_id the view identifier
67 @param[in] leaving the members that left from the previous view
68 @param[in] joined the new members
69 @param[in] group_id the group identifier
70 */
71
72 explicit Gcs_view(const std::vector<Gcs_member_identifier> &members,
73 const Gcs_view_identifier &view_id,
74 const std::vector<Gcs_member_identifier> &leaving,
75 const std::vector<Gcs_member_identifier> &joined,
76 const Gcs_group_identifier &group_id);
77
78 /**
79 @param[in] members group members
80 @param[in] view_id the view identifier
81 @param[in] leaving the members that left from the previous view
82 @param[in] joined the new members
83 @param[in] group_id the group identifier
84 @param[in] error_code error code associated to the view.
85 */
86
87 explicit Gcs_view(const std::vector<Gcs_member_identifier> &members,
88 const Gcs_view_identifier &view_id,
89 const std::vector<Gcs_member_identifier> &leaving,
90 const std::vector<Gcs_member_identifier> &joined,
91 const Gcs_group_identifier &group_id,
93
94 /**
95 Gcs_view constructor which does a deep copy of the object passed
96 as parameter.
97
98 @param[in] view reference to a Gcs_view object
99 */
100
101 explicit Gcs_view(Gcs_view const &view);
102
103 virtual ~Gcs_view();
104
105 /**
106 @return the current view identifier. This identifier marks a snapshot in
107 time and should increase monotonically
108 */
109
110 const Gcs_view_identifier &get_view_id() const;
111
112 /**
113 @return the group where this view pertains
114 */
115
116 const Gcs_group_identifier &get_group_id() const;
117
118 /**
119 @return the totality of members that currently belong to this group in a
120 certain moment in time, denoted by view_id
121 */
122
123 const std::vector<Gcs_member_identifier> &get_members() const;
124
125 /**
126 @return the members that left from the view n-1 to the current view n
127 */
128
129 const std::vector<Gcs_member_identifier> &get_leaving_members() const;
130
131 /**
132 @return the new members in view from view n-1 to the current view n
133 */
134
135 const std::vector<Gcs_member_identifier> &get_joined_members() const;
136
137 /**
138 @return error code associated to the current view.
139 */
140
142
143 /*
144 @param[in] address Member's identifier which is usually its address
145 @return the member whose identifier matches the one provided as
146 parameter
147 */
148
149 const Gcs_member_identifier *get_member(const std::string &member_id) const;
150
151 /*
152 @param[in] member_id Member's identifier which is usually its address
153 @return whether there is a member whose identifier matches the one
154 provided as parameter
155 */
156
157 bool has_member(const std::string &member_id) const;
158
159 private:
160 std::vector<Gcs_member_identifier> *m_members;
162 std::vector<Gcs_member_identifier> *m_leaving;
163 std::vector<Gcs_member_identifier> *m_joined;
166
167 /*
168 Auxiliary function used by constructors.
169 */
170 void clone(const std::vector<Gcs_member_identifier> &members,
171 const Gcs_view_identifier &view_id,
172 const std::vector<Gcs_member_identifier> &leaving,
173 const std::vector<Gcs_member_identifier> &joined,
174 const Gcs_group_identifier &group_id,
176
177 /*
178 Disabling the assignment operator.
179 */
181};
182
183#endif // GCS_VIEW_INCLUDED
This represents the unique identification of a group.
Definition: gcs_group_identifier.h:35
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
This represents the identification of a certain view of a certain group in a moment in time.
Definition: gcs_view_identifier.h:44
This represents the membership view that a member has from a group.
Definition: gcs_view.h:55
std::vector< Gcs_member_identifier > * m_members
Definition: gcs_view.h:160
Gcs_view_error_code
Define error codes associated to the view.
Definition: gcs_view.h:60
@ OK
Definition: gcs_view.h:60
@ MEMBER_EXPELLED
Definition: gcs_view.h:60
Gcs_view(const std::vector< Gcs_member_identifier > &members, const Gcs_view_identifier &view_id, const std::vector< Gcs_member_identifier > &leaving, const std::vector< Gcs_member_identifier > &joined, const Gcs_group_identifier &group_id)
Gcs_view constructor.
Definition: gcs_view.cc:29
std::vector< Gcs_member_identifier > * m_joined
Definition: gcs_view.h:163
const std::vector< Gcs_member_identifier > & get_joined_members() const
Definition: gcs_view.cc:125
bool has_member(const std::string &member_id) const
Definition: gcs_view.cc:146
Gcs_view_identifier * m_view_id
Definition: gcs_view.h:161
const Gcs_view_identifier & get_view_id() const
Definition: gcs_view.cc:110
Gcs_view::Gcs_view_error_code m_error_code
Definition: gcs_view.h:165
void clone(const std::vector< Gcs_member_identifier > &members, const Gcs_view_identifier &view_id, const std::vector< Gcs_member_identifier > &leaving, const std::vector< Gcs_member_identifier > &joined, const Gcs_group_identifier &group_id, Gcs_view::Gcs_view_error_code error_code)
Definition: gcs_view.cc:69
std::vector< Gcs_member_identifier > * m_leaving
Definition: gcs_view.h:162
const Gcs_group_identifier & get_group_id() const
Definition: gcs_view.cc:112
Gcs_view & operator=(Gcs_view const &)
const std::vector< Gcs_member_identifier > & get_leaving_members() const
Definition: gcs_view.cc:120
Gcs_group_identifier * m_group_id
Definition: gcs_view.h:164
virtual ~Gcs_view()
Definition: gcs_view.cc:102
const std::vector< Gcs_member_identifier > & get_members() const
Definition: gcs_view.cc:116
Gcs_view::Gcs_view_error_code get_error_code() const
Definition: gcs_view.cc:129
const Gcs_member_identifier * get_member(const std::string &member_id) const
Definition: gcs_view.cc:133