diff options
7 files changed, 46 insertions, 6 deletions
diff --git a/configserver/pom.xml b/configserver/pom.xml index a9cade47446..f932a963d14 100644 --- a/configserver/pom.xml +++ b/configserver/pom.xml @@ -168,6 +168,12 @@ </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> + <artifactId>flags</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> <artifactId>serviceview</artifactId> <version>${project.version}</version> <scope>compile</scope> diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java index 5987532c004..ad12c5c9e24 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java @@ -13,6 +13,7 @@ import com.yahoo.vespa.config.server.session.SessionPreparer; import com.yahoo.vespa.config.server.tenant.TenantListener; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.curator.Curator; +import com.yahoo.vespa.flags.FlagSource; import java.time.Clock; import java.util.Optional; @@ -40,5 +41,6 @@ public interface GlobalComponentRegistry { Zone getZone(); Clock getClock(); ConfigServerDB getConfigServerDB(); + FlagSource getFlagSource(); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java index 587eb5857bf..e9ebe954799 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java @@ -16,6 +16,7 @@ import com.yahoo.vespa.config.server.session.SessionPreparer; import com.yahoo.vespa.config.server.tenant.TenantListener; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.curator.Curator; +import com.yahoo.vespa.flags.FlagSource; import java.time.Clock; import java.util.Optional; @@ -41,6 +42,7 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry private final Optional<Provisioner> hostProvisioner; private final Zone zone; private final ConfigServerDB configServerDB; + private final FlagSource flagSource; @SuppressWarnings("WeakerAccess") @Inject @@ -57,7 +59,8 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry HostRegistries hostRegistries, HostProvisionerProvider hostProvisionerProvider, Zone zone, - ConfigServerDB configServerDB) { + ConfigServerDB configServerDB, + FlagSource flagSource) { this.curator = curator; this.configCurator = configCurator; this.metrics = metrics; @@ -72,6 +75,7 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry this.hostProvisioner = hostProvisionerProvider.getHostProvisioner(); this.zone = zone; this.configServerDB = configServerDB; + this.flagSource = flagSource; } @Override @@ -114,4 +118,7 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry @Override public ConfigServerDB getConfigServerDB() { return configServerDB; } + + @Override + public FlagSource getFlagSource() { return flagSource; } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java index 06a4c12fb32..032bb88eaaa 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java @@ -23,6 +23,9 @@ import com.yahoo.vespa.config.server.UnknownConfigDefinitionException; import com.yahoo.vespa.config.server.modelfactory.ModelResult; import com.yahoo.vespa.config.server.monitoring.MetricUpdater; import com.yahoo.vespa.config.util.ConfigUtils; +import com.yahoo.vespa.flags.FeatureFlag; +import com.yahoo.vespa.flags.FileFlagSource; +import com.yahoo.vespa.flags.FlagSource; import java.util.Objects; import java.util.Set; @@ -44,9 +47,15 @@ public class Application implements ModelResult { private final ServerCache cache; private final MetricUpdater metricUpdater; private final ApplicationId app; + private final FeatureFlag useConfigServerCache; public Application(Model model, ServerCache cache, long appGeneration, boolean internalRedeploy, Version vespaVersion, MetricUpdater metricUpdater, ApplicationId app) { + this(model, cache, appGeneration, internalRedeploy, vespaVersion, metricUpdater, app, new FileFlagSource()); + } + + public Application(Model model, ServerCache cache, long appGeneration, boolean internalRedeploy, + Version vespaVersion, MetricUpdater metricUpdater, ApplicationId app, FlagSource flagSource) { Objects.requireNonNull(model, "The model cannot be null"); this.model = model; this.cache = cache; @@ -55,6 +64,7 @@ public class Application implements ModelResult { this.vespaVersion = vespaVersion; this.metricUpdater = metricUpdater; this.app = app; + this.useConfigServerCache = new FeatureFlag("use-config-server-cache", true, flagSource); } /** @@ -109,7 +119,7 @@ public class Application implements ModelResult { debug("Resolving config " + cacheKey); } - if ( ! req.noCache()) { + if (useCache(req)) { ConfigResponse config = cache.get(cacheKey); if (config != null) { if (logDebug()) { @@ -136,7 +146,7 @@ public class Application implements ModelResult { ConfigResponse configResponse = responseFactory.createResponse(payload, def.getCNode(), appGeneration, internalRedeploy); metricUpdater.incrementProcTime(System.currentTimeMillis() - start); - if ( ! req.noCache()) { + if (useCache(req)) { cache.put(cacheKey, configResponse, configResponse.getConfigMd5()); metricUpdater.setCacheConfigElems(cache.configElems()); metricUpdater.setCacheChecksumElems(cache.checkSumElems()); @@ -144,6 +154,13 @@ public class Application implements ModelResult { return configResponse; } + private boolean useCache(GetConfigRequest request) { + if (request.noCache()) + return false; + else + return useConfigServerCache.value(); + } + private boolean logDebug() { return log.isLoggable(LogLevel.DEBUG); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java index 89c5cedb05c..103eec14b36 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java @@ -27,6 +27,7 @@ import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.session.SessionZooKeeperClient; import com.yahoo.vespa.config.server.session.SilentDeployLogger; import com.yahoo.vespa.curator.Curator; +import com.yahoo.vespa.flags.FlagSource; import java.net.URI; import java.time.Instant; @@ -51,6 +52,7 @@ public class ActivatedModelsBuilder extends ModelsBuilder<Application> { private final Metrics metrics; private final Curator curator; private final DeployLogger logger; + private final FlagSource flagSource; public ActivatedModelsBuilder(TenantName tenant, long appGeneration, @@ -68,6 +70,7 @@ public class ActivatedModelsBuilder extends ModelsBuilder<Application> { this.metrics = globalComponentRegistry.getMetrics(); this.curator = globalComponentRegistry.getCurator(); this.logger = new SilentDeployLogger(); + this.flagSource = globalComponentRegistry.getFlagSource(); } @Override @@ -100,7 +103,8 @@ public class ActivatedModelsBuilder extends ModelsBuilder<Application> { applicationPackage.getMetaData().isInternalRedeploy(), modelFactory.version(), applicationMetricUpdater, - applicationId); + applicationId, + flagSource); } private static <T> Optional<T> getForVersionOrLatest(Map<Version, T> map, Version version) { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java index 324f7c5de00..b2e911c47a4 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java @@ -18,6 +18,7 @@ import com.yahoo.vespa.config.server.session.*; import com.yahoo.vespa.curator.mock.MockCurator; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.curator.Curator; +import com.yahoo.vespa.flags.FileFlagSource; import com.yahoo.vespa.model.VespaModelFactory; import org.junit.Before; import org.junit.Rule; @@ -74,7 +75,7 @@ public class InjectedGlobalComponentRegistryTest { globalComponentRegistry = new InjectedGlobalComponentRegistry(curator, configCurator, metrics, modelFactoryRegistry, sessionPreparer, rpcServer, configserverConfig, generationCounter, defRepo, permanentApplicationPackage, hostRegistries, hostProvisionerProvider, zone, - new ConfigServerDB(configserverConfig)); + new ConfigServerDB(configserverConfig), new FileFlagSource()); } @Test diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java b/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java index 2c89678c90f..65c83633bbb 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java @@ -21,6 +21,8 @@ import com.yahoo.vespa.config.server.tenant.TenantRequestHandlerTest; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; +import com.yahoo.vespa.flags.FileFlagSource; +import com.yahoo.vespa.flags.FlagSource; import com.yahoo.vespa.model.VespaModelFactory; import java.time.Clock; @@ -196,7 +198,8 @@ public class TestComponentRegistry implements GlobalComponentRegistry { public Clock getClock() { return clock;} @Override public ConfigServerDB getConfigServerDB() { return configServerDB;} - + @Override + public FlagSource getFlagSource() { return new FileFlagSource(); } public FileDistributionFactory getFileDistributionFactory() { return fileDistributionFactory; } |