MySQL 9.0.0
Source Code Documentation
gcs_xcom_synode.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 GCS_XCOM_SYNODE_H
25#define GCS_XCOM_SYNODE_H
26
27#include <sstream>
28#include <unordered_set>
30
31/**
32 Defines a message identifier so that joining members can fetch the associated
33 packet from a remote node.
34
35 See Gcs_xcom_communication_interface::recover_packets.
36
37 It wraps synode_no so we can use it in hash-based containers.
38 */
40 public:
41 Gcs_xcom_synode() noexcept;
42 explicit Gcs_xcom_synode(synode_no synod) noexcept;
43
45
46 Gcs_xcom_synode(Gcs_xcom_synode const &other) = default;
47 Gcs_xcom_synode &operator=(Gcs_xcom_synode const &other) = default;
48
49 Gcs_xcom_synode(Gcs_xcom_synode &&other) noexcept;
50 Gcs_xcom_synode &operator=(Gcs_xcom_synode &&other) noexcept;
51
52 bool operator==(const Gcs_xcom_synode &other) const;
53
54 synode_no const &get_synod() const;
55
56 private:
57 synode_no synode_;
58};
59
60/*
61 Specialization of std::hash<Gcs_xcom_synode> so we can use it in hash-based
62 containers.
63 */
64namespace std {
65template <>
66struct hash<Gcs_xcom_synode> {
67 std::size_t operator()(Gcs_xcom_synode const &s) const noexcept {
68 /*
69 Represent the synode as a string of the format g<gid>m<msg_nr>n<node_nr> to
70 serve as the hash function argument.
71 */
72 std::hash<std::string> hash_function;
73
74 std::ostringstream formatter;
75 formatter << "g" << s.get_synod().group_id << "m" << s.get_synod().msgno
76 << "n" << s.get_synod().node;
77 auto representation = formatter.str();
78
79 return hash_function(representation);
80 }
81};
82} // namespace std
83
84using Gcs_xcom_synode_set = std::unordered_set<Gcs_xcom_synode>;
85
86#endif // GCS_XCOM_SYNODE_H
Defines a message identifier so that joining members can fetch the associated packet from a remote no...
Definition: gcs_xcom_synode.h:39
Gcs_xcom_synode() noexcept
Definition: gcs_xcom_synode.cc:26
synode_no synode_
Definition: gcs_xcom_synode.h:57
Gcs_xcom_synode & operator=(Gcs_xcom_synode const &other)=default
Gcs_xcom_synode(Gcs_xcom_synode const &other)=default
bool operator==(const Gcs_xcom_synode &other) const
Definition: gcs_xcom_synode.cc:43
synode_no const & get_synod() const
Definition: gcs_xcom_synode.cc:47
std::unordered_set< Gcs_xcom_synode > Gcs_xcom_synode_set
Definition: gcs_xcom_synode.h:84
Definition: gcs_xcom_synode.h:64
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2871
std::size_t operator()(Gcs_xcom_synode const &s) const noexcept
Definition: gcs_xcom_synode.h:67