Skip to content

Commit 380c2ca

Browse files
committed
XWIKI-23613: When using udp configuration it takes a long time to notice a cluster member went down
1 parent 9768c9e commit 380c2ca

File tree

1 file changed

+24
-4
lines changed
  • xwiki-platform-core/xwiki-platform-observation/xwiki-platform-observation-remote/src/main/java/org/xwiki/observation/remote/internal/jgroups

1 file changed

+24
-4
lines changed

xwiki-platform-core/xwiki-platform-observation/xwiki-platform-observation-remote/src/main/java/org/xwiki/observation/remote/internal/jgroups/JGroupsNetworkChannel.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.jgroups.JChannel;
3838
import org.jgroups.Message;
3939
import org.jgroups.ObjectMessage;
40+
import org.jgroups.Receiver;
41+
import org.jgroups.View;
4042
import org.jgroups.blocks.MessageDispatcher;
4143
import org.jgroups.blocks.RequestHandler;
4244
import org.jgroups.blocks.RequestOptions;
@@ -70,7 +72,7 @@
7072
// It's unfortunately not so easy to reduce the class fan out complexity (which is currently just above the accepted
7173
// threshold)
7274
@SuppressWarnings("checkstyle:ClassFanOutComplexity")
73-
public class JGroupsNetworkChannel implements NetworkChannel
75+
public class JGroupsNetworkChannel implements NetworkChannel, Receiver
7476
{
7577
/**
7678
* Relative path where to find JGroups channels configurations.
@@ -170,6 +172,7 @@ public void start(String id) throws Exception
170172

171173
// Register the member handler dispatcher
172174
this.memberIdDispatcher = new MessageDispatcher(this.jchannel, new JGroupsMemberHandler());
175+
this.memberIdDispatcher.setReceiver(this);
173176

174177
// Start the channel
175178
this.jchannel.connect("event");
@@ -192,15 +195,15 @@ public void start(String id) throws Exception
192195
this.members =
193196
Map.of(currentMemberId, new JGroupsNetworkMember(this, currentMemberId, this.jchannel.getAddress()));
194197

195-
// Send the to other members and wait for their ids in response (wait for 1min max).
198+
// Send the message to other members and wait for their ids in response (wait for 1min max).
196199
RspList<String> responses = this.memberIdDispatcher.castMessage(null, new ObjectMessage(null, currentMemberId),
197200
new RequestOptions(ResponseMode.GET_ALL, 60000));
198201
for (Map.Entry<Address, Rsp<String>> response : responses.entrySet()) {
199202
this.membersIdMap.put(response.getKey().toString(), response.getValue().getValue());
200203
}
201204

202205
// Initialize the channel
203-
// It's actually the second time that #onViewChanged is called, but the first time we did not had enough
206+
// It's actually the second time that #updateMembers is called, but the first time we did not had enough
204207
// information for it to do much
205208
updateMembers(false);
206209
}
@@ -297,7 +300,24 @@ public void send(Message message) throws Exception
297300
this.memberIdDispatcher.castMessage(null, new ObjectMessage(null, message), RequestOptions.ASYNC());
298301
}
299302

300-
private void updateMembers(boolean notifyChanges)
303+
@Override
304+
public void viewAccepted(View view)
305+
{
306+
if (this.membersIdMap == null) {
307+
// Not ready
308+
return;
309+
}
310+
311+
// Check if a member has been removed
312+
for (JGroupsNetworkMember member : this.members.values()) {
313+
if (!this.jchannel.getView().containsMember(member.getAddress())) {
314+
// At least one member left, update the members cache
315+
updateMembers(true);
316+
}
317+
}
318+
}
319+
320+
private synchronized void updateMembers(boolean notifyChanges)
301321
{
302322
if (this.membersIdMap == null) {
303323
// Not ready

0 commit comments

Comments
 (0)