summaryrefslogtreecommitdiffstats
path: root/config-proxy
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-02-21 11:29:28 +0100
committerHarald Musum <musum@verizonmedia.com>2020-02-21 11:29:28 +0100
commit25a3eb4ce927bd5ea1225bfb77b69ce3512b0647 (patch)
tree5b60d0a5480465efdd8ab561d756ea15918bb4e3 /config-proxy
parent25bcc44fcf22a5e4737d6d4551b4a292bc04d4e0 (diff)
Move timing values into RpcConfigSourceClient
Diffstat (limited to 'config-proxy')
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java43
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java19
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java3
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java4
4 files changed, 23 insertions, 46 deletions
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java
index 0966de940f1..72c8db28b21 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java
@@ -10,7 +10,6 @@ import com.yahoo.log.LogLevel;
import com.yahoo.log.LogSetup;
import com.yahoo.log.event.Event;
import com.yahoo.vespa.config.RawConfig;
-import com.yahoo.vespa.config.TimingValues;
import com.yahoo.vespa.config.protocol.JRTServerConfigRequest;
import com.yahoo.vespa.config.proxy.filedistribution.FileDistributionAndUrlDownload;
import com.yahoo.yolean.system.CatchSignals;
@@ -52,35 +51,22 @@ public class ProxyServer implements Runnable {
private volatile ConfigSourceClient configClient;
- private final TimingValues timingValues;
private final MemoryCache memoryCache;
- private static final double timingValuesRatio = 0.8;
- private final static TimingValues defaultTimingValues;
private final FileDistributionAndUrlDownload fileDistributionAndUrlDownload;
private volatile Mode mode = new Mode(DEFAULT);
- static {
- // Proxy should time out before clients upon subscription.
- TimingValues tv = new TimingValues();
- tv.setUnconfiguredDelay((long)(tv.getUnconfiguredDelay()* timingValuesRatio)).
- setConfiguredErrorDelay((long)(tv.getConfiguredErrorDelay()* timingValuesRatio)).
- setSubscribeTimeout((long)(tv.getSubscribeTimeout()* timingValuesRatio)).
- setConfiguredErrorTimeout(-1); // Never cache errors
- defaultTimingValues = tv;
- }
-
ProxyServer(Spec spec, ConfigSourceSet source, MemoryCache memoryCache, ConfigSourceClient configClient) {
this.delayedResponses = new DelayedResponses();
this.configSource = source;
log.log(LogLevel.DEBUG, "Using config source '" + source);
- this.timingValues = defaultTimingValues;
this.memoryCache = memoryCache;
this.rpcServer = createRpcServer(spec);
- this.configClient = createClient(rpcServer, delayedResponses, source, timingValues, memoryCache, configClient);
+ this.configClient = (configClient == null) ? createRpcClient(rpcServer, delayedResponses, source, memoryCache) : configClient;
this.fileDistributionAndUrlDownload = new FileDistributionAndUrlDownload(supervisor, source);
}
+ @Override
public void run() {
if (rpcServer != null) {
Thread t = new Thread(rpcServer);
@@ -123,7 +109,7 @@ public class ProxyServer implements Runnable {
break;
case DEFAULT:
flush();
- configClient = createRpcClient();
+ configClient = createRpcClient(rpcServer, delayedResponses, configSource, memoryCache);
this.mode = new Mode(modeName);
break;
default:
@@ -132,20 +118,13 @@ public class ProxyServer implements Runnable {
log.log(LogLevel.INFO, "Switched from '" + oldMode.name().toLowerCase() + "' mode to '" + getMode().name().toLowerCase() + "' mode");
}
- private ConfigSourceClient createClient(RpcServer rpcServer, DelayedResponses delayedResponses,
- ConfigSourceSet source, TimingValues timingValues,
- MemoryCache memoryCache, ConfigSourceClient client) {
- return (client == null)
- ? new RpcConfigSourceClient(rpcServer, source, memoryCache, timingValues, delayedResponses)
- : client;
- }
-
private ConfigProxyRpcServer createRpcServer(Spec spec) {
return (spec == null) ? null : new ConfigProxyRpcServer(this, supervisor, spec); // TODO: Try to avoid first argument being 'this'
}
- private RpcConfigSourceClient createRpcClient() {
- return new RpcConfigSourceClient(rpcServer, configSource, memoryCache, timingValues, delayedResponses);
+ private RpcConfigSourceClient createRpcClient(RpcServer rpcServer, DelayedResponses delayedResponses,
+ ConfigSourceSet source, MemoryCache memoryCache) {
+ return new RpcConfigSourceClient(rpcServer, source, memoryCache, delayedResponses);
}
private void setupSignalHandler() {
@@ -202,14 +181,6 @@ public class ProxyServer implements Runnable {
}
}
- static TimingValues defaultTimingValues() {
- return defaultTimingValues;
- }
-
- TimingValues getTimingValues() {
- return timingValues;
- }
-
// Cancels all config instances and flushes the cache. When this method returns,
// the cache will not be updated again before someone calls getConfig().
private synchronized void flush() {
@@ -240,7 +211,7 @@ public class ProxyServer implements Runnable {
void updateSourceConnections(List<String> sources) {
configSource = new ConfigSourceSet(sources);
flush();
- configClient = createRpcClient();
+ configClient = createRpcClient(rpcServer, delayedResponses, configSource, memoryCache);
}
}
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java
index 47afbe83bb6..a674a43be8d 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java
@@ -32,6 +32,8 @@ import java.util.logging.Logger;
class RpcConfigSourceClient implements ConfigSourceClient {
private final static Logger log = Logger.getLogger(RpcConfigSourceClient.class.getName());
+ private static final double timingValuesRatio = 0.8;
+
private final Supervisor supervisor = new Supervisor(new Transport());
private final RpcServer rpcServer;
@@ -40,22 +42,29 @@ class RpcConfigSourceClient implements ConfigSourceClient {
private final Object activeSubscribersLock = new Object();
private final MemoryCache memoryCache;
private final DelayedResponses delayedResponses;
- private final TimingValues timingValues;
+ private final static TimingValues timingValues;
private final ExecutorService exec;
private final JRTConfigRequester requester;
+ static {
+ // Proxy should time out before clients upon subscription.
+ TimingValues tv = new TimingValues();
+ tv.setUnconfiguredDelay((long)(tv.getUnconfiguredDelay()* timingValuesRatio)).
+ setConfiguredErrorDelay((long)(tv.getConfiguredErrorDelay()* timingValuesRatio)).
+ setSubscribeTimeout((long)(tv.getSubscribeTimeout()* timingValuesRatio)).
+ setConfiguredErrorTimeout(-1); // Never cache errors
+ timingValues = tv;
+ }
RpcConfigSourceClient(RpcServer rpcServer,
ConfigSourceSet configSourceSet,
MemoryCache memoryCache,
- TimingValues timingValues,
DelayedResponses delayedResponses) {
this.rpcServer = rpcServer;
this.configSourceSet = configSourceSet;
this.memoryCache = memoryCache;
this.delayedResponses = delayedResponses;
- this.timingValues = timingValues;
checkConfigSources();
exec = Executors.newCachedThreadPool(new DaemonThreadFactory("subscriber-"));
requester = JRTConfigRequester.create(configSourceSet, timingValues);
@@ -140,8 +149,8 @@ class RpcConfigSourceClient implements ConfigSourceClient {
log.log(LogLevel.DEBUG, () -> "Already a subscriber running for: " + configCacheKey);
} else {
log.log(LogLevel.DEBUG, () -> "Could not find good config in cache, creating subscriber for: " + configCacheKey);
- UpstreamConfigSubscriber subscriber = new UpstreamConfigSubscriber(input, this, configSourceSet,
- timingValues, requester, memoryCache);
+ UpstreamConfigSubscriber subscriber =
+ new UpstreamConfigSubscriber(input, this, configSourceSet, timingValues, requester, memoryCache);
try {
subscriber.subscribe();
activeSubscribers.put(configCacheKey, subscriber);
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java
index bc35a8670a3..f52598b3ee5 100644
--- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java
+++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java
@@ -27,7 +27,7 @@ public class ProxyServerTest {
private final MemoryCache memoryCache = new MemoryCache();
private final MockConfigSource source = new MockConfigSource();
- private MockConfigSourceClient client = new MockConfigSourceClient(source, memoryCache);
+ private final MockConfigSourceClient client = new MockConfigSourceClient(source, memoryCache);
private ProxyServer proxy;
static final RawConfig fooConfig = ConfigTester.fooConfig;
@@ -58,7 +58,6 @@ public class ProxyServerTest {
public void basic() {
assertTrue(proxy.getMode().isDefault());
assertThat(proxy.getMemoryCache().size(), is(0));
- assertThat(proxy.getTimingValues(), is(ProxyServer.defaultTimingValues()));
ConfigTester tester = new ConfigTester();
final MemoryCache memoryCache = proxy.getMemoryCache();
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java
index 35f1dd8fcd8..f3e79f8118d 100644
--- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java
+++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClientTest.java
@@ -29,9 +29,7 @@ public class RpcConfigSourceClientTest {
public void setup() {
rpcServer = new MockRpcServer();
delayedResponses = new DelayedResponses();
- rpcConfigSourceClient =
- new RpcConfigSourceClient(rpcServer, new MockConfigSource(),
- new MemoryCache(), ProxyServer.defaultTimingValues(), delayedResponses);
+ rpcConfigSourceClient = new RpcConfigSourceClient(rpcServer, new MockConfigSource(), new MemoryCache(), delayedResponses);
}
@Test