How to get JGroups to make node a coordinator?

I’m looking for a way to get JGroups to use a specific server as the Coordinator, and if this server is not there, select the new Coordinator until it indicates that it is joining the cluster and it becomes the coordinator.

In this case, we have some information that we bring to the cluster by the Coordinator, who listens for updates, but extracting and processing these updates can be resource-intensive, so we don’t want something outside the World on the server. Therefore, in the load balancer in front of the cluster, we configured it not to send to the coordinator. But since the coordinator is randomly selected, we basically need to disconnect the cluster until only one machine remains, and then run a backup of the rest of the cluster.

+4
source share
3 answers

There is currently no way to do this. Jgroups spent considerable time ensuring that the coordinator could be any of the nodes in the group. All tasks that support and control the health of the list of group members are distributed among all group members to make sure that the responsibilities of the coordinator do not affect the performance of the coordinator. The standard class of the GMS protocol stack (Group MembershipService) is what is responsible for choosing a coordinator. This is currently just the first node on the watch list.

To get this behavior, you will have to implement your own protocol stack. Interestingly, I was working on a protocol stack for Jgroups that implements something you ask for, but it is not ready for prime time.

Others may have cracked this question. I would recommend posting to the jgroups mailing list and asking the same question.

+5
source

You can set the desired node coordinator .: github example

And I add a sync block for all changes and all codes:

public static final String GMS_DELTA_VIEW_FIELD_NAME = "use_delta_views"; /** * Change coordinator to {@code desiredCoordinator}. Must be invoked from coordinator. * @param desiredCoordinator * @return {@code true} if changes success, {@code false} overwise */ boolean changeCoordinator(JChannel currentChannel, Address desiredCoordinator) { if(!Util.isCoordinator(currentChannel.getAddress)) { throw new RuntimeException("The current node is not coordinator."); } ArrayList<Address> newMembersOrder = Lists.newArrayList(currentView.getMembers()); // Switch desired node to first place Collections.swap(newMembersOrder, 0, newMembersOrder.indexOf(desiredCoordinator)); // Create new view long newId = currentView.getViewId().getId() + 1; View newView = new View(newMembersOrder.get(0), newId, newMembersOrder); GMS gms = (GMS)clusterChannel.getProtocolStack().findProtocol(GMS.class); CustomProtocol protocol = new CustomProtocol(newMembersOrder.stream() .filter(item -> !item.equals(currentChannel.getAddress())) .collect(Collectors.toSet())); boolean oldUseDeltaViews = (Boolean)gms.getValue(GMS_DELTA_VIEW_FIELD_NAME); try { // Disable using_delta_views at GMS gms.setValue(GMS_DELTA_VIEW_FIELD_NAME, false); // Insert custom protocol below GMS for synchronizing with VIEW_ACK events currentChannel.getProtocolStack().insertProtocolInStack(protocol, gms, ProtocolStack.BELOW); gms.castViewChange(newView, null, newMembersOrder); // Wait no more than 30 seconds to all VIEW_ACK responses if (!protocol.collector.waitForAllAcks(TimeUnit.SECONDS.toMillis(30))) { return false; } return true; } finally { // Repair old state gms.setValue(GMS_DELTA_VIEW_FIELD_NAME, oldUseDeltaViews); currentChannel.getProtocolStack().removeProtocol(protocol); } } private class CustomProtocol extends Protocol implements UpHandler { AckCollector collector; public CustomProtocol(Collection<Address> waitedAddresses) { collector = new AckCollector(waitedAddresses); } @Override public Object up(Event evt) { if(evt.getType() == Event.MSG) { final Message msg=(Message)evt.getArg(); GmsHeader hdr=(GmsHeader)msg.getHeader(proto_id); if(hdr != null && hdr.getType() == GmsHeader.VIEW_ACK) { collector.ack(msg.getSrc()); } } return super.up(evt); } } 
0
source

Just stumbled upon this post. There is a simple and standard way to do this in JGroups: [1]. This essentially allows the user code to control the generation of the view.

[1] http://www.jgroups.org/manual4/index.html#MembershipChangePolicy

0
source

Source: https://habr.com/ru/post/1415476/


All Articles