Search in sources :

Example 1 with ConfigCacheKey

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);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigCacheKey(com.yahoo.vespa.config.ConfigCacheKey) ArrayList(java.util.ArrayList) Slime(com.yahoo.slime.Slime) RawConfig(com.yahoo.vespa.config.RawConfig) Before(org.junit.Before)

Example 2 with ConfigCacheKey

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));
    }
}
Also used : JRTServerConfigRequest(com.yahoo.vespa.config.protocol.JRTServerConfigRequest) ConfigCacheKey(com.yahoo.vespa.config.ConfigCacheKey) RawConfig(com.yahoo.vespa.config.RawConfig) Date(java.util.Date)

Example 3 with ConfigCacheKey

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);
}
Also used : ConfigCacheKey(com.yahoo.vespa.config.ConfigCacheKey)

Example 4 with ConfigCacheKey

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;
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigCacheKey(com.yahoo.vespa.config.ConfigCacheKey) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigDefinition(com.yahoo.vespa.config.buildergen.ConfigDefinition) UnknownConfigDefinitionException(com.yahoo.vespa.config.server.UnknownConfigDefinitionException) ConfigResponse(com.yahoo.vespa.config.protocol.ConfigResponse)

Aggregations

ConfigCacheKey (com.yahoo.vespa.config.ConfigCacheKey)4 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)2 RawConfig (com.yahoo.vespa.config.RawConfig)2 ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)1 Slime (com.yahoo.slime.Slime)1 ConfigDefinition (com.yahoo.vespa.config.buildergen.ConfigDefinition)1 ConfigResponse (com.yahoo.vespa.config.protocol.ConfigResponse)1 JRTServerConfigRequest (com.yahoo.vespa.config.protocol.JRTServerConfigRequest)1 UnknownConfigDefinitionException (com.yahoo.vespa.config.server.UnknownConfigDefinitionException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Before (org.junit.Before)1