summaryrefslogtreecommitdiffstats
path: root/config/src
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-04-28 10:15:21 +0200
committerHarald Musum <musum@verizonmedia.com>2021-04-28 10:15:21 +0200
commit7b3f38ea06998f42ad7e3bed428b6b2eb1271e49 (patch)
tree6a581da0b2b5e4a7784c1dc06688c817e9464984 /config/src
parent04a5db19b3e8ef8f27e441e3c4676b64cc223c8e (diff)
Simplify code
Add equals and hashcode to JRTConnection Just switch to a new one if current connection is failing Removes need for last sucess, error etc. and healthy status
Diffstat (limited to 'config/src')
-rw-r--r--config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java1
-rw-r--r--config/src/main/java/com/yahoo/config/subscription/impl/MockConnection.java19
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/Connection.java7
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/JRTConnection.java39
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/JRTConnectionPool.java11
-rw-r--r--config/src/test/java/com/yahoo/config/subscription/impl/JRTConfigRequesterTest.java1
-rw-r--r--config/src/test/java/com/yahoo/vespa/config/JRTConnectionPoolTest.java3
7 files changed, 17 insertions, 64 deletions
diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java b/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java
index f846231ac98..efb93c6aed2 100644
--- a/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java
+++ b/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java
@@ -234,7 +234,6 @@ public class JRTConfigRequester implements RequestWaiter {
fatalFailures = 0;
transientFailures = 0;
noApplicationWarningLogged = Instant.MIN;
- connection.setSuccess();
sub.setLastCallBackOKTS(Instant.now());
log.log(FINE, () -> "OK response received in handleOkRequest: " + jrtReq);
if (jrtReq.hasUpdatedGeneration()) {
diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/MockConnection.java b/config/src/main/java/com/yahoo/config/subscription/impl/MockConnection.java
index c234fdda32c..bed7a0fa3c4 100644
--- a/config/src/main/java/com/yahoo/config/subscription/impl/MockConnection.java
+++ b/config/src/main/java/com/yahoo/config/subscription/impl/MockConnection.java
@@ -22,11 +22,6 @@ public class MockConnection implements ConnectionPool, Connection {
private final ResponseHandler responseHandler;
private int numberOfRequests = 0;
- public int getNumberOfFailovers() {
- return numberOfFailovers;
- }
-
- private int numberOfFailovers = 0;
private final int numSpecs;
public MockConnection() {
@@ -59,16 +54,6 @@ public class MockConnection implements ConnectionPool, Connection {
}
@Override
- public void setError(int errorCode) {
- numberOfFailovers++;
- }
-
- @Override
- public void setSuccess() {
- numberOfFailovers = 0;
- }
-
- @Override
public String getAddress() {
return null;
}
@@ -77,9 +62,7 @@ public class MockConnection implements ConnectionPool, Connection {
public void close() {}
@Override
- public void setError(Connection connection, int errorCode) {
- connection.setError(errorCode);
- }
+ public void setError(Connection connection, int errorCode) { }
@Override
public Connection getCurrent() {
diff --git a/config/src/main/java/com/yahoo/vespa/config/Connection.java b/config/src/main/java/com/yahoo/vespa/config/Connection.java
index e39175a3a78..f10fbc487bd 100644
--- a/config/src/main/java/com/yahoo/vespa/config/Connection.java
+++ b/config/src/main/java/com/yahoo/vespa/config/Connection.java
@@ -1,4 +1,4 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config;
import com.yahoo.jrt.Request;
@@ -13,9 +13,6 @@ public interface Connection {
void invokeSync(Request request, double jrtTimeout);
- void setError(int errorCode);
-
- void setSuccess();
-
String getAddress();
+
}
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 0d5f483ad2c..f6352204d4b 100644
--- a/config/src/main/java/com/yahoo/vespa/config/JRTConnection.java
+++ b/config/src/main/java/com/yahoo/vespa/config/JRTConnection.java
@@ -7,8 +7,7 @@ import com.yahoo.jrt.Spec;
import com.yahoo.jrt.Supervisor;
import com.yahoo.jrt.Target;
-import java.time.Duration;
-import java.time.Instant;
+import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -25,10 +24,6 @@ public class JRTConnection implements Connection {
private final Supervisor supervisor;
private Target target;
- private Instant lastConnected = Instant.EPOCH.plus(Duration.ofSeconds(1)); // to be healthy initially, see isHealthy()
- private Instant lastSuccess = Instant.EPOCH;
- private Instant lastFailure = Instant.EPOCH;
-
public JRTConnection(String address, Supervisor supervisor) {
this.address = address;
this.supervisor = supervisor;
@@ -58,38 +53,26 @@ public class JRTConnection implements Connection {
if (target == null || !target.isValid()) {
logger.log(Level.INFO, "Connecting to " + address);
target = supervisor.connect(new Spec(address));
- lastConnected = Instant.now();
}
return target;
}
@Override
- public synchronized void setError(int errorCode) {
- lastFailure = Instant.now();
+ public String toString() {
+ return address;
}
@Override
- public synchronized void setSuccess() {
- lastSuccess = Instant.now();
- }
-
- public synchronized boolean isHealthy() {
- return lastSuccess.isAfter(lastFailure) || lastConnected.isAfter(lastFailure);
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ JRTConnection that = (JRTConnection) o;
+ return address.equals(that.address);
}
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(address);
- sb.append(", ").append(isHealthy() ? "healthy" : "unhealthy");
- if (lastSuccess.isAfter(Instant.EPOCH)) {
- sb.append(", last success: ");
- sb.append(lastSuccess);
- }
- if (lastFailure.isAfter(Instant.EPOCH)) {
- sb.append(", last failure: ");
- sb.append(lastFailure);
- }
- return sb.toString();
+ @Override
+ public int hashCode() {
+ return Objects.hash(address);
}
}
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 cc005a54054..26eafb67c1b 100644
--- a/config/src/main/java/com/yahoo/vespa/config/JRTConnectionPool.java
+++ b/config/src/main/java/com/yahoo/vespa/config/JRTConnectionPool.java
@@ -12,7 +12,6 @@ import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Collectors;
/**
* A pool of JRT connections to a config source (either a config server or a config proxy).
@@ -83,13 +82,8 @@ public class JRTConnectionPool implements ConnectionPool {
synchronized JRTConnection switchConnection() {
if (getSources().size() <= 1) throw new IllegalStateException("Cannot switch connection, not enough sources");
- List<JRTConnection> sourceCandidates = getSources().stream()
- .filter(JRTConnection::isHealthy)
- .collect(Collectors.toList());
- if (sourceCandidates.size() == 0) {
- sourceCandidates = getSources();
- sourceCandidates.remove(currentConnection);
- }
+ List<JRTConnection> sourceCandidates = getSources();
+ sourceCandidates.remove(currentConnection);
JRTConnection newConnection = pickNewConnectionRandomly(sourceCandidates);
log.log(Level.INFO, () -> "Switching from " + currentConnection + " to " + newConnection);
return currentConnection = newConnection;
@@ -117,7 +111,6 @@ public class JRTConnectionPool implements ConnectionPool {
@Override
public void setError(Connection connection, int errorCode) {
- connection.setError(errorCode);
switchConnection(connection);
}
diff --git a/config/src/test/java/com/yahoo/config/subscription/impl/JRTConfigRequesterTest.java b/config/src/test/java/com/yahoo/config/subscription/impl/JRTConfigRequesterTest.java
index 4211345dff7..1b56e9290b2 100644
--- a/config/src/test/java/com/yahoo/config/subscription/impl/JRTConfigRequesterTest.java
+++ b/config/src/test/java/com/yahoo/config/subscription/impl/JRTConfigRequesterTest.java
@@ -277,7 +277,6 @@ public class JRTConfigRequesterTest {
} catch (InterruptedException e) {
e.printStackTrace();
}
- assertTrue(connection.getNumberOfFailovers() >= 1);
}
private JRTConfigSubscription<SimpletypesConfig> createSubscription(ConfigSubscriber subscriber, TimingValues timingValues) {
diff --git a/config/src/test/java/com/yahoo/vespa/config/JRTConnectionPoolTest.java b/config/src/test/java/com/yahoo/vespa/config/JRTConnectionPoolTest.java
index 8bd88d8958f..bfe132c9660 100644
--- a/config/src/test/java/com/yahoo/vespa/config/JRTConnectionPoolTest.java
+++ b/config/src/test/java/com/yahoo/vespa/config/JRTConnectionPoolTest.java
@@ -139,14 +139,13 @@ public class JRTConnectionPoolTest {
JRTConnection secondConnection = failAndGetNewConnection(connectionPool, firstConnection);
assertNotEquals(firstConnection, secondConnection);
- // Should change connection, , not getting first or seconds connection as new
+ // Should change connection, not getting second connection as new
JRTConnection thirdConnection = failAndGetNewConnection(connectionPool, secondConnection);
// Fail a few more times with old connection, as will happen when there are multiple subscribers
// Connection should not change
assertEquals(thirdConnection, failAndGetNewConnection(connectionPool, secondConnection));
assertEquals(thirdConnection, failAndGetNewConnection(connectionPool, secondConnection));
assertEquals(thirdConnection, failAndGetNewConnection(connectionPool, secondConnection));
- assertNotEquals(firstConnection, thirdConnection);
assertNotEquals(secondConnection, thirdConnection);
// Should change connection, not getting third connection as new