summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2021-10-13 07:31:29 +0200
committerHarald Musum <musum@yahooinc.com>2021-10-13 07:31:29 +0200
commit77bda8e21e3b4cd04eb68cd68590ce02176f253b (patch)
treee0a7a9e66fcc81db14e9f24b9c3848e8bc47b2d5 /configserver
parenta5e37d9dfada0dbc346857b09be18779d2652adf (diff)
Cleanup, no functional changes
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java33
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ServerCacheTest.java30
2 files changed, 33 insertions, 30 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java
index 3b765a3d8a7..6d6b93dad46 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java
@@ -4,6 +4,7 @@ package com.yahoo.vespa.config.server;
import com.yahoo.config.model.api.ConfigDefinitionRepo;
import com.yahoo.vespa.config.ConfigCacheKey;
import com.yahoo.vespa.config.ConfigDefinitionKey;
+import com.yahoo.vespa.config.PayloadChecksum;
import com.yahoo.vespa.config.buildergen.ConfigDefinition;
import com.yahoo.vespa.config.protocol.ConfigResponse;
@@ -11,6 +12,8 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
+import static com.yahoo.vespa.config.PayloadChecksum.Type.XXHASH64;
+
/**
* Cache that holds configs and config definitions (builtin and user config definitions).
*
@@ -22,8 +25,8 @@ public class ServerCache {
private final ConfigDefinitionRepo userConfigDefinitions;
// NOTE: The reason we do a double mapping here is to de-dupe configs that have the same md5.
- private final Map<ConfigCacheKey, String> md5Sums = new ConcurrentHashMap<>();
- private final Map<String, ConfigResponse> md5ToConfig = new ConcurrentHashMap<>();
+ private final Map<ConfigCacheKey, PayloadChecksum> checksums = new ConcurrentHashMap<>();
+ private final Map<PayloadChecksum, ConfigResponse> checksumToConfig = new ConcurrentHashMap<>();
private final Object [] stripedLocks = new Object[113];
public ServerCache(ConfigDefinitionRepo builtinConfigDefinitions, ConfigDefinitionRepo userConfigDefinitions) {
@@ -40,15 +43,15 @@ public class ServerCache {
}
private void put(ConfigCacheKey key, ConfigResponse config) {
- String configMd5 = config.getConfigMd5();
- md5Sums.put(key, configMd5);
- md5ToConfig.put(configMd5, config);
+ PayloadChecksum xxhash64 = config.getPayloadChecksums().getForType(XXHASH64);
+ checksums.put(key, xxhash64);
+ checksumToConfig.put(xxhash64, config);
}
ConfigResponse get(ConfigCacheKey key) {
- String md5 = md5Sums.get(key);
- if (md5 == null) return null;
- return md5ToConfig.get(md5);
+ PayloadChecksum xxhash64 = checksums.get(key);
+ if (xxhash64 == null) return null;
+ return checksumToConfig.get(xxhash64);
}
public ConfigResponse computeIfAbsent(ConfigCacheKey key, Function<ConfigCacheKey, ConfigResponse> mappingFunction) {
@@ -57,13 +60,13 @@ public class ServerCache {
return config;
}
synchronized (stripedLocks[Math.abs(key.hashCode()%stripedLocks.length)]) {
- String md5 = md5Sums.get(key);
- if (md5 == null) {
+ PayloadChecksum xxhash64 = checksums.get(key);
+ if (xxhash64 == null) {
config = mappingFunction.apply(key);
put(key, config);
return config;
}
- return md5ToConfig.get(md5);
+ return checksumToConfig.get(xxhash64);
}
}
@@ -73,8 +76,8 @@ public class ServerCache {
sb.append("Cache\n");
sb.append("builtin defs: ").append(builtinConfigDefinitions.getConfigDefinitions().size()).append("\n");
sb.append("user defs: ").append(userConfigDefinitions.getConfigDefinitions().size()).append("\n");
- sb.append("md5sums: ").append(md5Sums.size()).append("\n");
- sb.append("md5ToConfig: ").append(md5ToConfig.size()).append("\n");
+ sb.append("md5sums: ").append(checksums.size()).append("\n");
+ sb.append("md5ToConfig: ").append(checksumToConfig.size()).append("\n");
return sb.toString();
}
@@ -89,7 +92,7 @@ public class ServerCache {
* @return elems
*/
public int configElems() {
- return md5ToConfig.size();
+ return checksumToConfig.size();
}
/**
@@ -97,7 +100,7 @@ public class ServerCache {
* @return elems
*/
public int checkSumElems() {
- return md5Sums.size();
+ return checksums.size();
}
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ServerCacheTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ServerCacheTest.java
index 4d64e90a617..068a03d810c 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ServerCacheTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ServerCacheTest.java
@@ -11,10 +11,10 @@ import com.yahoo.vespa.config.protocol.SlimeConfigResponse;
import org.junit.Before;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.is;
+import static com.yahoo.vespa.config.PayloadChecksum.Type.XXHASH64;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertSame;
/**
* @author Ulf Lilleengen
@@ -24,8 +24,8 @@ public class ServerCacheTest {
private static final String defMd5 = "595f44fec1e92a71d3e9e77456ba80d1";
private static final String defMd5_2 = "a2f8edfc965802bf6d44826f9da7e2b0";
- private static final String configMd5 = "mymd5";
- private static final String configMd5_2 = "mymd5_2";
+ private static final String xxhash64 = "595f44fec1e92a71d";
+ private static final String xxhash64_2 = "a2f8edfc965802bf6";
private static final ConfigDefinition def = new ConfigDefinition("mypayload", new String[0]);
private static final ConfigDefinitionKey fooBarDefKey = new ConfigDefinitionKey("foo", "bar");
@@ -48,31 +48,31 @@ public class ServerCacheTest {
cache = new ServerCache(new TestConfigDefinitionRepo(), userConfigDefinitionRepo);
- cache.computeIfAbsent(fooBarCacheKey, (ConfigCacheKey key) -> SlimeConfigResponse.fromConfigPayload(ConfigPayload.empty(), 2, false, configMd5));
- cache.computeIfAbsent(bazQuuxCacheKey, (ConfigCacheKey key) -> SlimeConfigResponse.fromConfigPayload(ConfigPayload.empty(), 2, false, configMd5));
- cache.computeIfAbsent(fooBarCacheKeyDifferentMd5, (ConfigCacheKey key) -> SlimeConfigResponse.fromConfigPayload(ConfigPayload.empty(), 2, false, configMd5_2));
+ cache.computeIfAbsent(fooBarCacheKey, (ConfigCacheKey key) -> SlimeConfigResponse.fromConfigPayload(ConfigPayload.empty(), 2, false, xxhash64));
+ cache.computeIfAbsent(bazQuuxCacheKey, (ConfigCacheKey key) -> SlimeConfigResponse.fromConfigPayload(ConfigPayload.empty(), 2, false, xxhash64));
+ cache.computeIfAbsent(fooBarCacheKeyDifferentMd5, (ConfigCacheKey key) -> SlimeConfigResponse.fromConfigPayload(ConfigPayload.empty(), 2, false, xxhash64_2));
}
@Test
public void testThatCacheWorks() {
assertNotNull(cache.getDef(fooBazDefKey));
- assertThat(cache.getDef(fooBarDefKey), is(def));
- assertThat(cache.getDef(fooBimDefKey).getCNode().getName(), is("mynode"));
+ assertEquals(def, cache.getDef(fooBarDefKey));
+ assertEquals("mynode", cache.getDef(fooBimDefKey).getCNode().getName());
ConfigResponse raw = cache.get(fooBarCacheKey);
- assertThat(raw.getConfigMd5(), is(configMd5));
+ assertEquals(xxhash64, raw.getPayloadChecksums().getForType(XXHASH64).asString());
}
@Test
public void testThatCacheWorksWithSameKeyDifferentMd5() {
- assertThat(cache.getDef(fooBarDefKey), is(def));
+ assertEquals(def, cache.getDef(fooBarDefKey));
ConfigResponse raw = cache.get(fooBarCacheKey);
- assertThat(raw.getConfigMd5(), is(configMd5));
+ assertEquals(xxhash64, raw.getPayloadChecksums().getForType(XXHASH64).asString());
raw = cache.get(fooBarCacheKeyDifferentMd5);
- assertThat(raw.getConfigMd5(), is(configMd5_2));
+ assertEquals(xxhash64_2, raw.getPayloadChecksums().getForType(XXHASH64).asString());
}
@Test
public void testThatCacheWorksWithDifferentKeySameMd5() {
- assertTrue(cache.get(fooBarCacheKey) == cache.get(bazQuuxCacheKey));
+ assertSame(cache.get(fooBarCacheKey), cache.get(bazQuuxCacheKey));
}
}