WL#12896: Group Replication: delivery message service
In order to allow other modules of the server to use Group Replication as a communication bus, Group Replication plugin will implement a service that will allow modules to register to send and receive messages.
This service, built on top of the new service infrastructure, will allow a module to send messages to all group members being those messages delivered to interested modules.
This service will send messages that contain raw payloads, being the marshal/unmarshall operations responsibility of the module that sends/receives the messages.
Motivation
To allow a better integration with 3rd parties or new features, we are creating two services to allow send and/or receive messages to all members of the group, the only requirement being that the module is part of the MySQL process.
Component developer stories
As a MySQL component developer I want to use Group Replication communication mechanism to transmit from on member messages to all members of the group.
As a MySQL component developer I want to use Group Replication communication mechanism to receive messages from members of the group.
Functional Requirements
FR1: A message sent for the group shall be received by all members that register the read service
FR2: The receiver service will queue all messages and deliver to subscribers on a dedicated thread, thence not holding the Group Communication Service deliver thread.
FR3: Only a member that does support the send service, can send messages.
FR4: Only a member that does support the receive service, can receive messages. Non-supported versions will not receive the message.
Non-Functional Requirements
Definitions
- GCS: Group Communication Service
- Group Replication: The group replication plugin, many times named GR in this document.
- Service: MySQL service registry component that works as an execution interface from different modules
- Modules: a component/plugin part of MySQL process that can use its services
Summary of approach
Using service registry Group Replication will add two services:
- send: send a message for all members of the group
- receive: will receive messages sent to the group
To implement this Group Replication will use GCS plugin messages to transmit to all members of the group.
Potential solutions
The transmitted message will be a generic message, that only carries data. The goal is to be the more generic possible.
To allow multiple usages of the send/receive services, the message will need to include some sender and/or receiver identifier.
It was evaluated three possible solutions:
A number representing the type of message will be sent with message and subscribers of read service will verify if will consume it or not
A list of service names will be sent with the message and when execute the receiver will acquire the service on the list and execute it
A tag is sent with the message, receivers validate if is of their interest and consume it if so
Solution 1 and 3 only differ how they identify the message, a integer or a tag system.
Solution 2 is more restrict, is based on service implementation. This is more restrict if you want to have multiple subscribers access to the same information.
Chosen Solution
Using a tag system, solution 3, we are able to send messages for multiple services registered, the service will validate if is interested on it or not.
The tag mechanism allow for a more informative description that a number but has the impact of more information needs to be transmitted between members.
Security context
To be able to use the service to cause any failure on the group, the attacker already has permissions to a lot of harm to the server.
A note on over use of service mechanism, it can consume resources on members of the group.
Upgrade/downgrade and cross-version replication
This service is only available on members that do support it, that is, on a group with members that do support it and that do not support it, only the members that do support can send and receive messages.
API
It will be added two services that will allow to send and receive messages to/from all members of the group.
Observability
In terms of observability, no new structures will be added in this worklog.
Deployment and installation
The worklog won't introduce any modification on plugin deployment or installation.
Protocol
The worklog will add one message type to GCS plugin messages that transmits a payload and a tag between all members of the group.
An example of a message:
Message = {
tag: "string";
payload: [bytes];
}
Failure model specification
The services are a layer over GCS plugin messages and service registry, the failures can deviate from errors from both under layers.
If the group has members that do not support the receive service, they will be ignored, thence not throwing errors.
Example: Group with 3 members, version 8.0.16 do not support receive service. M1: 8.0.16, M2: 8.0.17, M3: 8.0.17 A message sent from M2 or M3, is only delivered to M2 and M3.
Summary of Changes
A new GCS plugin message type, group service message, will be created to send the tag and the data
A recv service that will allow subscribers to received group service messages delivered to the group
A send service that will allow subscribers to send a group service message to all members of the group
GCS Plugin messages
Add group_service_message to plugin_gcs_messages, that will have two fields:
a tag that identify the type of the message transmitted
a payload that will contain data to be delivered to all members
To implement this it will be created a Group_service_message to allow decode and encode message (but not the payload) to be transmitted.
/*
@class Group_service_message
*/
class Group_service_message : public Plugin_gcs_message {
public:
enum enum_payload_item_type {
// This type should not be used anywhere.
PIT_UNKNOWN = 0,
// Length of the payload item: variable
PIT_TAG = 1,
// Length of the payload item: variable
PIT_DATA = 2,
// No valid type codes can appear after this one.
PIT_MAX = 3
};
private:
std::string m_tag;
std::vector<uchar> m_data;
};
MySQL component service
It will be added two services gr_message_service_send and gr_message_service_recv each one with one method.
On service gr_message_service_send it will be implemented a send method, to allow all registered members to send a message to the group.
/**
A service that can be used to send messages in the group replication stream.
*/
BEGIN_SERVICE_DEFINITION(gr_message_service_send)
/**
This function SHALL be called whenever the caller wants to
send an message to the group replication stream.
@return false success, true on failure.
*/
DECLARE_BOOL_METHOD(send, (const char* tag, const size_t tag_length, const unsigned char *payload, const size_t payload_length));
END_SERVICE_DEFINITION(gr_message_service_send)
On service gr_message_service_recv it will be implemented a recv method, to allow all registered to receive a message from the group.
/**
A service that gets called whenever an message from the group replication
stream is to be delivered by the group replication receiver thread.
The implementation MUST NOT block the caller.
*/
BEGIN_SERVICE_DEFINITION(gr_message_service_recv)
/**
This function SHALL be called whenever the caller wants to
send an message to the group replication stream.
@return false success, true on failure.
*/
DECLARE_BOOL_METHOD(recv, (const char* tag, const size_t tag_length, const unsigned char *payload, const size_t payload_length));
END_SERVICE_DEFINITION(gr_message_service_recv)
When the receiver services receives a message, it will queue the message in memory and deliver it to the listeners on a dedicated thread, thence not holding the Group Communication Service deliver thread.
Group Replication message service implementation
A message_service file will be added to services of group replication, it will contain gr_message_service_recv implementation that will call registered members of service read, to deliver the contents of sent from gr_message_service_send.
Test services
An implementation with usage of the services will be created, this will permit send and receive messages between elements from the group.