MySQL 8.0.39
Source Code Documentation
gcs_plugin_messages.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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_PLUGIN_MESSAGES_INCLUDED
25#define GCS_PLUGIN_MESSAGES_INCLUDED
26
27/*
28 Since this file is used on unit tests, through member_info.h,
29 includes must set here and not through plugin_server_include.h.
30*/
31#include <string>
32#include <vector>
33
34#include "my_inttypes.h"
35
36/**
37 This is the base GCS plugin message.
38 It is composed by a fixed header and 1 or more payload items.
39
40 The on-the-wire layout looks like this:
41
42 +-----------------------------------+
43 | fixed header | payload |
44 +-----------------------------------+
45
46 The on-the-wire representation of the message is:
47
48 +-------------------+-----------+--------------------------------------+
49 | field | wire size | description |
50 +===================+===========+======================================+
51 | version | 4 bytes | protocol version |
52 | fixed_hdr_len | 2 bytes | length of the fixed header |
53 | message_len | 8 bytes | length of the message |
54 | cargo_type | 2 bytes | the cargo type in the payload |
55 +-------------------+-----------+--------------------------------------+
56 | payload_item_type | 2 bytes | the item type in the payload |
57 | payload_item_len | 8 bytes | length of the payload item |
58 | payload_item | X bytes | payload item |
59 +-------------------+-----------+--------------------------------------+
60
61 The last tree lines can occur one or more times.
62*/
63
65 public:
66 /**
67 The protocol version number.
68 */
70
71 /**
72 The protocol version number.
73 */
74 static const unsigned int WIRE_VERSION_SIZE;
75
76 /**
77 The on-the-wire size of the header length field.
78 */
79 static const unsigned int WIRE_HD_LEN_SIZE;
80
81 /**
82 The on-the-wire size of the message size field.
83 */
84 static const unsigned int WIRE_MSG_LEN_SIZE;
85
86 /**
87 The on-the-wire size of the cargo type field.
88 */
89 static const unsigned int WIRE_CARGO_TYPE_SIZE;
90
91 /**
92 The on-the-wire size of the fixed header.
93 */
94 static const unsigned int WIRE_FIXED_HEADER_SIZE;
95
96 /**
97 The on-the-wire size of the each payload item type field.
98 */
99 static const unsigned int WIRE_PAYLOAD_ITEM_TYPE_SIZE;
100
101 /**
102 The on-the-wire size of the each payload item size field.
103 */
104 static const unsigned int WIRE_PAYLOAD_ITEM_LEN_SIZE;
105
106 /**
107 The on-the-wire size of the payload item header.
108 */
109 static const unsigned int WIRE_PAYLOAD_ITEM_HEADER_SIZE;
110
111 /**
112 The different cargo type codes.
113
114 NOTE: all type values must fit into WIRE_CARGO_TYPE_SIZE bytes storage.
115 */
117 // This type should not be used anywhere.
119
120 // This cargo type is used for certification events, GTID_EXECUTED
121 // broadcast.
123
124 // This cargo type is used for transaction data.
126
127 // This cargo type is used for recovery events, signal when a given member
128 // becomes online.
130
131 // This cargo type is used for messaging related to stage exchanges,
132 // on which it represents one member.
134
135 // This cargo type is used for messaging related to stage exchanges,
136 // on which it represents a set of members.
138
139 // This cargo type is used for messaging related to members pipeline
140 // stats.
142
143 // This cargo type is used for messaging related to single primary
144 // mode.
146
147 // This cargo type is used for messaging related to group coordinated
148 // actions.
150
151 // This cargo type is used for messaging when checking if a group is valid
152 // for some task
154
155 // This cargo type is used for synchronization before executing a
156 // transaction.
158
159 // This cargo type is used for transaction data with guarantee.
161
162 // This cargo type is used to inform about prepared transactions.
164
165 // This cargo type is used for messages that are for
166 // senders/consumers outside the GR plugin.
168
169 // No valid type codes can appear after this one.
170 CT_MAX = 14
171 };
172
173 private:
174 /**
175 This header instance protocol version.
176 */
178
179 /**
180 This header instance length.
181 */
182 unsigned short m_fixed_header_len;
183
184 /**
185 This is the message length field.
186 */
187 unsigned long long m_msg_len;
188
189 /**
190 The cargo type code.
191 */
193
194 public:
195 virtual ~Plugin_gcs_message() = default;
196
197 /**
198 @return the value of the version field.
199 */
200 int get_version() { return m_version; }
201
202 /**
203 @return the value of the header length field value.
204 */
205 unsigned short get_header_length() { return m_fixed_header_len; }
206
207 /**
208 @return the cargo type.
209 */
211
212 /**
213 @return the message length field value.
214 */
215 unsigned long long get_msg_length() { return m_msg_len; }
216
217 /**
218 Encodes the contents of this instance into the buffer.
219
220 @param[out] buffer the buffer to encode to.
221 */
222 void encode(std::vector<unsigned char> *buffer) const;
223
224 /**
225 Decodes the contents of the buffer and sets the field values
226 according to the values decoded.
227
228 @param[in] buffer the buffer to decode from.
229 @param[in] length the length of the buffer.
230 */
231 void decode(const unsigned char *buffer, size_t length);
232
233 /**
234 Return the cargo type of a given message buffer, without decode
235 the complete message.
236
237 @param[in] buffer the buffer to decode from.
238
239 @return the cargo type of a given message buffer
240 */
241 static enum_cargo_type get_cargo_type(const unsigned char *buffer);
242
243 /**
244 Return the raw data of the first payload item of a given message buffer,
245 without decode the complete message.
246
247 @param[out] buffer the buffer to decode from.
248 @param[out] payload_item_data the data.
249 @param[out] payload_item_length the length of the data.
250 */
252 const unsigned char *buffer, const unsigned char **payload_item_data,
253 size_t *payload_item_length);
254
255 protected:
256 /**
257 Plugin_gcs_message constructor. Only to be called by derivative classes
258
259 @param[in] cargo_type Message type to be sent
260 */
261 explicit Plugin_gcs_message(enum_cargo_type cargo_type);
262
263 /**
264 Encodes the header of this instance into the buffer.
265
266 @param[out] buffer the buffer to encode to.
267 */
268 void encode_header(std::vector<unsigned char> *buffer) const;
269
270 /**
271 Decodes the header of the buffer into this instance.
272
273 @param[out] slider before call `decode_header`: the start of the buffer
274 after call `decode_header`: the position on which the
275 header ends on the buffer.
276 */
277 void decode_header(const unsigned char **slider);
278
279 /**
280 Encodes the contents of this instance payload into the buffer.
281
282 @param[out] buffer the buffer to encode to.
283 */
284 virtual void encode_payload(std::vector<unsigned char> *buffer) const = 0;
285
286 /**
287 Decodes the contents of the buffer and sets the payload field
288 values according to the values decoded.
289
290 @param[in] buffer the buffer to decode from.
291 @param[in] end the end of the buffer.
292 */
293 virtual void decode_payload(const unsigned char *buffer,
294 const unsigned char *end) = 0;
295
296 /**
297 Encodes the given payload item type and length into the buffer.
298
299 @param[out] buffer the buffer to encode to
300 @param[in] payload_item_type the type of the payload item
301 @param[in] payload_item_length the length of the payload item
302 */
304 std::vector<unsigned char> *buffer, uint16 payload_item_type,
305 unsigned long long payload_item_length) const;
306
307 /**
308 Decodes the given payload item type and length from the buffer.
309
310 @param[in] buffer the buffer to encode from
311 @param[out] payload_item_type the type of the payload item
312 @param[out] payload_item_length the length of the payload item
313 */
315 const unsigned char **buffer, uint16 *payload_item_type,
316 unsigned long long *payload_item_length);
317
318 /**
319 Encodes the given payload item (type, length and value) into the buffer as
320 a char (1 byte).
321
322 @param[out] buffer the buffer to encode to
323 @param[in] type the type of the payload item
324 @param[in] value the value of the payload item
325 */
326 void encode_payload_item_char(std::vector<unsigned char> *buffer, uint16 type,
327 unsigned char value) const;
328
329 /**
330 Decodes the given payload item (type, length and value) from the buffer as
331 a char (1 byte).
332
333 @param[in] buffer the buffer to encode from
334 @param[out] type the type of the payload item
335 @param[out] value the value of the payload item
336 */
337 static void decode_payload_item_char(const unsigned char **buffer,
338 uint16 *type, unsigned char *value);
339
340 /**
341 Encodes the given payload item (type, length and value) into the buffer as
342 a 2 bytes integer.
343
344 @param[out] buffer the buffer to encode to
345 @param[in] type the type of the payload item
346 @param[in] value the value of the payload item
347 */
348 void encode_payload_item_int2(std::vector<unsigned char> *buffer, uint16 type,
349 uint16 value) const;
350
351 /**
352 Decodes the given payload item (type, length and value) from the buffer as
353 a 2 bytes integer.
354
355 @param[in] buffer the buffer to encode from
356 @param[out] type the type of the payload item
357 @param[out] value the value of the payload item
358 */
359 void decode_payload_item_int2(const unsigned char **buffer, uint16 *type,
360 uint16 *value);
361
362 /**
363 Encodes the given payload item (type, length and value) into the buffer as
364 a 4 bytes integer.
365
366 @param[out] buffer the buffer to encode to
367 @param[in] type the type of the payload item
368 @param[in] value the value of the payload item
369 */
370 void encode_payload_item_int4(std::vector<unsigned char> *buffer, uint16 type,
371 uint32 value) const;
372
373 /**
374 Decodes the given payload item (type, length and value) from the buffer as
375 a 4 bytes integer.
376
377 @param[in] buffer the buffer to encode from
378 @param[out] type the type of the payload item
379 @param[out] value the value of the payload item
380 */
381 void decode_payload_item_int4(const unsigned char **buffer, uint16 *type,
382 uint32 *value);
383
384 /**
385 Encodes the given payload item (type, length and value) into the buffer as
386 a 8 bytes integer.
387
388 @param[out] buffer the buffer to encode to
389 @param[in] type the type of the payload item
390 @param[in] value the value of the payload item
391 */
392 void encode_payload_item_int8(std::vector<unsigned char> *buffer, uint16 type,
393 ulonglong value) const;
394
395 /**
396 Decodes the given payload item (type, length and value) from the buffer as
397 a 8 bytes integer.
398
399 @param[in] buffer the buffer to encode from
400 @param[out] type the type of the payload item
401 @param[out] value the value of the payload item
402 */
403 void decode_payload_item_int8(const unsigned char **buffer, uint16 *type,
404 uint64 *value);
405
406 /**
407 Encodes the given payload item (type, length and value) into the buffer as
408 a char array (variable size).
409
410 @param[out] buffer the buffer to encode to
411 @param[in] type the type of the payload item
412 @param[in] value the value of the payload item
413 @param[in] length the length of the payload item
414 */
415 void encode_payload_item_string(std::vector<unsigned char> *buffer,
416 uint16 type, const char *value,
417 unsigned long long length) const;
418
419 /**
420 Decodes the given payload item (type, length and value) from the buffer as
421 a char array (variable size).
422
423 @param[in] buffer the buffer to encode from
424 @param[out] type the type of the payload item
425 @param[out] value the value of the payload item
426 @param[out] length the length of the payload item
427 */
428 void decode_payload_item_string(const unsigned char **buffer, uint16 *type,
429 std::string *value,
430 unsigned long long *length);
431
432 /**
433 Encodes the given payload item (type, length and value) into the buffer as
434 a byte buffer (variable size).
435
436 @param[out] buffer the buffer to encode to
437 @param[in] type the type of the payload item
438 @param[in] value the value of the payload item
439 @param[in] length the length of the payload item
440 */
441 void encode_payload_item_bytes(std::vector<unsigned char> *buffer,
442 uint16 type, const unsigned char *value,
443 unsigned long long length) const;
444
445 /**
446 Decodes the given payload item (type, length and value) from the buffer as
447 a byte buffer (variable size).
448
449 @param[in] buffer the buffer to encode from
450 @param[out] type the type of the payload item
451 @param[out] value the value of the payload item
452 @param[out] length the length of the payload item
453 */
454 void decode_payload_item_bytes(const unsigned char **buffer, uint16 *type,
455 unsigned char *value,
456 unsigned long long *length);
457};
458
459#endif /* GCS_PLUGIN_MESSAGES_INCLUDED */
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
void decode_payload_item_int2(const unsigned char **buffer, uint16 *type, uint16 *value)
Decodes the given payload item (type, length and value) from the buffer as a 2 bytes integer.
Definition: gcs_plugin_messages.cc:200
enum_cargo_type get_cargo_type() const
Definition: gcs_plugin_messages.h:210
void encode(std::vector< unsigned char > *buffer) const
Encodes the contents of this instance into the buffer.
Definition: gcs_plugin_messages.cc:78
void encode_payload_item_type_and_length(std::vector< unsigned char > *buffer, uint16 payload_item_type, unsigned long long payload_item_length) const
Encodes the given payload item type and length into the buffer.
Definition: gcs_plugin_messages.cc:140
static const int PLUGIN_GCS_MESSAGE_VERSION
The protocol version number.
Definition: gcs_plugin_messages.h:69
int m_version
This header instance protocol version.
Definition: gcs_plugin_messages.h:177
void encode_payload_item_string(std::vector< unsigned char > *buffer, uint16 type, const char *value, unsigned long long length) const
Encodes the given payload item (type, length and value) into the buffer as a char array (variable siz...
Definition: gcs_plugin_messages.cc:250
static void get_first_payload_item_raw_data(const unsigned char *buffer, const unsigned char **payload_item_data, size_t *payload_item_length)
Return the raw data of the first payload item of a given message buffer, without decode the complete ...
Definition: gcs_plugin_messages.cc:128
void encode_header(std::vector< unsigned char > *buffer) const
Encodes the header of this instance into the buffer.
Definition: gcs_plugin_messages.cc:56
unsigned long long get_msg_length()
Definition: gcs_plugin_messages.h:215
void encode_payload_item_int2(std::vector< unsigned char > *buffer, uint16 type, uint16 value) const
Encodes the given payload item (type, length and value) into the buffer as a 2 bytes integer.
Definition: gcs_plugin_messages.cc:190
unsigned short get_header_length()
Definition: gcs_plugin_messages.h:205
static const unsigned int WIRE_PAYLOAD_ITEM_LEN_SIZE
The on-the-wire size of the each payload item size field.
Definition: gcs_plugin_messages.h:104
enum_cargo_type
The different cargo type codes.
Definition: gcs_plugin_messages.h:116
@ CT_TRANSACTION_MESSAGE
Definition: gcs_plugin_messages.h:125
@ CT_CERTIFICATION_MESSAGE
Definition: gcs_plugin_messages.h:122
@ CT_RECOVERY_MESSAGE
Definition: gcs_plugin_messages.h:129
@ CT_TRANSACTION_WITH_GUARANTEE_MESSAGE
Definition: gcs_plugin_messages.h:160
@ CT_GROUP_ACTION_MESSAGE
Definition: gcs_plugin_messages.h:149
@ CT_SINGLE_PRIMARY_MESSAGE
Definition: gcs_plugin_messages.h:145
@ CT_MAX
Definition: gcs_plugin_messages.h:170
@ CT_SYNC_BEFORE_EXECUTION_MESSAGE
Definition: gcs_plugin_messages.h:157
@ CT_MEMBER_INFO_MESSAGE
Definition: gcs_plugin_messages.h:133
@ CT_TRANSACTION_PREPARED_MESSAGE
Definition: gcs_plugin_messages.h:163
@ CT_UNKNOWN
Definition: gcs_plugin_messages.h:118
@ CT_MESSAGE_SERVICE_MESSAGE
Definition: gcs_plugin_messages.h:167
@ CT_MEMBER_INFO_MANAGER_MESSAGE
Definition: gcs_plugin_messages.h:137
@ CT_GROUP_VALIDATION_MESSAGE
Definition: gcs_plugin_messages.h:153
@ CT_PIPELINE_STATS_MEMBER_MESSAGE
Definition: gcs_plugin_messages.h:141
static const unsigned int WIRE_PAYLOAD_ITEM_TYPE_SIZE
The on-the-wire size of the each payload item type field.
Definition: gcs_plugin_messages.h:99
static const unsigned int WIRE_FIXED_HEADER_SIZE
The on-the-wire size of the fixed header.
Definition: gcs_plugin_messages.h:94
virtual void encode_payload(std::vector< unsigned char > *buffer) const =0
Encodes the contents of this instance payload into the buffer.
static const unsigned int WIRE_PAYLOAD_ITEM_HEADER_SIZE
The on-the-wire size of the payload item header.
Definition: gcs_plugin_messages.h:109
enum_cargo_type m_cargo_type
The cargo type code.
Definition: gcs_plugin_messages.h:192
void encode_payload_item_bytes(std::vector< unsigned char > *buffer, uint16 type, const unsigned char *value, unsigned long long length) const
Encodes the given payload item (type, length and value) into the buffer as a byte buffer (variable si...
Definition: gcs_plugin_messages.cc:269
void decode_payload_item_string(const unsigned char **buffer, uint16 *type, std::string *value, unsigned long long *length)
Decodes the given payload item (type, length and value) from the buffer as a char array (variable siz...
Definition: gcs_plugin_messages.cc:259
static void decode_payload_item_char(const unsigned char **buffer, uint16 *type, unsigned char *value)
Decodes the given payload item (type, length and value) from the buffer as a char (1 byte).
Definition: gcs_plugin_messages.cc:179
static const unsigned int WIRE_MSG_LEN_SIZE
The on-the-wire size of the message size field.
Definition: gcs_plugin_messages.h:84
int get_version()
Definition: gcs_plugin_messages.h:200
void decode(const unsigned char *buffer, size_t length)
Decodes the contents of the buffer and sets the field values according to the values decoded.
Definition: gcs_plugin_messages.cc:104
void encode_payload_item_int8(std::vector< unsigned char > *buffer, uint16 type, ulonglong value) const
Encodes the given payload item (type, length and value) into the buffer as a 8 bytes integer.
Definition: gcs_plugin_messages.cc:230
static void decode_payload_item_type_and_length(const unsigned char **buffer, uint16 *payload_item_type, unsigned long long *payload_item_length)
Decodes the given payload item type and length from the buffer.
Definition: gcs_plugin_messages.cc:156
static const unsigned int WIRE_HD_LEN_SIZE
The on-the-wire size of the header length field.
Definition: gcs_plugin_messages.h:79
void encode_payload_item_int4(std::vector< unsigned char > *buffer, uint16 type, uint32 value) const
Encodes the given payload item (type, length and value) into the buffer as a 4 bytes integer.
Definition: gcs_plugin_messages.cc:210
unsigned long long m_msg_len
This is the message length field.
Definition: gcs_plugin_messages.h:187
virtual ~Plugin_gcs_message()=default
void encode_payload_item_char(std::vector< unsigned char > *buffer, uint16 type, unsigned char value) const
Encodes the given payload item (type, length and value) into the buffer as a char (1 byte).
Definition: gcs_plugin_messages.cc:168
static const unsigned int WIRE_VERSION_SIZE
The protocol version number.
Definition: gcs_plugin_messages.h:74
void decode_payload_item_int4(const unsigned char **buffer, uint16 *type, uint32 *value)
Decodes the given payload item (type, length and value) from the buffer as a 4 bytes integer.
Definition: gcs_plugin_messages.cc:220
virtual void decode_payload(const unsigned char *buffer, const unsigned char *end)=0
Decodes the contents of the buffer and sets the payload field values according to the values decoded.
void decode_payload_item_bytes(const unsigned char **buffer, uint16 *type, unsigned char *value, unsigned long long *length)
Decodes the given payload item (type, length and value) from the buffer as a byte buffer (variable si...
Definition: gcs_plugin_messages.cc:279
unsigned short m_fixed_header_len
This header instance length.
Definition: gcs_plugin_messages.h:182
static const unsigned int WIRE_CARGO_TYPE_SIZE
The on-the-wire size of the cargo type field.
Definition: gcs_plugin_messages.h:89
Plugin_gcs_message(enum_cargo_type cargo_type)
Plugin_gcs_message constructor.
Definition: gcs_plugin_messages.cc:50
void decode_payload_item_int8(const unsigned char **buffer, uint16 *type, uint64 *value)
Decodes the given payload item (type, length and value) from the buffer as a 8 bytes integer.
Definition: gcs_plugin_messages.cc:240
void decode_header(const unsigned char **slider)
Decodes the header of the buffer into this instance.
Definition: gcs_plugin_messages.cc:85
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint64_t uint64
Definition: my_inttypes.h:69
uint16_t uint16
Definition: my_inttypes.h:65
uint32_t uint32
Definition: my_inttypes.h:67
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:76
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:420
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
required string type
Definition: replication_group_member_actions.proto:34