diff --git a/cluster2/src/main/java/io/scalecube/cluster2/AbstractAgent.java b/cluster2/src/main/java/io/scalecube/cluster2/AbstractAgent.java index e0e21333..31486071 100644 --- a/cluster2/src/main/java/io/scalecube/cluster2/AbstractAgent.java +++ b/cluster2/src/main/java/io/scalecube/cluster2/AbstractAgent.java @@ -46,7 +46,7 @@ public int doWork() { workCount += pollMessage(); workCount += receiveMessage(); workCount += processTick(); - workCount += callbackInvoker.doWork(); + workCount += callbackInvoker != null ? callbackInvoker.doWork() : 0; return workCount; } diff --git a/cluster2/src/main/java/io/scalecube/cluster2/fdetector/FailureDetector.java b/cluster2/src/main/java/io/scalecube/cluster2/fdetector/FailureDetector.java index 132521d5..358476fc 100644 --- a/cluster2/src/main/java/io/scalecube/cluster2/fdetector/FailureDetector.java +++ b/cluster2/src/main/java/io/scalecube/cluster2/fdetector/FailureDetector.java @@ -289,9 +289,12 @@ Member nextPingMember() { return null; } - final int i = index == size ? index = 0 : index++; - if (i == 0) { + final int i; + if (index >= size) { + i = index = 0; shuffle(); + } else { + i = index++; } return pingMembers.get(i); diff --git a/cluster2/src/main/java/io/scalecube/cluster2/gossip/GossipProtocol.java b/cluster2/src/main/java/io/scalecube/cluster2/gossip/GossipProtocol.java index ed57f7b3..58cc2603 100644 --- a/cluster2/src/main/java/io/scalecube/cluster2/gossip/GossipProtocol.java +++ b/cluster2/src/main/java/io/scalecube/cluster2/gossip/GossipProtocol.java @@ -294,13 +294,26 @@ void nextGossipMembers() { return; } - // for (int i = 0, limit = Math.min(gossipFanout, size); i < limit; ) { - // final Member member = remoteMembers.get(random.nextInt(remoteMembers.size())); - // if (!gossipMembers.contains(member)) { - // gossipMembers.add(member); - // i++; - // } - // } + if (size <= gossipFanout) { + shuffle(); + for (int i = 0; i < size; i++) { + gossipMembers.add(remoteMembers.get(i)); + } + return; + } + + final int step = gossipFanout; + final int limit = step * (size / step); + final int nextLimit = index + step; + + if (nextLimit >= limit) { + index = 0; + shuffle(); + } + + for (; index < nextLimit; index++) { + gossipMembers.add(remoteMembers.get(index)); + } } void shuffle() {