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());
}
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?
}
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));
}
}
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));
}
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));
}
}
Aggregations