From 69deb04413941ae6a418bda9eee03e9e7b7535b8 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Tue, 27 Apr 2021 13:48:49 +0200 Subject: Exclude current sources when all sources are unhealthy When choosing a new source when all are unhealthy exclude the current source. Minor changes to toString for JRTConnection --- .../java/com/yahoo/vespa/config/JRTConnection.java | 9 +++------ .../com/yahoo/vespa/config/JRTConnectionPool.java | 20 +++++++++----------- 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'config/src/main') diff --git a/config/src/main/java/com/yahoo/vespa/config/JRTConnection.java b/config/src/main/java/com/yahoo/vespa/config/JRTConnection.java index 52031ebde72..0d5f483ad2c 100644 --- a/config/src/main/java/com/yahoo/vespa/config/JRTConnection.java +++ b/config/src/main/java/com/yahoo/vespa/config/JRTConnection.java @@ -79,17 +79,14 @@ public class JRTConnection implements Connection { public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("Address: "); sb.append(address); - sb.append("\n").append("Healthy: ").append(isHealthy()); + sb.append(", ").append(isHealthy() ? "healthy" : "unhealthy"); if (lastSuccess.isAfter(Instant.EPOCH)) { - sb.append("\n"); - sb.append("Last success: "); + sb.append(", last success: "); sb.append(lastSuccess); } if (lastFailure.isAfter(Instant.EPOCH)) { - sb.append("\n"); - sb.append("Last failure: "); + sb.append(", last failure: "); sb.append(lastFailure); } return sb.toString(); diff --git a/config/src/main/java/com/yahoo/vespa/config/JRTConnectionPool.java b/config/src/main/java/com/yahoo/vespa/config/JRTConnectionPool.java index 801cdc868e1..019103c7015 100644 --- a/config/src/main/java/com/yahoo/vespa/config/JRTConnectionPool.java +++ b/config/src/main/java/com/yahoo/vespa/config/JRTConnectionPool.java @@ -19,7 +19,7 @@ import java.util.stream.Collectors; * The current connection is chosen randomly when calling {#link {@link #switchConnection()}} * (it will continue to use the same connection if there is only one source). * The current connection is available with {@link #getCurrent()}. - * When calling {@link #setError(Connection, int)}, {#link {@link #switchConnection()}} will always be called. + * When calling {@link #setError(Connection, int)}, {@link #switchConnection()} will always be called. * * @author Gunnar Gauslaa Bergem * @author hmusum @@ -53,7 +53,7 @@ public class JRTConnectionPool implements ConnectionPool { connections.put(address, new JRTConnection(address, supervisor)); } } - initialize(); + currentConnection = initialize(); } /** @@ -70,23 +70,21 @@ public class JRTConnectionPool implements ConnectionPool { List sources = getSources(); if (sources.size() <= 1) return currentConnection; - List healthySources = sources.stream() + List sourceCandidates = sources.stream() .filter(JRTConnection::isHealthy) .collect(Collectors.toList()); - if (healthySources.size() == 0) { - log.log(Level.INFO, "No healthy sources, keep using " + currentConnection); - return currentConnection; + JRTConnection newConnection; + if (sourceCandidates.size() == 0) { + sourceCandidates = getSources(); + sourceCandidates.remove(currentConnection); } - JRTConnection newConnection = pickNewConnectionRandomly(healthySources); + newConnection = pickNewConnectionRandomly(sourceCandidates); log.log(Level.INFO, () -> "Switching from " + currentConnection + " to " + newConnection); return currentConnection = newConnection; } public synchronized JRTConnection initialize() { - List sources = getSources(); - currentConnection = pickNewConnectionRandomly(sources); - log.log(Level.INFO, () -> "Choosing new connection: " + currentConnection); - return currentConnection; + return pickNewConnectionRandomly(getSources()); } private JRTConnection pickNewConnectionRandomly(List sources) { -- cgit v1.2.3