forked from mariadb-corporation/MaxScale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.hh
302 lines (258 loc) · 8.31 KB
/
server.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* Copyright (c) 2018 MariaDB Corporation Ab
* Copyright (c) 2023 MariaDB plc, Finnish Branch
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2027-11-30
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#pragma once
#include <maxscale/ccdefs.hh>
#include <mutex>
#include <string>
#include <unordered_map>
#include <maxscale/config_common.hh>
#include <maxscale/ssl.hh>
#include <maxscale/target.hh>
/**
* The SERVER structure defines a backend server. Each server has a name
* or IP address for the server, a port that the server listens on and
* the name of a protocol module that is loaded to implement the protocol
* between the gateway and the server.
*/
class SERVER : public mxs::Target
{
public:
/**
* Stores server version info. Encodes/decodes to/from the version number received from the server.
* Also stores the version string and parses information from it. Assumed to rarely change, so reads
* are not synchronized. */
class VersionInfo
{
public:
enum class Type
{
UNKNOWN, /**< Not connected yet */
MYSQL, /**< MySQL 5.5 or later. */
MARIADB, /**< MariaDB 5.5 or later */
XPAND, /**< Xpand node */
BLR /**< Binlog router */
};
struct Version
{
uint64_t total {0}; /**< Total version number received from server */
uint32_t major {0}; /**< Major version */
uint32_t minor {0}; /**< Minor version */
uint32_t patch {0}; /**< Patch version */
};
/**
* Reads in version data. Deduces server type from version string.
*
* @param version_num Version number from server
* @param version_string Version string from server
* @return True if version data changed
*/
bool set(uint64_t version_num, const std::string& version_string);
/**
* Return true if the server is a real database and can process queries. Returns false if server
* type is unknown or if the server is a binlogrouter.
*
* @return True if server is a real database
*/
bool is_database() const;
Type type() const;
const Version& version_num() const;
const char* version_string() const;
std::string type_string() const;
private:
static const int MAX_VERSION_LEN = 256;
mutable std::mutex m_lock; /**< Protects against concurrent writing */
Version m_version_num; /**< Numeric version */
Type m_type {Type::UNKNOWN}; /**< Server type */
char m_version_str[MAX_VERSION_LEN + 1] {'\0'}; /**< Server version string */
};
/**
* Find a server with the specified name.
*
* @param name Name of the server
* @return The server or NULL if not found
*/
static SERVER* find_by_unique_name(const std::string& name);
/**
* Find several servers with the names specified in an array. The returned array is equal in size
* to the server_names-array. If any server name was not found, then the corresponding element
* will be NULL.
*
* @param server_names An array of server names
* @return Array of servers
*/
static std::vector<SERVER*> server_find_by_unique_names(const std::vector<std::string>& server_names);
virtual ~SERVER() = default;
/**
* Get server address
*/
virtual const char* address() const = 0;
/**
* Get server port
*/
virtual int port() const = 0;
/**
* Get server extra port
*/
virtual int extra_port() const = 0;
/**
* Is proxy protocol in use?
*/
virtual bool proxy_protocol() const = 0;
/**
* Set proxy protocol
*
* @param proxy_protocol Whether proxy protocol is used
*/
virtual void set_proxy_protocol(bool proxy_protocol) = 0;
/**
* Get server character set
*
* @return The numeric character set or 0 if no character set has been read
*/
virtual uint8_t charset() const = 0;
/**
* Set server character set
*
* @param charset Character set to set
*/
virtual void set_charset(uint8_t charset) = 0;
/**
* Check if server has disk space threshold settings.
*
* @return True if limits exist
*/
virtual bool have_disk_space_limits() const = 0;
/**
* Get a copy of disk space limit settings.
*
* @return A copy of settings
*/
virtual DiskSpaceLimits get_disk_space_limits() const = 0;
/**
* Is persistent connection pool enabled.
*
* @return True if enabled
*/
virtual bool persistent_conns_enabled() const = 0;
/**
* Update server version.
*
* @param version_num New numeric version
* @param version_str New version string
*/
virtual void set_version(uint64_t version_num, const std::string& version_str) = 0;
/**
* Get version information. The contents of the referenced object may change at any time,
* although in practice this is rare.
*
* @return Version information
*/
virtual const VersionInfo& info() const = 0;
/**
* Update server address.
*
* @param address The new address
*/
virtual bool set_address(const std::string& address) = 0;
/**
* Update the server port.
*
* @param new_port New port. The value is not checked but should generally be 1 -- 65535.
*/
virtual void set_port(int new_port) = 0;
/**
* Update the server extra port.
*
* @param new_port New port. The value is not checked but should generally be 1 -- 65535.
*/
virtual void set_extra_port(int new_port) = 0;
/**
* @brief Check if a server points to a local MaxScale service
*
* @return True if the server points to a local MaxScale service
*/
virtual bool is_mxs_service() const = 0;
/**
* Set current ping
*
* @param ping Ping in milliseconds
*/
virtual void set_ping(int64_t ping) = 0;
/**
* Set replication lag
*
* @param lag The current replication lag in seconds
*/
virtual void set_replication_lag(int64_t lag) = 0;
// TODO: Don't expose this to the modules and instead destroy the server
// via ServerManager (currently needed by xpandmon)
virtual void deactivate() = 0;
/**
* Set a status bit in the server without locking
*
* @param bit The bit to set for the server
*/
virtual void set_status(uint64_t bit) = 0;
/**
* Clear a status bit in the server without locking
*
* @param bit The bit to clear for the server
*/
virtual void clear_status(uint64_t bit) = 0;
/**
* Assign server status
*
* @param status Status to assign
*/
virtual void assign_status(uint64_t status) = 0;
/**
* Get SSL configuration
*/
virtual mxb::SSLConfig ssl_config() const = 0;
/**
* Set value of 'session_track_system_variables'.
*
* @param value Value found in the MariaDB Server
*/
virtual void set_session_track_system_variables(std::string&& value) = 0;
/**
* Get server variable 'session_track_system_variables'.
*
* @param key Variable name to get
* @return Variable value
*/
virtual std::string get_session_track_system_variables() const = 0;
/**
* Set GTID positions
*
* @param positions List of pairs for the domain and the GTID position for it
*/
virtual void set_gtid_list(const std::vector<std::pair<uint32_t, uint64_t>>& positions) = 0;
/**
* Remove all stored GTID positions
*/
virtual void clear_gtid_list() = 0;
/**
* Get current server priority
*
* This should be used to decide which server is chosen as a master. Currently only galeramon uses it.
*/
virtual int64_t priority() const = 0;
/**
* Convert the configuration into parameters
*
* @return The server configuration
*/
virtual mxs::ConfigParameters to_params() const = 0;
};