...
Geode uses UDP messaging through JGroups for peer-to-peer messaging related to membership. Geode does not actually use jgroups group membership system, just only it's reliable UDP messaging. Using UDP messaging through JGroups has a couple of issues:
...
- It is not a goal to allow the user to configure their own messaging system.
- It is not a goal to replace the existing and separate peer-to-peer TCP messaging system that is used for cache operations. The new messaging system is initially targeted only at replacing our use of jgroups UDP for membership messages.
Design
All of messaging related to membership is handled by the JGroupsMessenger class, which implements the Messenger interface. We will create a new implementation of Messenger that uses TCP sockets, rather than JGroups and UDP sockets.
Our proposal for the new Messenger is to implement a TCP server and client using Netty. The Netty server and client will use the existing cluster SSL configuration. So if cluster SSL is enabled no additional properties will be required. See https://geode.apache.org/docs/guide/latest/managing/security/implementing_ssl.html for information on the relevant properties.
The host and port of this new TCP server socket need to be shared with other members. Currently, we distribute the jgroups UDP server port as part of the InternalDistributedMember. Those member ids are sent as part of view messages, which allow all members to discover the listening port of other members (see GMSJoinLeave message sequence diagrams). We propose adding a new port field to the InternalDistributedMember to keep track of this new port. (See the Rolling Upgrade section, below.)
The current Messenger interface is somewhat tied to geode specific group messaging. It has the concept of a view, and methods related to returning a QuorumChecker and performing a state flush. In order to separate out group membership from the messaging system, we will create a new module and a new interface for the messenger that is strictly focused on point to point messaging of geode objects - UnicastMessenger. This should also make it easier to swap out different messaging implementations if we want to experiment with them.
In order to support rolling upgrades, we are going to need to continue to run the old Messenger implementation that uses jgroups, until we drop support for old versions. Therefore, we will also need a BackwardsCompatibleMessenger that wraps the new Messenger and the JGroupsMessenger. The class diagram will look something like this:
PlantUML |
---|
@startuml
interface Messenger {
"Existing interface, has group messaging capabilities"
+ installView
+ start
+ send(MemberID, Message)
+ addHandler(Class, MessageHandler)
}
interface UnicastMessenger {
"Point to point messenger"
+ start(): Address
+ send(Address, Object message)
+ addHandler(Class, MessageHandler)
}
Messenger <|-- MessengerImpl
Messenger <|-- JGroupsMessenger
Messenger <|-- BackwardsCompatibleMessenger
BackwardsCompatibleMessenger *-- JGroupsMessenger
BackwardsCompatibleMessenger *-- MessengerImpl
MessengerImpl *-- UnicastMessenger
UnicastMessenger <|-- NettyUnicastMessenger
@enduml |
The NettyUnicastMessenger server socket will use the existing bind-address and membership-port-range properties to determine it's address and port.
The netty based messenger will maintain one connection to each peer. When sending a message the NettyUnicastMessenger messenger will create a connection to all destinations if no connection exists yet. Once a connection is established, the connection will remain open until the messenger is told to shut it down.
Messages dispatched from NettyUnicastMessenger received by the netty server will be dispatched from netty event loop threads. For this reason, it is important that message processing should not block, or it will prevent other messages from being received. The old JGroupsMessenger dispatched messages using a single jgroups dispatcher thread.receiver thread.
Backwards Compatibility and Upgrade Path
We need to be able to do a rolling upgrade from the old JGroups-based protocol to the new protocol. We will need to continue to support rolling upgrades for a certain range of versions before we can drop JGroups.
In order to accomplish this a member will actually need to be listening for connections on both protocols when it initially starts up. We will create a VersionAwareMessenger that contains both a JGroupsMessenger and a NettyMessenger. It can install handlers in both of them, and decide which Messenger to use when sending a message based on the version of the recipient. If a member receives a view that contains no old members that don't support the old protocol it could shut down the JGroups-based Messenger.
There is an issue here with the need to listen on two separate ports and distribute both ports to other members. Currently, we distribute the jgroups UDP server port as part of the InternalDistributedMember. Those member ids are sent as part of view messages, which allow all members to discover the listening port of other members (see GMSJoinLeave message sequence diagrams). We need to distribute the new port field as well. There are a couple options we are evaluating:
- Add another port field to InternalDistributedMember
- Pass the new membership port around outside of InternalDistributedMember. This would probably involve sending it part of the FindCoordinatorResponse, as well as including it in the GMSMembershipView.
For either of this options, we will need to version either InternalDistributedMember itself, or the FindCoordinatorResponse and GMSMembershipView classes. Old members will only receive the UDP port, newer members will receive both ports.
Handling TCP connection failures
...
- Reestablish a connection to the destination to if the existing TCP connection fails.
- Retransmit messages that may not have been received. Because more than one message can be in the TCP send buffer of the sender when a TCP connection fails, we need to retransmit some window of messages.
- Because we are retransmitting messages, we need include some sort of sequence number to prevent duplicate messages, and possibly also to deliver messages in order.
Possible options:
- Implement something akin to a TCP sliding window, with an increasing sequence number attached to each message and acknowledged by the receiver.
- Implement something like JGroups UNICAST3 protocol? https://github.com/belaban/JGroups/blob/master/doc/design/UNICAST3.txt. This is what the current membership layer is using.
- ???
- Prevent duplication of retransmitted messages on the receiver side
In order to accomplish these goals, we we implement a layer that attaches an increasing sequence number with each message, and save messages on the sender until their sequence numbers are acknowledged.
One concern about switching to a TCP-based protocol is that network outages may result in TCP sockets hanging on read or write operations. We need to ensure that, if a connection to one member is blocked, we still send messages to the other members. Each destination will have its own queue of messages to be sent, and adding to one queue should never block.
Changes and Additions to Public Interfaces
If you are proposing to add or modify public interfaces, those changes should be outlined here in detail.
Performance Impact
Do you anticipate the proposed changes to impact performance in any way? Are there plans to measure and/or mitigate the impact?
Backwards Compatibility and Upgrade Path
We need to be able to do a rolling upgrade from the old JGroups-based protocol to the new protocol. We will need to continue to support rolling upgrades for a certain range of versions before we can drop JGroups.
In order to accomplish this a member will actually need to be listening for connections on both protocols when it initially starts up. We will create a delegating Messenger that contains both a JGroupsMessenger and a NettyMessenger. It can install handlers in both of them, and decide which Messenger to use when sending a message based on the version of the recipient. If a member receives a view that contains no old members that don't support the old protocol it could shut down the JGroups-based Messenger.
There is an issue here with the need to listen on two separate ports, because InternalDistributedMember currently only has support for a single port field. There are a few options we are evaluating:
- Just use the same port for JGroups and Netty. Since one is a UDP port and the other is TCP port, they can both be open at the same time.
- Encode the second port in some other field in InternalDistributedMember, for example by using part of the UUID bytes. This is kind of hacky.
- Pass the new membership port around outside of InternalDistributedMember. This would probably involve sending as part of the FindCoordinatorResponse, as well as including it in the NetView.
Prior Art
Because we are getting rid of udp messaging, the following udp messaging related gemfire properties will be deprecated:
udp-fragment-size
udp-recv-buffer-size
udp-send-buffer-size
security-udp-dhalgo
mcast-address- mcast-ttl
- mcast-flow-control
- mcast-port
- mcast-recv-buffer-size
- mcast-send-buffer-size
- disable-tcp
Performance Impact
This proposal is only targeted at replacing the UDP messages used for membership events, which are fairly low traffic. Region operations like puts and gets go over separate TCP connections that are not going to be changed as part of this proposal. Therefore we don't anticipate any performance impact for region operations.
In the future we could consider switching all peer-to-peer messages to flow through this new TCP messaging system. We would only do that if the new system has similar or better performance than the old system.
Rejected Alternatives
Use DTLS
One option to address concerns with using custom encryption protocol would be to continue using jgroups, but remove our old security-udp-dhalgo property in favor of using DTLS. However, this approach is complicated by the fact the the JDK does not have DTLS support built in to Java 8, which would require us to backport and maintain an implementation. In addition, this would not help us fix the problem of being tied to an outdated jgroups stack that cannot be upgraded.
Use the existing P2P tcp socket code
One the face of it, just using our existing TCP sockets for membership messages as well seems attractive. However, this code as it is written is dependent on the membership system to bootstrap itself. For example, it will not even send messages until the member has completely joined and some startup messages are exchanged. It would take some refactoring to be able to send membership messages over this system in order to bootstrap membership. The existing P2P socket code is also fairly old, and we feel a better path forward is to move towards a new system based on netty that is less entangled with the rest of the system.
Use a third party messaging system
Aeron, rsocket, grpc, ??What would be the alternatives to the proposed solution? What would happen if we don’t solve the problem? Why should this proposal be preferred?
FAQ
Answers to questions you’ve commonly been asked after requesting comments for this proposal.
...