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