Skip to content

Commit

Permalink
Fix broken order in seed node selection logic in case of network time…
Browse files Browse the repository at this point in the history
…outs
  • Loading branch information
syermakov committed May 12, 2022
1 parent b6b2539 commit fcd728a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private enum Status {

RETRY,

TIMEOUT,

FAILED,

BAN
Expand Down Expand Up @@ -211,7 +213,7 @@ public void onFailure(InetSocketAddress seed, Throwable cause) {
log.warn("Seed node timeout ...will retry [address={}, cause={}]", s.address(), String.valueOf(cause));
}

s.updateStatus(Status.RETRY);
s.updateStatus(Status.TIMEOUT);
} else {
if (log.isWarnEnabled()) {
log.warn("Couldn't contact seed node [address={}, cause={}]", s.address(), String.valueOf(cause));
Expand All @@ -235,7 +237,9 @@ public void onBan(InetSocketAddress seed) {
}

private boolean triedAllNodes() {
return seeds.stream().allMatch(s -> s.address().equals(localAddress) || s.status() != Status.NEW);
return seeds.stream().allMatch(s ->
s.address().equals(localAddress) || (s.status() != Status.NEW && s.status() != Status.TIMEOUT)
);
}

private boolean isNetworkTimeout(Throwable cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.hekate.cluster.internal.gossip;

import io.hekate.HekateTestBase;
import io.hekate.network.NetworkConnectTimeoutException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -58,6 +59,30 @@ public void testNextSeed() throws Exception {
});
}

@Test
public void testOrderOnNetworkTimeout() throws Exception {
List<InetSocketAddress> seeds = new ArrayList<>();

seeds.add(newSocketAddress(100));
seeds.add(newSocketAddress(200));
seeds.add(newSocketAddress(300));

for (int localPort = 0; localPort <= 303; localPort += 101) {
say("Local port: " + localPort);

GossipSeedNodesSate s = new GossipSeedNodesSate(newSocketAddress(localPort), seeds, false);

repeat(3, i ->
seeds.forEach(seed -> {
assertFalse(s.isSelfJoin());
assertEquals(seed, s.nextSeed(false));

s.onFailure(seed, new NetworkConnectTimeoutException(TEST_ERROR.getMessage()));
})
);
}
}

@Test
public void testNextSeedBusy() throws Exception {
List<InetSocketAddress> seeds = new ArrayList<>();
Expand Down

0 comments on commit fcd728a

Please sign in to comment.