summaryrefslogtreecommitdiffstats
path: root/config-proxy/src/main/java
diff options
context:
space:
mode:
authorHarald Musum <musum@yahoo-inc.com>2017-02-14 22:17:35 +0100
committerHarald Musum <musum@yahoo-inc.com>2017-02-14 22:17:35 +0100
commit58474e77ccd2a0f495a69c77cabe41e40d94bcfa (patch)
tree58e3aca49204f9e1559506bd40b25f4dfbab93aa /config-proxy/src/main/java
parent7c6ae7d45e6c53c70b9033973061ddebf95e8a98 (diff)
Refactoring
* Remove traces of diskcache mode and simplify startup now that only default mode is supported when starting config proxy * Remove CacheManager now that we have only one type of cache * Rename some classes
Diffstat (limited to 'config-proxy/src/main/java')
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/CacheManager.java46
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ClientUpdater.java22
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServer.java20
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyStatistics.java4
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigSourceClient.java5
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/DelayedResponse.java2
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/DelayedResponseHandler.java (renamed from config-proxy/src/main/java/com/yahoo/vespa/config/proxy/CheckDelayedResponses.java)18
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java31
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClient.java6
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/Mode.java6
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java100
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java4
12 files changed, 107 insertions, 157 deletions
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/CacheManager.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/CacheManager.java
deleted file mode 100644
index 680bb6b43ac..00000000000
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/CacheManager.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2016 Yahoo Inc. 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.RawConfig;
-
-/**
- * Manages memory and disk caches.
- *
- * @author hmusum
- */
-public class CacheManager {
-
- private final MemoryCache memoryCache;
-
- public CacheManager(MemoryCache memoryCache) {
- this.memoryCache = memoryCache;
- }
-
- static CacheManager createTestCacheManager() {
- return CacheManager.createTestCacheManager(new MemoryCache());
- }
-
- static CacheManager createTestCacheManager(MemoryCache memoryCache) {
- return new CacheManager(memoryCache);
- }
-
- void putInCache(RawConfig config) {
- putInMemoryCache(config);
- }
-
- private void putInMemoryCache(RawConfig config) {
- if (!config.isError()) {
- memoryCache.put(config);
- }
- }
-
- public MemoryCache getMemoryCache() {
- return memoryCache;
- }
-
- // Only for testing.
- int getCacheSize() {
- return getMemoryCache().size();
- }
-
-}
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 fbbc2071d30..28fc22538b6 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
@@ -14,21 +14,21 @@ import java.util.logging.Logger;
*
* @author hmusum
*/
-public class ClientUpdater {
- final static Logger log = Logger.getLogger(ClientUpdater.class.getName());
+class ClientUpdater {
+ private final static Logger log = Logger.getLogger(ClientUpdater.class.getName());
- private final CacheManager cacheManager;
+ private final MemoryCache memoryCache;
private final ConfigProxyStatistics statistics;
private final RpcServer rpcServer;
private final DelayedResponses delayedResponses;
private final Mode mode;
- public ClientUpdater(CacheManager cacheManager,
- RpcServer rpcServer,
- ConfigProxyStatistics statistics,
- DelayedResponses delayedResponses,
- Mode mode) {
- this.cacheManager = cacheManager;
+ ClientUpdater(MemoryCache memoryCache,
+ RpcServer rpcServer,
+ ConfigProxyStatistics statistics,
+ DelayedResponses delayedResponses,
+ Mode mode) {
+ this.memoryCache = memoryCache;
this.rpcServer = rpcServer;
this.statistics = statistics;
this.delayedResponses = delayedResponses;
@@ -54,11 +54,11 @@ public class ClientUpdater {
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Config updated for " + config.getKey() + "," + config.getGeneration());
}
- cacheManager.putInCache(config);
+ memoryCache.put(config);
sendResponse(config);
}
- void sendResponse(RawConfig config) {
+ private void sendResponse(RawConfig config) {
if (config.isError()) { statistics.incErrorCount(); }
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Sending response for " + config.getKey() + "," + config.getGeneration());
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServer.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServer.java
index 7104ed5a24b..eff25aa9191 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServer.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServer.java
@@ -25,13 +25,13 @@ import java.util.logging.Logger;
public class ConfigProxyRpcServer implements Runnable, TargetWatcher, RpcServer {
private final static Logger log = Logger.getLogger(ConfigProxyRpcServer.class.getName());
- static final int TRACELEVEL = 6;
+ private static final int TRACELEVEL = 6;
private final Spec spec;
private final Supervisor supervisor = new Supervisor(new Transport());
private final ProxyServer proxyServer;
- public ConfigProxyRpcServer(ProxyServer proxyServer, Spec spec) {
+ ConfigProxyRpcServer(ProxyServer proxyServer, Spec spec) {
this.proxyServer = proxyServer;
this.spec = spec;
setUp();
@@ -53,11 +53,11 @@ public class ConfigProxyRpcServer implements Runnable, TargetWatcher, RpcServer
supervisor.transport().shutdown();
}
- public Spec getSpec() {
+ Spec getSpec() {
return spec;
}
- void setUp() {
+ private void setUp() {
// The getConfig method in this class will handle RPC calls for getting config
supervisor.addMethod(JRTMethods.createConfigV3GetConfigMethod(this, "getConfigV3"));
supervisor.addMethod(new Method("ping", "", "i",
@@ -157,13 +157,13 @@ public class ConfigProxyRpcServer implements Runnable, TargetWatcher, RpcServer
RawConfig config = proxyServer.resolveConfig(request);
if (config == null) {
if (log.isLoggable(LogLevel.DEBUG)) {
- log.log(LogLevel.DEBUG, "No config received yet for " + request.getShortDescription() + ",not sending response");
+ log.log(LogLevel.DEBUG, "No config received yet for " + request.getShortDescription() + ", not sending response");
}
} else if (ProxyServer.configOrGenerationHasChanged(config, request)) {
returnOkResponse(request, config);
} else {
if (log.isLoggable(LogLevel.DEBUG)) {
- log.log(LogLevel.DEBUG, "No new config for " + request.getShortDescription() + ",not sending response");
+ log.log(LogLevel.DEBUG, "No new config for " + request.getShortDescription() + ", not sending response");
}
}
} catch (Exception e) {
@@ -236,7 +236,7 @@ public class ConfigProxyRpcServer implements Runnable, TargetWatcher, RpcServer
}
public final void invalidateCache(Request req) {
- proxyServer.getCacheManager().getMemoryCache().clear();
+ proxyServer.getMemoryCache().clear();
String[] s = new String[2];
s[0] = "0";
s[1] = "success";
@@ -265,13 +265,13 @@ public class ConfigProxyRpcServer implements Runnable, TargetWatcher, RpcServer
@SuppressWarnings({"UnusedDeclaration"})
public final void dumpCache(Request req) {
- final CacheManager cacheManager = proxyServer.getCacheManager();
- req.returnValues().add(new StringValue(cacheManager.getMemoryCache().dumpCacheToDisk(req.parameters().get(0).asString(), cacheManager.getMemoryCache())));
+ final MemoryCache memoryCache = proxyServer.getMemoryCache();
+ req.returnValues().add(new StringValue(memoryCache.dumpCacheToDisk(req.parameters().get(0).asString(), memoryCache)));
}
final void listCachedConfig(Request req, boolean full) {
String[] ret;
- MemoryCache cache = proxyServer.getCacheManager().getMemoryCache();
+ MemoryCache cache = proxyServer.getMemoryCache();
ret = new String[cache.size()];
int i = 0;
for (RawConfig config : cache.values()) {
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyStatistics.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyStatistics.java
index 5ad521ef5f6..ce123b219a9 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyStatistics.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigProxyStatistics.java
@@ -59,11 +59,11 @@ class ConfigProxyStatistics implements Runnable {
Event.value("delayed_responses", delayedResponses());
}
- public void stop() {
+ void stop() {
stopped = true;
}
- public Long getEventInterval() {
+ Long getEventInterval() {
return eventInterval;
}
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigSourceClient.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigSourceClient.java
index 5bbb6d40cc7..f8b2cafa50f 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigSourceClient.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ConfigSourceClient.java
@@ -19,12 +19,11 @@ import java.util.List;
public abstract class ConfigSourceClient {
static ConfigSourceClient createClient(ConfigSource source,
ClientUpdater clientUpdater,
- CacheManager cacheManager,
+ MemoryCache memoryCache,
TimingValues timingValues,
- ConfigProxyStatistics statistics,
DelayedResponses delayedResponses) {
if (source instanceof ConfigSourceSet) {
- return new RpcConfigSourceClient((ConfigSourceSet) source, clientUpdater, cacheManager, timingValues, delayedResponses);
+ return new RpcConfigSourceClient((ConfigSourceSet) source, clientUpdater, memoryCache, timingValues, delayedResponses);
} else if (source instanceof MapBackedConfigSource) {
return (ConfigSourceClient) source;
} else {
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/DelayedResponse.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/DelayedResponse.java
index 257b94038b6..2a89dc224c5 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/DelayedResponse.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/DelayedResponse.java
@@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
* delayed responses and returning requests that are about to time out, in cases where no new
* config has been returned from upstream)
*
- * @see com.yahoo.vespa.config.proxy.CheckDelayedResponses
+ * @see DelayedResponseHandler
*/
public class DelayedResponse implements Delayed {
private final JRTServerConfigRequest request;
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/CheckDelayedResponses.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/DelayedResponseHandler.java
index c6a5d90fd2b..21909a5e371 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/CheckDelayedResponses.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/DelayedResponseHandler.java
@@ -11,20 +11,20 @@ import java.util.Date;
import java.util.logging.Logger;
/**
- * The run method of this class is executed periodically to
- * return requests that are about to time out.
+ * The run method of this class is executed periodically to return delayed responses
+ * (long polling requests that are about to time out and needs to be returned).
*
* @author hmusum
*/
-public class CheckDelayedResponses implements Runnable {
+public class DelayedResponseHandler implements Runnable {
- final static Logger log = Logger.getLogger(CheckDelayedResponses.class.getName());
+ private final static Logger log = Logger.getLogger(DelayedResponseHandler.class.getName());
private final DelayedResponses delayedResponses;
private final MemoryCache memoryCache;
private final RpcServer rpcServer;
- public CheckDelayedResponses(DelayedResponses delayedResponses, MemoryCache memoryCache, RpcServer rpcServer) {
+ DelayedResponseHandler(DelayedResponses delayedResponses, MemoryCache memoryCache, RpcServer rpcServer) {
this.delayedResponses = delayedResponses;
this.memoryCache = memoryCache;
this.rpcServer = rpcServer;
@@ -39,7 +39,7 @@ public class CheckDelayedResponses implements Runnable {
try {
long start = System.currentTimeMillis();
if (log.isLoggable(LogLevel.SPAM)) {
- log.log(LogLevel.SPAM, "Running CheckDelayedResponses. There are " + delayedResponses.size() + " delayed responses. First one is " + delayedResponses.responses().peek());
+ log.log(LogLevel.SPAM, "Running DelayedResponseHandler. There are " + delayedResponses.size() + " delayed responses. First one is " + delayedResponses.responses().peek());
}
DelayedResponse response;
int i = 0;
@@ -59,13 +59,13 @@ public class CheckDelayedResponses implements Runnable {
}
}
if (log.isLoggable(LogLevel.SPAM)) {
- log.log(LogLevel.SPAM, "Finished running CheckDelayedResponses. " + i + " delayed responses sent in " +
+ log.log(LogLevel.SPAM, "Finished running DelayedResponseHandler. " + i + " delayed responses sent in " +
(System.currentTimeMillis() - start) + " ms");
}
} catch (Exception e) { // To avoid thread throwing exception and executor never running this again
- log.log(LogLevel.WARNING, "Got exception in CheckDelayedResponses: " + Exceptions.toMessageString(e));
+ log.log(LogLevel.WARNING, "Got exception in DelayedResponseHandler: " + Exceptions.toMessageString(e));
} catch (Throwable e) {
- com.yahoo.protect.Process.logAndDie("Got error in CheckDelayedResponses, exiting: " + Exceptions.toMessageString(e));
+ com.yahoo.protect.Process.logAndDie("Got error in DelayedResponseHandler, exiting: " + Exceptions.toMessageString(e));
}
}
}
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java
index e5ef69cbe7a..a3ed15405da 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java
@@ -27,30 +27,31 @@ public class MemoryCache {
// Separator in file names between different fields of config key
private final static String separator = ":";
private static final String DEFAULT_DUMP_DIR = Defaults.getDefaults().vespaHome() + "var/vespa/cache/config";
- private final String dumpDir;
private final ConcurrentHashMap<ConfigCacheKey, RawConfig> cache = new ConcurrentHashMap<>(500, 0.75f);
- public MemoryCache() {
- dumpDir = DEFAULT_DUMP_DIR;
- }
-
public RawConfig get(ConfigCacheKey key) {
return cache.get(key);
}
- public RawConfig put(RawConfig config) {
+ /**
+ * Put in cache, except when config has an error
+ * @param config config to put in cache
+ */
+ public void put(RawConfig config) {
+ if (config.isError()) return;
+
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Putting '" + config + "' into memory cache");
}
- return cache.put(new ConfigCacheKey(config.getKey(), config.getDefMd5()), config);
+ cache.put(new ConfigCacheKey(config.getKey(), config.getDefMd5()), config);
}
boolean containsKey(ConfigCacheKey key) {
return cache.containsKey(key);
}
- public Collection<RawConfig> values() {
+ Collection<RawConfig> values() {
return cache.values();
}
@@ -69,7 +70,7 @@ public class MemoryCache {
String dumpCacheToDisk(String path, MemoryCache cache) {
if (path == null || path.isEmpty()) {
- path = dumpDir;
+ path = DEFAULT_DUMP_DIR;
log.log(LogLevel.DEBUG, "dumpCache. No path or empty path. Using dir '" + path + "'");
}
if (path.endsWith("/")) {
@@ -83,19 +84,19 @@ public class MemoryCache {
return "Not a dir or not able to write to '" + dir + "'";
}
for (RawConfig config : cache.values()) {
- put(config, path);
+ writeConfigToFile(config, path);
}
return "success";
}
- void put(RawConfig config, String path) {
- if (log.isLoggable(LogLevel.DEBUG)) {
- log.log(LogLevel.DEBUG, "Putting '" + config.getKey() + "' into disk cache");
- }
+ private void writeConfigToFile(RawConfig config, String path) {
String filename = null;
Writer writer = null;
try {
filename = path + File.separator + createCacheFileName(config);
+ if (log.isLoggable(LogLevel.DEBUG)) {
+ log.log(LogLevel.DEBUG, "Writing '" + config.getKey() + "' to '" + filename + "'");
+ }
final Payload payload = config.getPayload();
long protocolVersion = 3;
log.log(LogLevel.DEBUG, "Writing config '" + config + "' to file '" + filename + "' with protocol version " + protocolVersion);
@@ -127,7 +128,7 @@ public class MemoryCache {
return createCacheFileName(new ConfigCacheKey(config.getKey(), config.getDefMd5()));
}
- static String createCacheFileName(ConfigCacheKey key) {
+ private static String createCacheFileName(ConfigCacheKey key) {
final ConfigKey<?> configKey = key.getKey();
return configKey.getNamespace() + "." + configKey.getName() + separator + configKey.getConfigId().replaceAll("/", "_") +
separator + key.getDefMd5();
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClient.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClient.java
index cfe3836faa7..f1980b05817 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClient.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCacheConfigClient.java
@@ -13,7 +13,7 @@ import java.util.logging.Logger;
* @author hmusum
* @since 5.1.10
*/
-public class MemoryCacheConfigClient extends ConfigSourceClient {
+class MemoryCacheConfigClient extends ConfigSourceClient {
private final static Logger log = Logger.getLogger(MemoryCacheConfigClient.class.getName());
private final MemoryCache cache;
@@ -22,13 +22,13 @@ public class MemoryCacheConfigClient extends ConfigSourceClient {
this.cache = cache;
}
- @Override
/**
- * Retrieves the requested config from the cache. Used when in 'memorycache' mode</p>
+ * Retrieves the requested config from the cache. Used when in 'memorycache' mode.
*
* @param request The config to retrieve - can be empty (no payload), or have a valid payload.
* @return A Config with a payload.
*/
+ @Override
RawConfig getConfig(RawConfig input, JRTServerConfigRequest request) {
log.log(LogLevel.DEBUG, "Getting config from cache");
ConfigKey<?> key = input.getKey();
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/Mode.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/Mode.java
index 38ba9d646b4..ecec8aca3a9 100644
--- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/Mode.java
+++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/Mode.java
@@ -22,7 +22,11 @@ class Mode {
}
public Mode() {
- this(ModeName.DEFAULT.name());
+ this(ModeName.DEFAULT);
+ }
+
+ public Mode(ModeName modeName) {
+ mode = modeName;
}
public Mode(String modeString) {
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 131d292ce5a..a0ce5853768 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
@@ -20,6 +20,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
+import static com.yahoo.vespa.config.proxy.Mode.ModeName.DEFAULT;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
@@ -40,7 +41,7 @@ public class ProxyServer implements Runnable {
// Scheduled executor that periodically checks for requests that have timed out and response should be returned to clients
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, new DaemonThreadFactory());
private final ClientUpdater clientUpdater;
- private ScheduledFuture<?> checkerHandle;
+ private ScheduledFuture<?> delayedResponseScheduler;
private final ConfigProxyRpcServer rpcServer;
final DelayedResponses delayedResponses;
@@ -50,57 +51,56 @@ public class ProxyServer implements Runnable {
private final ConfigProxyStatistics statistics;
private final TimingValues timingValues;
- private final CacheManager cacheManager;
- private static final double timingvaluesRatio = 0.8;
+ private final MemoryCache memoryCache;
+ private static final double timingValuesRatio = 0.8;
private final static TimingValues defaultTimingValues;
private final boolean delayedResponseHandling;
private volatile Mode mode;
-
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)).
+ tv.setUnconfiguredDelay((long)(tv.getUnconfiguredDelay()* timingValuesRatio)).
+ setConfiguredErrorDelay((long)(tv.getConfiguredErrorDelay()* timingValuesRatio)).
+ setSubscribeTimeout((long)(tv.getSubscribeTimeout()* timingValuesRatio)).
setConfiguredErrorTimeout(-1); // Never cache errors
defaultTimingValues = tv;
}
private ProxyServer(Spec spec, DelayedResponses delayedResponses, ConfigSource source,
ConfigProxyStatistics statistics, TimingValues timingValues, Mode mode, boolean delayedResponseHandling,
- CacheManager cacheManager) {
+ MemoryCache memoryCache) {
this.delayedResponses = delayedResponses;
this.configSource = source;
- log.log(LogLevel.DEBUG, "Using config sources: " + source);
+ log.log(LogLevel.DEBUG, "Using config source '" + source);
this.statistics = statistics;
this.timingValues = timingValues;
this.mode = mode;
this.delayedResponseHandling = delayedResponseHandling;
- this.cacheManager = cacheManager;
+ this.memoryCache = memoryCache;
if (spec == null) {
rpcServer = null;
} else {
rpcServer = new ConfigProxyRpcServer(this, spec);
}
- clientUpdater = new ClientUpdater(cacheManager, rpcServer, statistics, delayedResponses, mode);
- this.configSourceClient = ConfigSourceClient.createClient(source, clientUpdater, cacheManager, timingValues, statistics, delayedResponses);
+ clientUpdater = new ClientUpdater(memoryCache, rpcServer, statistics, delayedResponses, mode);
+ this.configSourceClient = ConfigSourceClient.createClient(source, clientUpdater, memoryCache, timingValues, delayedResponses);
}
- static ProxyServer create(int port, DelayedResponses delayedResponses, ConfigSource source,
- ConfigProxyStatistics statistics, Mode mode) {
- return new ProxyServer(new Spec(null, port), delayedResponses, source, statistics, defaultTimingValues(), mode, true, new CacheManager(new MemoryCache()));
+ private static ProxyServer create(int port, DelayedResponses delayedResponses, ConfigSource source,
+ ConfigProxyStatistics statistics, Mode mode) {
+ return new ProxyServer(new Spec(null, port), delayedResponses, source, statistics, defaultTimingValues(), mode, true, new MemoryCache());
}
- static ProxyServer createTestServer(ConfigSource source) {
- final Mode mode = new Mode(Mode.ModeName.DEFAULT.name());
- return ProxyServer.createTestServer(source, false, mode, CacheManager.createTestCacheManager());
- }
- static ProxyServer createTestServer(ConfigSource source, boolean delayedResponseHandling, Mode mode, CacheManager cacheManager) {
+ static ProxyServer createTestServer(ConfigSource source) {
+ final Mode mode = new Mode(DEFAULT);
final ConfigProxyStatistics statistics = new ConfigProxyStatistics();
- return new ProxyServer(null, new DelayedResponses(statistics), source, statistics, defaultTimingValues(), mode, delayedResponseHandling, cacheManager);
+ final boolean delayedResponseHandling = false;
+ return new ProxyServer(null, new DelayedResponses(statistics),
+ source, statistics, defaultTimingValues(), mode, delayedResponseHandling,
+ new MemoryCache());
}
public void run() {
@@ -111,7 +111,10 @@ public class ProxyServer implements Runnable {
}
if (delayedResponseHandling) {
// Wait for 5 seconds initially, then run every second
- checkerHandle = scheduler.scheduleAtFixedRate(new CheckDelayedResponses(delayedResponses, cacheManager.getMemoryCache(), rpcServer), 5, 1, SECONDS);
+ delayedResponseScheduler = scheduler.scheduleAtFixedRate(new DelayedResponseHandler(delayedResponses,
+ memoryCache,
+ rpcServer),
+ 5, 1, SECONDS);
} else {
log.log(LogLevel.INFO, "Running without delayed response handling");
}
@@ -125,7 +128,7 @@ public class ProxyServer implements Runnable {
// In the last case the method below will return null.
RawConfig config = configSourceClient.getConfig(RawConfig.createFromServerRequest(req), req);
if (configOrGenerationHasChanged(config, req)) {
- cacheManager.putInCache(config);
+ memoryCache.put(config);
}
return config;
}
@@ -143,19 +146,22 @@ public class ProxyServer implements Runnable {
log.log(LogLevel.INFO, "Switching from " + this.mode + " mode to " + modeName.toLowerCase() + " mode");
this.mode = new Mode(modeName);
- if (mode.isMemoryCache()) {
- configSourceClient.shutdownSourceConnections();
- configSourceClient = new MemoryCacheConfigClient(cacheManager.getMemoryCache());
- } else if (mode.isDefault()) {
- flush();
- configSourceClient = createRpcClient();
- } else {
- throw new IllegalArgumentException("Not able to handle mode '" + modeName + "'");
+ switch (mode.getMode()) {
+ case MEMORYCACHE:
+ configSourceClient.shutdownSourceConnections();
+ configSourceClient = new MemoryCacheConfigClient(memoryCache);
+ break;
+ case DEFAULT:
+ flush();
+ configSourceClient = createRpcClient();
+ break;
+ default:
+ throw new IllegalArgumentException("Not able to handle mode '" + modeName + "'");
}
}
private RpcConfigSourceClient createRpcClient() {
- return new RpcConfigSourceClient((ConfigSourceSet) configSource, clientUpdater, cacheManager, timingValues, delayedResponses);
+ return new RpcConfigSourceClient((ConfigSourceSet) configSource, clientUpdater, memoryCache, timingValues, delayedResponses);
}
private void setupSigTermHandler() {
@@ -194,20 +200,9 @@ public class ProxyServer implements Runnable {
t.setDaemon(true);
t.start();
- Mode startupMode = new Mode(properties.mode);
- if (!startupMode.isDefault()) log.log(LogLevel.INFO, "Starting config proxy in '" + startupMode + "' mode");
-
- if (startupMode.isMemoryCache()) {
- log.log(LogLevel.ERROR, "Starting config proxy in '" + startupMode + "' mode is not allowed");
- System.exit(1);
- }
-
- ConfigSourceSet configSources = new ConfigSourceSet();
- if (startupMode.requiresConfigSource()) {
- configSources = new ConfigSourceSet(properties.configSources);
- }
+ ConfigSourceSet configSources = new ConfigSourceSet(properties.configSources);
DelayedResponses delayedResponses = new DelayedResponses(statistics);
- ProxyServer proxyServer = ProxyServer.create(port, delayedResponses, configSources, statistics, startupMode);
+ ProxyServer proxyServer = ProxyServer.create(port, delayedResponses, configSources, statistics, new Mode(DEFAULT));
// catch termination signal
proxyServer.setupSigTermHandler();
Thread proxyserverThread = new Thread(proxyServer);
@@ -219,19 +214,16 @@ public class ProxyServer implements Runnable {
static Properties getSystemProperties() {
// Read system properties
long eventInterval = Long.getLong("eventinterval", ConfigProxyStatistics.defaultEventInterval);
- String mode = System.getProperty("mode", Mode.ModeName.DEFAULT.name());
final String[] inputConfigSources = System.getProperty("proxyconfigsources", DEFAULT_PROXY_CONFIG_SOURCES).split(",");
- return new Properties(eventInterval, mode, inputConfigSources);
+ return new Properties(eventInterval, inputConfigSources);
}
static class Properties {
final long eventInterval;
- final String mode;
final String[] configSources;
- Properties(long eventInterval, String mode, String[] configSources) {
+ Properties(long eventInterval, String[] configSources) {
this.eventInterval = eventInterval;
- this.mode = mode;
this.configSources = configSources;
}
}
@@ -251,22 +243,22 @@ public class ProxyServer implements Runnable {
// Cancels all config instances and flushes the cache. When this method returns,
// the cache will not be updated again before someone calls getConfig().
synchronized void flush() {
- cacheManager.getMemoryCache().clear();
+ memoryCache.clear();
configSourceClient.cancel();
}
public void stop() {
Event.stopping("configproxy", "shutdown");
if (rpcServer != null) rpcServer.shutdown();
- if (checkerHandle != null) checkerHandle.cancel(true);
+ if (delayedResponseScheduler != null) delayedResponseScheduler.cancel(true);
flush();
if (statistics != null) {
statistics.stop();
}
}
- public CacheManager getCacheManager() {
- return cacheManager;
+ public MemoryCache getMemoryCache() {
+ return memoryCache;
}
String getActiveSourceConnection() {
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 30c85efe93b..1f5d49270ed 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
@@ -43,12 +43,12 @@ public class RpcConfigSourceClient extends ConfigSourceClient {
RpcConfigSourceClient(ConfigSourceSet configSourceSet,
ClientUpdater clientUpdater,
- CacheManager cacheManager,
+ MemoryCache memoryCache,
TimingValues timingValues,
DelayedResponses delayedResponses) {
this.configSourceSet = configSourceSet;
this.clientUpdater = clientUpdater;
- this.memoryCache = cacheManager.getMemoryCache();
+ this.memoryCache = memoryCache;
this.delayedResponses = delayedResponses;
this.timingValues = timingValues;
checkConfigSources();