diff options
author | Harald Musum <musum@yahooinc.com> | 2022-01-20 09:41:28 +0100 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-01-20 09:41:28 +0100 |
commit | f1567c72ad6250761cdc8365983f20d14f61ee65 (patch) | |
tree | da923aca37037eef23efac08f4fcfffbd81f5da8 /configserver | |
parent | ba2e0756be5266872f8dc81043b156660c7b6cd2 (diff) |
Use clock when available
Diffstat (limited to 'configserver')
4 files changed, 24 insertions, 16 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java index 57e49ef3e8d..8d51a91bc3a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java @@ -17,6 +17,7 @@ import com.yahoo.vespa.config.server.version.VersionState; import com.yahoo.vespa.flags.FlagSource; import com.yahoo.yolean.Exceptions; +import java.time.Clock; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; @@ -73,6 +74,7 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable private final RedeployingApplicationsFails exitIfRedeployingApplicationsFails; private final ExecutorService rpcServerExecutor; private final ConfigServerMaintenance configServerMaintenance; + private final Clock clock; @SuppressWarnings("unused") // Injected component @Inject @@ -83,21 +85,22 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable applicationRepository.configserverConfig().hostedVespa() ? VipStatusMode.VIP_STATUS_FILE : VipStatusMode.VIP_STATUS_PROGRAMMATICALLY, - flagSource, convergence); + flagSource, convergence, Clock.systemUTC()); } // For testing only ConfigServerBootstrap(ApplicationRepository applicationRepository, RpcServer server, VersionState versionState, StateMonitor stateMonitor, VipStatus vipStatus, VipStatusMode vipStatusMode, - FlagSource flagSource, ConfigConvergenceChecker convergence) { + FlagSource flagSource, ConfigConvergenceChecker convergence, Clock clock) { this(applicationRepository, server, versionState, stateMonitor, vipStatus, - FOR_TESTING_NO_BOOTSTRAP_OF_APPS, CONTINUE, vipStatusMode, flagSource, convergence); + FOR_TESTING_NO_BOOTSTRAP_OF_APPS, CONTINUE, vipStatusMode, flagSource, convergence, clock); } private ConfigServerBootstrap(ApplicationRepository applicationRepository, RpcServer server, VersionState versionState, StateMonitor stateMonitor, VipStatus vipStatus, Mode mode, RedeployingApplicationsFails exitIfRedeployingApplicationsFails, - VipStatusMode vipStatusMode, FlagSource flagSource, ConfigConvergenceChecker convergence) { + VipStatusMode vipStatusMode, FlagSource flagSource, ConfigConvergenceChecker convergence, + Clock clock) { this.applicationRepository = applicationRepository; this.server = server; this.versionState = versionState; @@ -107,6 +110,7 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable this.maxDurationOfRedeployment = Duration.ofSeconds(configserverConfig.maxDurationOfBootstrap()); this.sleepTimeWhenRedeployingFails = Duration.ofSeconds(configserverConfig.sleepTimeWhenRedeployingFails()); this.exitIfRedeployingApplicationsFails = exitIfRedeployingApplicationsFails; + this.clock = clock; rpcServerExecutor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("config server RPC server")); configServerMaintenance = new ConfigServerMaintenance(configserverConfig, @@ -197,8 +201,8 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable private void startRpcServerWithFileDistribution() { rpcServerExecutor.execute(server); - Instant end = Instant.now().plus(Duration.ofSeconds(10)); - while (!server.isRunning() && Instant.now().isBefore(end)) { + Instant end = clock.instant().plus(Duration.ofSeconds(10)); + while (!server.isRunning() && clock.instant().isBefore(end)) { try { Thread.sleep(10); } catch (InterruptedException e) { @@ -220,7 +224,7 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable } private void redeployAllApplications() throws InterruptedException { - Instant end = Instant.now().plus(maxDurationOfRedeployment); + Instant end = clock.instant().plus(maxDurationOfRedeployment); List<ApplicationId> applicationsToRedeploy = applicationRepository.listApplications(); Collections.shuffle(applicationsToRedeploy); long failCount = 0; @@ -233,7 +237,7 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable log.log(Level.INFO, "Redeployment of " + applicationsToRedeploy + " not finished, will retry in " + sleepTime); Thread.sleep(sleepTime.toMillis()); } - } while ( ! applicationsToRedeploy.isEmpty() && Instant.now().isBefore(end)); + } while ( ! applicationsToRedeploy.isEmpty() && clock.instant().isBefore(end)); if ( ! applicationsToRedeploy.isEmpty()) throw new RuntimeException("Redeploying applications not finished after " + maxDurationOfRedeployment + @@ -296,11 +300,11 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable } private void logProgress(LogState logState, int failedDeployments, int finishedDeployments) { - if ( ! Duration.between(logState.lastLogged, Instant.now()).minus(Duration.ofSeconds(10)).isNegative() + if ( ! Duration.between(logState.lastLogged, clock.instant()).minus(Duration.ofSeconds(10)).isNegative() && (logState.failedDeployments != failedDeployments || logState.finishedDeployments != finishedDeployments)) { log.log(Level.INFO, () -> finishedDeployments + " of " + logState.applicationCount + " apps redeployed " + "(" + failedDeployments + " failed)"); - logState.update(Instant.now(), failedDeployments, finishedDeployments); + logState.update(clock.instant(), failedDeployments, finishedDeployments); } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java index 98ddf702a7f..937ec2bb0e7 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java @@ -472,7 +472,7 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica // If some are missing, quorum is enough, but wait for all up to 5 seconds before returning if (respondents.size() >= barrierMemberCount()) { if (gotQuorumTime.isBefore(startTime)) - gotQuorumTime = Instant.now(); + gotQuorumTime = clock.instant(); // Give up if more than some time has passed since we got quorum, otherwise continue if (Duration.between(Instant.now(), gotQuorumTime.plus(waitForAll)).isNegative()) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java index b3c2fa2e300..7d53c383cf5 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java @@ -330,7 +330,7 @@ public class TenantRepository { private Tenant createTenant(TenantName tenantName, Instant created) { if (tenants.containsKey(tenantName)) return getTenant(tenantName); - Instant start = Instant.now(); + Instant start = clock.instant(); log.log(Level.FINE, () -> "Adding tenant '" + tenantName); TenantApplications applicationRepo = new TenantApplications(tenantName, @@ -375,7 +375,7 @@ public class TenantRepository { configDefinitionRepo, zookeeperServerConfig.juteMaxBuffer()); log.log(Level.INFO, "Adding tenant '" + tenantName + "'" + ", created " + created + - ". Bootstrapping in " + Duration.between(start, Instant.now())); + ". Bootstrapping in " + Duration.between(start, clock.instant())); Tenant tenant = new Tenant(tenantName, sessionRepository, applicationRepo, created); createAndWriteTenantMetaData(tenant); tenants.putIfAbsent(tenantName, tenant); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java index 852f6ffba8f..67613d5a806 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java @@ -18,6 +18,7 @@ import com.yahoo.container.handler.VipStatus; import com.yahoo.container.jdisc.state.StateMonitor; import com.yahoo.docproc.jdisc.metric.NullMetric; import com.yahoo.path.Path; +import com.yahoo.test.ManualClock; import com.yahoo.text.Utf8; import com.yahoo.vespa.config.server.application.ConfigConvergenceChecker; import com.yahoo.vespa.config.server.deploy.DeployTester; @@ -42,6 +43,7 @@ import java.util.Optional; import java.util.function.BooleanSupplier; import java.util.stream.Collectors; +import static com.yahoo.vespa.config.server.ConfigServerBootstrap.VipStatusMode; import static com.yahoo.vespa.config.server.ConfigServerBootstrap.VipStatusMode.VIP_STATUS_FILE; import static com.yahoo.vespa.config.server.ConfigServerBootstrap.VipStatusMode.VIP_STATUS_PROGRAMMATICALLY; import static com.yahoo.vespa.config.server.deploy.DeployTester.createHostedModelFactory; @@ -56,6 +58,7 @@ import static org.junit.Assert.assertTrue; public class ConfigServerBootstrapTest { private final MockCurator curator = new MockCurator(); + private final ManualClock clock = new ManualClock(); @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -177,7 +180,7 @@ public class ConfigServerBootstrapTest { waitUntil(() -> bootstrap.vipStatus().isInRotation(), "failed waiting for server to be in rotation"); } - private ConfigServerBootstrap createBootstrap(DeployTester tester, RpcServer rpcServer, ConfigServerBootstrap.VipStatusMode vipStatusProgrammatically) throws IOException { + private ConfigServerBootstrap createBootstrap(DeployTester tester, RpcServer rpcServer, VipStatusMode vipStatusMode) throws IOException { VersionState versionState = createVersionState(); assertTrue(versionState.isUpgraded()); @@ -188,9 +191,10 @@ public class ConfigServerBootstrapTest { versionState, stateMonitor, vipStatus, - vipStatusProgrammatically, + vipStatusMode, new InMemoryFlagSource(), - new ConfigConvergenceChecker()); + new ConfigConvergenceChecker(), + clock); } private void waitUntil(BooleanSupplier booleanSupplier, String messageIfWaitingFails) throws InterruptedException { |