diff options
Diffstat (limited to 'configserver')
3 files changed, 31 insertions, 0 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java index acc195729e0..9533f04107d 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java @@ -45,6 +45,7 @@ import com.yahoo.vespa.config.server.application.Application; import com.yahoo.vespa.config.server.application.ApplicationCuratorDatabase; import com.yahoo.vespa.config.server.application.ApplicationData; import com.yahoo.vespa.config.server.application.ApplicationReindexing; +import com.yahoo.vespa.config.server.application.ApplicationReindexing.Status; import com.yahoo.vespa.config.server.application.ApplicationVersions; import com.yahoo.vespa.config.server.application.ClusterReindexing; import com.yahoo.vespa.config.server.application.ClusterReindexingStatusClient; @@ -128,6 +129,7 @@ import static com.yahoo.vespa.config.server.tenant.TenantRepository.HOSTED_VESPA import static com.yahoo.vespa.curator.Curator.CompletionWaiter; import static com.yahoo.yolean.Exceptions.uncheck; import static java.nio.file.Files.readAttributes; +import static java.util.Comparator.naturalOrder; /** * The API for managing applications. @@ -468,6 +470,17 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return Optional.of(createTime); } + @Override + public boolean readiedReindexingAfter(ApplicationId id, Instant instant) { + Tenant tenant = tenantRepository.getTenant(id.tenant()); + if (tenant == null) return false; + + return tenant.getApplicationRepo().database().readReindexingStatus(id) + .flatMap(ApplicationReindexing::lastReadiedAt) + .map(readiedAt -> readiedAt.isAfter(instant)) + .orElse(false); + } + public ApplicationId activate(Tenant tenant, long sessionId, TimeoutBudget timeoutBudget, diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationReindexing.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationReindexing.java index 5ecc7e6c8aa..4c32cccdf20 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationReindexing.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationReindexing.java @@ -6,11 +6,14 @@ import com.yahoo.vespa.config.server.maintenance.ReindexingMaintainer; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; +import static java.util.Comparator.naturalOrder; + /** * Pending reindexing: convergence to the stored config generation allows reindexing to start. * Ready reindexing: reindexing may start after this timestamp. @@ -94,6 +97,16 @@ public class ApplicationReindexing implements Reindexing { return Optional.ofNullable(clusters.get(clusterName)).map(cluster -> cluster.ready().get(documentType)); } + /** Instant at which reindexing in this was last readied, unless no reindexing is still pending, in which case this is empty. */ + public Optional<Instant> lastReadiedAt() { + if ( ! enabled) return Optional.empty(); + if (clusters.values().stream().anyMatch(cluster -> ! cluster.pending().isEmpty())) return Optional.empty(); + return clusters.values().stream() + .flatMap(cluster -> cluster.ready().values().stream()) + .map(Reindexing.Status::ready) + .max(naturalOrder()); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/application/ApplicationReindexingTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/application/ApplicationReindexingTest.java index 80ac28e9dbc..972bd86d752 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/application/ApplicationReindexingTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/application/ApplicationReindexingTest.java @@ -41,6 +41,11 @@ public class ApplicationReindexingTest { assertEquals(Optional.empty(), reindexing.status("three", "a")); + assertEquals(Optional.empty(), + reindexing.lastReadiedAt()); + assertEquals(Optional.of(Instant.ofEpochMilli(3)), + reindexing.withoutPending("two", "b").lastReadiedAt()); + // Remove "a" in "one", and "one" entirely. assertEquals(Optional.empty(), reindexing.without("one", "a").status("one", "a")); |