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