MySQL 8.0.31
Source Code Documentation
group_replication_message_service.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 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 GROUP_REPLICATION_MESSAGE_SERVICE_H
24#define GROUP_REPLICATION_MESSAGE_SERVICE_H
25
27#include <stddef.h>
28
29/**
30 @ingroup group_components_services_inventory
31
32 A service that sends content agnostic messages from a member to the group.
33
34 This only works if the component is on a server with group replication
35 running and the member state is ONLINE. If server isn't ONLINE message won't
36 be deliver.
37
38 After message sent to all members of the group, all components that have
39 registered group_replication_message_service_recv service will be notified.
40
41 @code
42 SERVICE_TYPE(registry) *plugin_registry = mysql_plugin_registry_acquire();
43 my_service<SERVICE_TYPE(group_replication_message_service_send)> svc(
44 "group_replication_message_service_send", plugin_registry);
45
46 if (svc.is_valid()) {
47 bool error = svc->send("tag", "payload", sizeof("payload"));
48 }
49 @endcode
50*/
51BEGIN_SERVICE_DEFINITION(group_replication_message_service_send)
52
53/**
54 This function SHALL be called whenever the caller wants to
55 send an agnostic messages to the group replication stream.
56
57 @param[in] tag tag identifies message
58 @param[in] payload data to be deliver
59 @param[in] payload_length size of data
60
61 @return false success, true on failure. Failure can happen if Group
62 Replication status isn't ONLINE or RECOVERING or a communication failure
63 occurs.
64*/
65DECLARE_BOOL_METHOD(send, (const char *tag, const unsigned char *payload,
66 const size_t payload_length));
67
68END_SERVICE_DEFINITION(group_replication_message_service_send)
69
70/**
71 A service that gets called whenever an agnostic message
72 from the group replication stream is to be delivered by
73 the group replication receiver thread.
74
75 The implementation MUST NOT block the caller.
76
77 This only works if the component is on a server with group replication
78 running and the member state is ONLINE. If server isn't ONLINE message won't
79 be notified about messages received.
80
81 @code
82DEFINE_BOOL_METHOD(recv, (const char *tag, const unsigned char *data,
83 size_t data_length)) {
84
85 // If tag is of interest do something with data
86 return false;
87}
88
89BEGIN_SERVICE_IMPLEMENTATION(listener_example,
90 group_replication_message_service_recv)
91recv, END_SERVICE_IMPLEMENTATION();
92
93bool register_listener() {
94 SERVICE_TYPE(registry) *plugin_registry = mysql_plugin_registry_acquire();
95 my_service<SERVICE_TYPE(registry_registration)> reg("registry_registration",
96 plugin_registry);
97 using group_replication_message_service_recv_t =
98 SERVICE_TYPE_NO_CONST(group_replication_message_service_recv);
99 bool result = reg->register_service(
100 "group_replication_message_service_recv.listener_example",
101 reinterpret_cast<my_h_service>(
102 const_cast<group_replication_message_service_recv_t *>(
103 &SERVICE_IMPLEMENTATION(
104 listener_example,
105 group_replication_message_service_recv))));
106 @endcode
107*/
108BEGIN_SERVICE_DEFINITION(group_replication_message_service_recv)
109
110/**
111 This function of every service implementation SHALL be called by group
112 replication whenever the group replication receive a service message sent to
113 the group.
114
115 @param[out] tag tag identifies message
116 @param[out] payload data to be deliver
117 @param[out] payload_length size of data
118
119 @return false success, true on failure.
120*/
121DECLARE_BOOL_METHOD(recv, (const char *tag, const unsigned char *payload,
122 const size_t payload_length));
123
124END_SERVICE_DEFINITION(group_replication_message_service_recv)
125
126#endif /* GROUP_REPLICATION_MESSAGE_SERVICE_H */
mysql_service_status_t recv(const char *tag, const unsigned char *data, size_t data_length) noexcept
Definition: gr_message_service_example.cc:38
mysql_service_status_t send(const char *tag, const unsigned char *data, const size_t data_length) noexcept
Definition: message_service.cc:31
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:90
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:85
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:111