summaryrefslogtreecommitdiffstats
path: root/config-proxy
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2019-05-01 08:50:59 +0200
committerHarald Musum <musum@verizonmedia.com>2019-05-01 08:50:59 +0200
commit7fa2bc2a4bbc6eb6b6c11c681acf1aa7804d6de7 (patch)
tree03be226970713b646a5e28bbe17b8fbf890dd4c3 /config-proxy
parentdd219ffd3416e1a752c50d92dfb8461e4689510a (diff)
Handle getting new config after getting empty config
Sentinel config is empty with generation 0 if an application does not exist. When we get that, make sure not to cache the config and make sure to ask for new new config even when we have one for generation 0, to handle cases where we get empty sentinel config due to some config server issue/bug when upgrading and where the effect is that empty sentinel config is served. This change should make the sentinel start services immediately after such an issue has been fixed.
Diffstat (limited to 'config-proxy')
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java3
-rw-r--r--config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java2
-rw-r--r--config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ProxyServerTest.java34
3 files changed, 37 insertions, 2 deletions
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 0fe7fe01467..80bca85d9e4 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
@@ -40,7 +40,8 @@ public class MemoryCache {
* @param config config to put in cache
*/
public void put(RawConfig config) {
- if (config.isError()) return;
+ // Do not cache errors or empty configs (which have generation 0)
+ if (config.isError() || config.getGeneration() == 0) return;
log.log(LogLevel.DEBUG, () -> "Putting '" + config + "' into memory cache");
cache.put(new ConfigCacheKey(config.getKey(), config.getDefMd5()), config);
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 b4eda05fde4..9306220f518 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
@@ -132,7 +132,7 @@ class RpcConfigSourceClient implements ConfigSourceClient {
ret = cachedConfig;
}
}
- if (!cachedConfig.isError()) {
+ if (!cachedConfig.isError() && cachedConfig.getGeneration() > 0) {
needToGetConfig = false;
}
}
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 22488da7c80..e21df82a036 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
@@ -171,6 +171,40 @@ public class ProxyServerTest {
assertEquals(1, cacheManager.size());
}
+ /**
+ * Verifies that config with generation 0 (used for empty sentinel config) is not cached.
+ * If it was cached, it would be served even when newer config is available
+ * (as they ask for config, saying that it now has config with generation 0).
+ * When the config has been successfully retrieved it must be put in the cache.
+ */
+ @Test
+ public void testNoCachingOfEmptyConfig() {
+ ConfigTester tester = new ConfigTester();
+ // Simulate an empty response
+ RawConfig emptyConfig = new RawConfig(fooConfig.getKey(), fooConfig.getDefMd5(),
+ Payload.from("{}"), fooConfig.getConfigMd5(),
+ 0, false, 0, fooConfig.getDefContent(), Optional.empty());
+ source.put(fooConfig.getKey(), emptyConfig);
+
+ MemoryCache cache = proxy.getMemoryCache();
+ assertEquals(0, cache.size());
+
+ RawConfig res = proxy.resolveConfig(tester.createRequest(fooConfig));
+ assertNotNull(res.getPayload());
+ assertThat(res.getPayload().toString(), is(emptyConfig.getPayload().toString()));
+ assertEquals(0, cache.size());
+
+ // Put a version of the same config into backend with new generation and see that it now works (i.e. we are
+ // not getting a cached response (of the error in the previous request)
+ source.put(fooConfig.getKey(), createConfigWithNextConfigGeneration(fooConfig, 0));
+
+ // Verify that we get the config now and that it is cached
+ res = proxy.resolveConfig(tester.createRequest(fooConfig));
+ assertNotNull(res.getPayload().getData());
+ assertThat(res.getPayload().toString(), is(ConfigTester.fooPayload.toString()));
+ assertEquals(1, cache.size());
+ }
+
@Test
public void testReconfiguration() {
ConfigTester tester = new ConfigTester();