use of com.yahoo.vespa.config.ConfigCacheKey in project vespa by vespa-engine.
the class MemoryCacheTest method setup.
@Before
public void setup() {
ArrayList<String> defContent = new ArrayList<>();
defContent.add("bar string");
Slime slime = new Slime();
slime.setString("bar \"value\"");
payload = Payload.from(new ConfigPayload(slime));
slime = new Slime();
slime.setString("bar \"baz\"");
payload2 = Payload.from(new ConfigPayload(slime));
slime = new Slime();
slime.setString("bar \"value2\"");
payloadDifferentMd5 = Payload.from(new ConfigPayload(slime));
config = new RawConfig(configKey, defMd5, payload, configMd5, generation, defContent, Optional.empty());
config2 = new RawConfig(configKey2, defMd52, payload2, configMd5, generation, defContent, Optional.empty());
configDifferentMd5 = new RawConfig(configKey, differentDefMd5, payloadDifferentMd5, configMd5, generation, defContent, Optional.empty());
cacheKey = new ConfigCacheKey(configKey, config.getDefMd5());
cacheKey2 = new ConfigCacheKey(configKey2, config2.getDefMd5());
cacheKeyDifferentMd5 = new ConfigCacheKey(configKey, differentDefMd5);
}
use of com.yahoo.vespa.config.ConfigCacheKey in project vespa by vespa-engine.
the class DelayedResponseHandler method checkDelayedResponses.
void checkDelayedResponses() {
try {
long start = System.currentTimeMillis();
if (log.isLoggable(LogLevel.SPAM)) {
log.log(LogLevel.SPAM, "Running DelayedResponseHandler. There are " + delayedResponses.size() + " delayed responses. First one is " + delayedResponses.responses().peek());
}
DelayedResponse response;
int i = 0;
while ((response = delayedResponses.responses().poll()) != null) {
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Returning with response that has return time " + new Date(response.getReturnTime()));
}
JRTServerConfigRequest request = response.getRequest();
ConfigCacheKey cacheKey = new ConfigCacheKey(request.getConfigKey(), request.getConfigKey().getMd5());
RawConfig config = memoryCache.get(cacheKey);
if (config != null) {
rpcServer.returnOkResponse(request, config);
i++;
} else {
log.log(LogLevel.WARNING, "Timed out (timeout " + request.getTimeout() + ") getting config " + request.getConfigKey() + ", will retry");
}
}
if (log.isLoggable(LogLevel.SPAM)) {
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 DelayedResponseHandler: " + Exceptions.toMessageString(e));
} catch (Throwable e) {
com.yahoo.protect.Process.logAndDie("Got error in DelayedResponseHandler, exiting: " + Exceptions.toMessageString(e));
}
}
use of com.yahoo.vespa.config.ConfigCacheKey in project vespa by vespa-engine.
the class MemoryCache method put.
/**
* 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;
log.log(LogLevel.DEBUG, () -> "Putting '" + config + "' into memory cache");
cache.put(new ConfigCacheKey(config.getKey(), config.getDefMd5()), config);
}
use of com.yahoo.vespa.config.ConfigCacheKey in project vespa by vespa-engine.
the class Application method resolveConfig.
/**
* Gets a config from ZK. Returns null if not found.
*/
public ConfigResponse resolveConfig(GetConfigRequest req, ConfigResponseFactory responseFactory) {
long start = System.currentTimeMillis();
metricUpdater.incrementRequests();
ConfigKey<?> configKey = req.getConfigKey();
String defMd5 = configKey.getMd5();
if (defMd5 == null || defMd5.isEmpty()) {
defMd5 = ConfigUtils.getDefMd5(req.getDefContent().asList());
}
ConfigCacheKey cacheKey = new ConfigCacheKey(configKey, defMd5);
if (logDebug()) {
debug("Resolving config " + cacheKey);
}
if (!req.noCache()) {
ConfigResponse config = cache.get(cacheKey);
if (config != null) {
if (logDebug()) {
debug("Found config " + cacheKey + " in cache");
}
metricUpdater.incrementProcTime(System.currentTimeMillis() - start);
return config;
}
}
ConfigDefinition def = getTargetDef(req);
if (def == null) {
metricUpdater.incrementFailedRequests();
throw new UnknownConfigDefinitionException("Unable to find config definition for '" + configKey.getNamespace() + "." + configKey.getName());
}
if (logDebug()) {
debug("Resolving " + configKey + " with config definition " + def);
}
ConfigPayload payload = model.getConfig(configKey, def);
if (payload == null) {
metricUpdater.incrementFailedRequests();
throw new ConfigurationRuntimeException("Unable to resolve config " + configKey);
}
ConfigResponse configResponse = responseFactory.createResponse(payload, def.getCNode(), appGeneration);
metricUpdater.incrementProcTime(System.currentTimeMillis() - start);
if (!req.noCache()) {
cache.put(cacheKey, configResponse, configResponse.getConfigMd5());
metricUpdater.setCacheConfigElems(cache.configElems());
metricUpdater.setCacheChecksumElems(cache.checkSumElems());
}
return configResponse;
}
Aggregations