Search in sources :

Example 1 with JRTServerConfigRequest

use of com.yahoo.vespa.config.protocol.JRTServerConfigRequest in project vespa by vespa-engine.

the class ProxyServerTest method testGetConfigAndCaching.

/**
 * Verifies that config is retrieved from the real server when it is not found in the cache,
 * that the cache is populated with the config and that the entry in the cache is used
 * when it is found there.
 */
@Test
public void testGetConfigAndCaching() {
    ConfigTester tester = new ConfigTester();
    final MemoryCache memoryCache = proxy.getMemoryCache();
    assertEquals(0, memoryCache.size());
    RawConfig res = proxy.resolveConfig(tester.createRequest(fooConfig));
    assertNotNull(res);
    assertThat(res.getPayload().toString(), is(ConfigTester.fooPayload.toString()));
    assertEquals(1, memoryCache.size());
    assertThat(memoryCache.get(new ConfigCacheKey(fooConfig.getKey(), fooConfig.getDefMd5())), is(res));
    // Trying same config again
    JRTServerConfigRequest newRequestBasedOnResponse = tester.createRequest(res);
    RawConfig res2 = proxy.resolveConfig(newRequestBasedOnResponse);
    assertFalse(ProxyServer.configOrGenerationHasChanged(res2, newRequestBasedOnResponse));
    assertEquals(1, memoryCache.size());
}
Also used : JRTServerConfigRequest(com.yahoo.vespa.config.protocol.JRTServerConfigRequest) Test(org.junit.Test)

Example 2 with JRTServerConfigRequest

use of com.yahoo.vespa.config.protocol.JRTServerConfigRequest in project vespa by vespa-engine.

the class ConfigProxyRpcServer method notifyTargetInvalid.

/**
 * Removes invalid targets (closed client connections) from delayedResponsesQueue.
 *
 * @param target a Target that has become invalid (i.e, client has closed connection)
 */
@Override
public void notifyTargetInvalid(Target target) {
    log.log(LogLevel.DEBUG, () -> "Target invalid " + target);
    for (Iterator<DelayedResponse> it = proxyServer.delayedResponses.responses().iterator(); it.hasNext(); ) {
        DelayedResponse delayed = it.next();
        JRTServerConfigRequest request = delayed.getRequest();
        if (request.getRequest().target().equals(target)) {
            log.log(LogLevel.DEBUG, () -> "Removing " + request.getShortDescription());
            it.remove();
        }
    }
// TODO: Could we also cancel active getConfig requests upstream if the client was the only one
// requesting this config?
}
Also used : JRTServerConfigRequest(com.yahoo.vespa.config.protocol.JRTServerConfigRequest)

Example 3 with JRTServerConfigRequest

use of com.yahoo.vespa.config.protocol.JRTServerConfigRequest 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 4 with JRTServerConfigRequest

use of com.yahoo.vespa.config.protocol.JRTServerConfigRequest in project vespa by vespa-engine.

the class DelayedResponseTest method basic.

@Test
public void basic() {
    ConfigTester tester = new ConfigTester();
    final long returnTime = System.currentTimeMillis();
    final long timeout = 1;
    final String configName = "foo";
    final JRTServerConfigRequest request = tester.createRequest(configName, configId, namespace, timeout);
    DelayedResponse delayedResponse = new DelayedResponse(request, returnTime);
    assertThat(delayedResponse.getRequest(), is(request));
    assertThat(delayedResponse.getReturnTime(), is(returnTime));
    assertTrue(delayedResponse.getDelay(TimeUnit.SECONDS) < returnTime);
    DelayedResponse before = new DelayedResponse(request, returnTime - 1000L);
    DelayedResponse after = new DelayedResponse(request, returnTime + 1000L);
    assertThat(delayedResponse.compareTo(delayedResponse), is(0));
    assertThat(delayedResponse.compareTo(before), is(1));
    assertThat(delayedResponse.compareTo(after), is(-1));
    assertThat(delayedResponse.compareTo(new Delayed() {

        @Override
        public long getDelay(TimeUnit unit) {
            return 0;
        }

        @Override
        public int compareTo(Delayed o) {
            return 0;
        }
    }), is(0));
}
Also used : JRTServerConfigRequest(com.yahoo.vespa.config.protocol.JRTServerConfigRequest) Delayed(java.util.concurrent.Delayed) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Example 5 with JRTServerConfigRequest

use of com.yahoo.vespa.config.protocol.JRTServerConfigRequest in project vespa by vespa-engine.

the class GetConfigProcessorTest method testSentinelConfig.

@Test
public void testSentinelConfig() {
    MockRpc rpc = new MockRpc(13337, false);
    // should be a sentinel config, but it does not matter for this test
    rpc.response = new MockConfigResponse("foo");
    // one tenant, which has host1 assigned
    boolean pretentToHaveLoadedApplications = true;
    TenantName testTenant = TenantName.from("test");
    rpc.onTenantCreate(testTenant, new MockTenantProvider(pretentToHaveLoadedApplications));
    rpc.hostsUpdated(testTenant, Collections.singleton("host1"));
    {
        // a config is returned normally
        JRTServerConfigRequest req = createV3SentinelRequest("host1");
        GetConfigProcessor proc = new GetConfigProcessor(rpc, req, false);
        proc.run();
        assertTrue(rpc.tryResolveConfig);
        assertTrue(rpc.tryRespond);
        assertThat(rpc.errorCode, is(0));
    }
    rpc.resetChecks();
    // host1 is replaced by host2 for this tenant
    rpc.hostsUpdated(testTenant, Collections.singleton("host2"));
    {
        // this causes us to get an empty config instead of normal config resolution
        JRTServerConfigRequest req = createV3SentinelRequest("host1");
        GetConfigProcessor proc = new GetConfigProcessor(rpc, req, false);
        proc.run();
        // <-- no normal config resolution happening
        assertFalse(rpc.tryResolveConfig);
        assertTrue(rpc.tryRespond);
        assertThat(rpc.errorCode, is(0));
    }
}
Also used : JRTServerConfigRequest(com.yahoo.vespa.config.protocol.JRTServerConfigRequest) GetConfigProcessor(com.yahoo.vespa.config.server.rpc.GetConfigProcessor) MockRpc(com.yahoo.vespa.config.server.rpc.MockRpc) TenantName(com.yahoo.config.provision.TenantName) MockTenantProvider(com.yahoo.vespa.config.server.tenant.MockTenantProvider) Test(org.junit.Test)

Aggregations

JRTServerConfigRequest (com.yahoo.vespa.config.protocol.JRTServerConfigRequest)12 Test (org.junit.Test)8 TenantName (com.yahoo.config.provision.TenantName)1 ConfigCacheKey (com.yahoo.vespa.config.ConfigCacheKey)1 RawConfig (com.yahoo.vespa.config.RawConfig)1 GetConfigContext (com.yahoo.vespa.config.server.GetConfigContext)1 GetConfigProcessor (com.yahoo.vespa.config.server.rpc.GetConfigProcessor)1 MockRpc (com.yahoo.vespa.config.server.rpc.MockRpc)1 MockTenantProvider (com.yahoo.vespa.config.server.tenant.MockTenantProvider)1 Date (java.util.Date)1 Delayed (java.util.concurrent.Delayed)1 TimeUnit (java.util.concurrent.TimeUnit)1