diff options
author | Harald Musum <musum@yahoo-inc.com> | 2017-07-14 09:56:58 +0200 |
---|---|---|
committer | Harald Musum <musum@yahoo-inc.com> | 2017-07-14 09:56:58 +0200 |
commit | 30085a22a570adb346fcc818105424377ef5bc26 (patch) | |
tree | 1d8ebbc7cfc084a9320bdb815df6d58d9e1a0b17 /config-proxy/src | |
parent | 7a4a2f2d55d309601e6fd24b54c4121cdc16ab5f (diff) |
Move code that puts config in cache
Diffstat (limited to 'config-proxy/src')
10 files changed, 27 insertions, 78 deletions
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ClientUpdater.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ClientUpdater.java index 5306e58a9f4..dd1f0d36abd 100644 --- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ClientUpdater.java +++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ClientUpdater.java @@ -10,51 +10,36 @@ import java.util.logging.Logger; /** * Updates clients subscribing to config when config changes or the - * timeout they have specified has elapsed. + * timeout they have specified has elapsed. Not used when in 'memorycache' mode. * * @author hmusum */ class ClientUpdater { private final static Logger log = Logger.getLogger(ClientUpdater.class.getName()); - private final MemoryCache memoryCache; private final ConfigProxyStatistics statistics; private final RpcServer rpcServer; private final DelayedResponses delayedResponses; - private final Mode mode; - ClientUpdater(MemoryCache memoryCache, - RpcServer rpcServer, + ClientUpdater(RpcServer rpcServer, ConfigProxyStatistics statistics, - DelayedResponses delayedResponses, - Mode mode) { - this.memoryCache = memoryCache; + DelayedResponses delayedResponses) { this.rpcServer = rpcServer; this.statistics = statistics; this.delayedResponses = delayedResponses; - this.mode = mode; } /** * This method will be called when a response with changed config is received from upstream * (content or generation has changed) or the server timeout has elapsed. - * Updates the cache with the returned config. + * Updates the cache with the returned config. Will only be called when in default mode * * @param config new config */ void updateSubscribers(RawConfig config) { - // ignore updates if we are in one of these modes (we will then only serve from cache). - if (!mode.requiresConfigSource()) { - if (log.isLoggable(LogLevel.DEBUG)) { - log.log(LogLevel.DEBUG, "Not updating " + config.getKey() + "," + config.getGeneration() + - ", since we are in '" + mode + "' mode"); - } - return; - } if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, "Config updated for " + config.getKey() + "," + config.getGeneration()); } - memoryCache.put(config); sendResponse(config); } @@ -105,8 +90,4 @@ class ClientUpdater { } } - // TODO: Remove, temporary until MapBackedConfigSource has been refactored - public MemoryCache getMemoryCache() { - return memoryCache; - } } 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 15440666a19..74f32f6d052 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 @@ -80,7 +80,7 @@ public class ProxyServer implements Runnable { this.delayedResponseHandling = delayedResponseHandling; this.memoryCache = memoryCache; this.rpcServer = createRpcServer(spec); - clientUpdater = new ClientUpdater(memoryCache, rpcServer, statistics, delayedResponses, mode); + clientUpdater = new ClientUpdater(rpcServer, statistics, delayedResponses); this.configClient = createClient(clientUpdater, delayedResponses, source, timingValues, memoryCache, configClient); } @@ -262,7 +262,7 @@ public class ProxyServer implements Runnable { } } - public MemoryCache getMemoryCache() { + MemoryCache getMemoryCache() { return 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 89234f400e9..4331d456f8e 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 @@ -153,7 +153,7 @@ 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, clientUpdater, configSourceSet, timingValues, requesterPool); + UpstreamConfigSubscriber subscriber = new UpstreamConfigSubscriber(input, clientUpdater, configSourceSet, timingValues, requesterPool, memoryCache); try { subscriber.subscribe(); activeSubscribers.put(configCacheKey, subscriber); diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriber.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriber.java index a11d5e32593..a52aa6d7216 100644 --- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriber.java +++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriber.java @@ -25,7 +25,8 @@ public class UpstreamConfigSubscriber implements Subscriber { private final ClientUpdater clientUpdater; private final ConfigSource configSourceSet; private final TimingValues timingValues; - private Map<ConfigSourceSet, JRTConfigRequester> requesterPool; + private final Map<ConfigSourceSet, JRTConfigRequester> requesterPool; + private final MemoryCache memoryCache; private GenericConfigSubscriber subscriber; private GenericConfigHandle handle; @@ -33,12 +34,14 @@ public class UpstreamConfigSubscriber implements Subscriber { ClientUpdater clientUpdater, ConfigSource configSourceSet, TimingValues timingValues, - Map<ConfigSourceSet, JRTConfigRequester> requesterPool) { + Map<ConfigSourceSet, JRTConfigRequester> requesterPool, + MemoryCache memoryCache) { this.config = config; this.clientUpdater = clientUpdater; this.configSourceSet = configSourceSet; this.timingValues = timingValues; this.requesterPool = requesterPool; + this.memoryCache = memoryCache; } void subscribe() { @@ -68,7 +71,7 @@ public class UpstreamConfigSubscriber implements Subscriber { "', generation=" + newConfig.getGeneration() + ", payload=" + newConfig.getPayload()); } - // memoryCache.put(); TODO: Add here later and remove in ClientUpdater + memoryCache.put(newConfig); clientUpdater.updateSubscribers(newConfig); } diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java index 9d1463aa8df..04a2c9077c6 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ClientUpdaterTest.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.proxy; -import com.yahoo.vespa.config.ConfigCacheKey; import com.yahoo.vespa.config.ConfigKey; import com.yahoo.vespa.config.RawConfig; import com.yahoo.vespa.config.protocol.JRTConfigRequestFactory; @@ -13,7 +12,6 @@ import org.junit.rules.TemporaryFolder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; /** @@ -23,8 +21,6 @@ public class ClientUpdaterTest { private MockRpcServer rpcServer; private ConfigProxyStatistics statistics; private DelayedResponses delayedResponses; - private Mode mode; - private MemoryCache memoryCache; private ClientUpdater clientUpdater; @Rule @@ -36,9 +32,7 @@ public class ClientUpdaterTest { rpcServer = new MockRpcServer(); statistics = new ConfigProxyStatistics(); delayedResponses = new DelayedResponses(statistics); - mode = new Mode(); - memoryCache = new MemoryCache(); - clientUpdater = new ClientUpdater(memoryCache, rpcServer, statistics, delayedResponses, mode); + clientUpdater = new ClientUpdater(rpcServer, statistics, delayedResponses); } @Test @@ -59,40 +53,15 @@ public class ClientUpdaterTest { RawConfig barConfig = new RawConfig(new ConfigKey<>("bar", "id", "namespace"), fooConfig.getDefMd5()); clientUpdater.updateSubscribers(barConfig); assertEquals(1, rpcServer.responses); - - - mode = new Mode(Mode.ModeName.MEMORYCACHE); - // Nothing should be returned, so still 1 response - assertEquals(1, rpcServer.responses); - assertThat(statistics.errors(), is(0L)); - } - - @Test - public void memoryCacheMode() { - final RawConfig fooConfig = ProxyServerTest.fooConfig; - mode = new Mode(Mode.ModeName.MEMORYCACHE); - clientUpdater = new ClientUpdater(memoryCache, rpcServer, statistics,delayedResponses, mode); - memoryCache.clear(); - assertThat(rpcServer.responses, is(0L)); - - clientUpdater.updateSubscribers(fooConfig); - assertNull(memoryCache.get(new ConfigCacheKey(fooConfig.getKey(), fooConfig.getDefMd5()))); - assertThat(memoryCache.size(), is(0)); - assertThat(rpcServer.responses, is(0L)); } @Test public void errorResponse() { assertThat(rpcServer.responses, is(0L)); - final RawConfig errorConfig = ProxyServerTest.errorConfig; - - clientUpdater.updateSubscribers(errorConfig); - // Error response, so not put into cache - assertNull(memoryCache.get(new ConfigCacheKey(errorConfig.getKey(), errorConfig.getDefMd5()))); + clientUpdater.updateSubscribers(ProxyServerTest.errorConfig); assertThat(rpcServer.responses, is(0L)); assertThat(statistics.errors(), is(1L)); } - } diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigTester.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigTester.java index 036c7ab0632..92cdb3094a5 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigTester.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigTester.java @@ -19,7 +19,7 @@ import java.util.Optional; */ public class ConfigTester { - private final long defaultTimeout = 10000; + private static final long defaultTimeout = 10000; public JRTServerConfigRequest createRequest(RawConfig config) { return createRequest(config, defaultTimeout); @@ -30,10 +30,6 @@ public class ConfigTester { config.getConfigMd5(), config.getDefMd5(), config.getGeneration(), timeout); } - public JRTServerConfigRequest createRequest(String configName, String configId, String namespace) { - return createRequest(configName, configId, namespace, defaultTimeout); - } - public JRTServerConfigRequest createRequest(String configName, String configId, String namespace, long timeout) { return createRequest(configName, configId, namespace, "", null, 0, timeout); } diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java index c01e236fa2a..a79f84a056d 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/DelayedResponseHandlerTest.java @@ -14,7 +14,7 @@ import static org.junit.Assert.assertThat; */ public class DelayedResponseHandlerTest { - private final MockConfigSource source = new MockConfigSource(new MockClientUpdater(new MemoryCache())); + private final MockConfigSource source = new MockConfigSource(new MockClientUpdater()); @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockClientUpdater.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockClientUpdater.java index 9064d9769a3..f399d1bb085 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockClientUpdater.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockClientUpdater.java @@ -10,12 +10,12 @@ import java.time.Instant; class MockClientUpdater extends ClientUpdater { private RawConfig lastConfig; - MockClientUpdater(MemoryCache memoryCache) { - this(new ConfigProxyStatistics(), new Mode(), memoryCache); + MockClientUpdater() { + this(new ConfigProxyStatistics()); } - private MockClientUpdater(ConfigProxyStatistics statistics, Mode mode, MemoryCache memoryCache) { - super(memoryCache, new MockRpcServer(), statistics, new DelayedResponses(statistics), mode); + private MockClientUpdater(ConfigProxyStatistics statistics) { + super(new MockRpcServer(), statistics, new DelayedResponses(statistics)); } @Override diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java index a16881033fa..784c82e2f88 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/MockConfigSourceClient.java @@ -14,18 +14,18 @@ import java.util.List; * @author hmusum */ public class MockConfigSourceClient implements ConfigSourceClient{ - private final ClientUpdater clientUpdater; private final MockConfigSource configSource; + private final MemoryCache memoryCache; - MockConfigSourceClient(ClientUpdater clientUpdater, MockConfigSource configSource) { - this.clientUpdater = clientUpdater; + MockConfigSourceClient(MockConfigSource configSource, MemoryCache memoryCache) { this.configSource = configSource; + this.memoryCache = memoryCache; } @Override public RawConfig getConfig(RawConfig input, JRTServerConfigRequest request) { final RawConfig config = getConfig(input.getKey()); - clientUpdater.getMemoryCache().put(config); + memoryCache.put(config); return config; } 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 c72240c1541..7a6c689a767 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 @@ -23,9 +23,9 @@ import static org.junit.Assert.*; public class ProxyServerTest { private final MemoryCache memoryCache = new MemoryCache(); - private MockClientUpdater clientUpdater = new MockClientUpdater(memoryCache); + private MockClientUpdater clientUpdater = new MockClientUpdater(); private final MockConfigSource source = new MockConfigSource(clientUpdater); - private MockConfigSourceClient client = new MockConfigSourceClient(clientUpdater, source); + private MockConfigSourceClient client = new MockConfigSourceClient(source, memoryCache); private final ConfigProxyStatistics statistics = new ConfigProxyStatistics(); private ProxyServer proxy; |