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