MySQL  8.0.22
Source Code Documentation
gcs_xcom_utils.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
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_UTILS_INCLUDED
24 #define GCS_XCOM_UTILS_INCLUDED
25 
26 #include <vector>
29 #include "plugin/group_replication/libmysqlgcs/xdr_gen/xcom_vp.h"
30 
31 #define XCOM_PREFIX "[XCOM] "
32 
33 /**
34  @class gcs_xcom_utils
35 
36  Class where the common binding utilities reside as static methods.
37 */
39  public:
40  /**
41  Create a xcom group identifier from a Group Identifier.
42 
43  @param[in] group_id A group identifier
44 
45  @return an hash of the group identifier string that will serve as input
46  for the group id in XCom
47  */
49 
50  /**
51  Processes a list of comma separated peer nodes.
52 
53  @param peer_nodes input string of comma separated peer nodes
54  @param[out] processed_peers the list of configured peers
55  */
56  static void process_peer_nodes(const std::string *peer_nodes,
57  std::vector<std::string> &processed_peers);
58 
59  /**
60  Validates peer nodes according with IP/Address rules enforced by
61  is_valid_hostname function
62 
63  @param [in,out] peers input list of peer nodes. It will be cleansed of
64  invalid peers
65  @param [in,out] invalid_peers This list will contain all invalid peers.
66  */
67  static void validate_peer_nodes(std::vector<std::string> &peers,
68  std::vector<std::string> &invalid_peers);
69 
70  /**
71  Simple multiplicative hash.
72 
73  @param buf the data to create an hash from
74  @param length data length
75 
76  @return calculated hash
77  */
78  static uint32_t mhash(const unsigned char *buf, size_t length);
79 
80  static int init_net();
81  static int deinit_net();
82 
83  virtual ~Gcs_xcom_utils();
84 };
85 
86 /**
87  * Converts the given GCS protocol version into the MySQL version that
88  * introduced it.
89  *
90  * @param protocol the GCS protocol
91  * @return the MySQL version that introduced it, in format major.minor.patch
92  */
94 
95 /*****************************************************
96  *****************************************************
97 
98  Auxiliary checking functions.
99 
100  *****************************************************
101  *****************************************************
102  */
103 
104 /**
105  Checks whether the given string is a number or not
106  @param s the string to check.
107  @return true if it is a number, false otherwise.
108  */
109 inline bool is_number(const std::string &s) {
110  return s.find_first_not_of("0123456789") == std::string::npos;
111 }
112 
113 /**
114  Parses the string "host:port" and checks if it is correct.
115 
116  @param server_and_port the server hostname and port in the form hostname:port.
117  @return true if it is a valid URL, false otherwise.
118  */
119 bool is_valid_hostname(const std::string &server_and_port);
120 
121 /**
122  Checks whether the given string is a valid GCS protocol known by this node.
123 
124  @returns true If it is, false otherwise.
125  */
126 bool is_valid_protocol(std::string const &protocol);
127 
128 /**
129  Does some transformations on the parameters. For instance, replaces
130  aliases with the correct ones
131  */
133 
134 /**
135  Checks that parameters are syntactically valid.
136 
137  @param params The parameters to validate syntactically.
138  @returns false if there is a syntax error, true otherwise.
139  */
141 #endif /* GCS_XCOM_UTILS_INCLUDED */
This class is to be used to provide parameters to bindings in a transparent and generic way...
Definition: gcs_types.h:58
bool is_number(const std::string &s)
Checks whether the given string is a number or not.
Definition: gcs_xcom_utils.h:109
bool is_valid_protocol(std::string const &protocol)
Checks whether the given string is a valid GCS protocol known by this node.
Definition: gcs_xcom_utils.cc:275
Gcs_protocol_version
The GCS protocol versions.
Definition: gcs_types.h:127
Definition: buf0block_hint.cc:29
protocol
Definition: memcached.h:112
static u_long build_xcom_group_id(Gcs_group_identifier &group_id)
Create a xcom group identifier from a Group Identifier.
Definition: gcs_xcom_utils.cc:67
static void validate_peer_nodes(std::vector< std::string > &peers, std::vector< std::string > &invalid_peers)
Validates peer nodes according with IP/Address rules enforced by is_valid_hostname function...
Definition: gcs_xcom_utils.cc:101
static int init_net()
Definition: gcs_xcom_utils.cc:125
bool is_valid_hostname(const std::string &server_and_port)
Parses the string "host:port" and checks if it is correct.
Definition: gcs_xcom_utils.cc:129
Definition: gcs_xcom_utils.h:38
static void process_peer_nodes(const std::string *peer_nodes, std::vector< std::string > &processed_peers)
Processes a list of comma separated peer nodes.
Definition: gcs_xcom_utils.cc:74
std::string gcs_protocol_to_mysql_version(Gcs_protocol_version protocol)
Converts the given GCS protocol version into the MySQL version that introduced it.
Definition: gcs_xcom_utils.cc:604
__u_long u_long
Definition: types.h:73
This represents the unique identification of a group.
Definition: gcs_group_identifier.h:34
virtual ~Gcs_xcom_utils()
Definition: gcs_xcom_utils.cc:65
static uint32_t mhash(const unsigned char *buf, size_t length)
Simple multiplicative hash.
Definition: gcs_xcom_utils.cc:115
static int deinit_net()
Definition: gcs_xcom_utils.cc:127
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
bool is_parameters_syntax_correct(const Gcs_interface_parameters &params)
Checks that parameters are syntactically valid.
Definition: gcs_xcom_utils.cc:311
void fix_parameters_syntax(Gcs_interface_parameters &params)
Does some transformations on the parameters.
Definition: gcs_xcom_utils.cc:149