From 6e06c8d9cb0a8a05009be93f9d31005827443783 Mon Sep 17 00:00:00 2001 From: HÃ¥kon Hallingstad Date: Sat, 4 Nov 2023 12:09:26 +0100 Subject: Evaluate flags referenced multiple times at the start of prepare --- .../vespa/hosted/provision/NodeRepository.java | 14 ++--- .../provision/autoscale/AllocatableResources.java | 28 ++++++---- .../provision/autoscale/AllocationOptimizer.java | 15 +++--- .../hosted/provision/autoscale/Autoscaler.java | 7 ++- .../hosted/provision/autoscale/ClusterModel.java | 17 ++++-- .../vespa/hosted/provision/autoscale/Limits.java | 7 +-- .../maintenance/HostCapacityMaintainer.java | 63 +++++++++++----------- .../provision/maintenance/HostFlavorUpgrader.java | 4 +- .../provision/provisioning/CapacityPolicies.java | 12 ++--- .../provisioning/ClusterAllocationFeatures.java | 29 ++++++++++ .../provision/provisioning/HostProvisioner.java | 5 +- .../provision/provisioning/NodeAllocation.java | 16 +++--- .../provision/provisioning/NodeCandidate.java | 6 +-- .../provision/provisioning/NodePrioritizer.java | 8 +-- .../provisioning/NodeRepositoryProvisioner.java | 50 +++++++++-------- .../provision/provisioning/NodeResourceLimits.java | 16 +++--- .../hosted/provision/provisioning/Preparer.java | 53 ++++++++---------- .../provision/restapi/ApplicationSerializer.java | 21 +++++--- .../provision/restapi/NodesV2ApiHandler.java | 6 ++- .../provision/testutils/MockHostProvisioner.java | 8 ++- 20 files changed, 222 insertions(+), 163 deletions(-) create mode 100644 node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ClusterAllocationFeatures.java (limited to 'node-repository/src/main/java/com') diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java index dfbe41e31d7..9d597a63fec 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java @@ -12,9 +12,6 @@ import com.yahoo.config.provision.Zone; import com.yahoo.config.provisioning.NodeRepositoryConfig; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.flags.FlagSource; -import com.yahoo.vespa.flags.JacksonFlag; -import com.yahoo.vespa.flags.PermanentFlags; -import com.yahoo.vespa.flags.custom.SharedHost; import com.yahoo.vespa.hosted.provision.Node.State; import com.yahoo.vespa.hosted.provision.applications.Applications; import com.yahoo.vespa.hosted.provision.archive.ArchiveUriManager; @@ -29,6 +26,7 @@ import com.yahoo.vespa.hosted.provision.persistence.CuratorDb; import com.yahoo.vespa.hosted.provision.persistence.DnsNameResolver; import com.yahoo.vespa.hosted.provision.persistence.JobControlFlags; import com.yahoo.vespa.hosted.provision.persistence.NameResolver; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import com.yahoo.vespa.hosted.provision.provisioning.ContainerImages; import com.yahoo.vespa.hosted.provision.provisioning.FirmwareChecks; import com.yahoo.vespa.hosted.provision.provisioning.HostResourcesCalculator; @@ -67,7 +65,6 @@ public class NodeRepository extends AbstractComponent { private final MetricsDb metricsDb; private final Orchestrator orchestrator; private final int spareCount; - private final JacksonFlag sharedHosts; /** * Creates a node repository from a zookeeper provider. @@ -141,7 +138,6 @@ public class NodeRepository extends AbstractComponent { this.metricsDb = metricsDb; this.orchestrator = orchestrator; this.spareCount = spareCount; - this.sharedHosts = PermanentFlags.SHARED_HOST.bindTo(flagSource()); nodes.rewrite(); } @@ -202,8 +198,8 @@ public class NodeRepository extends AbstractComponent { public int spareCount() { return spareCount; } /** Returns whether nodes must be allocated to hosts that are exclusive to the cluster type. */ - public boolean exclusiveClusterType(ClusterSpec cluster) { - return sharedHosts.value().hasClusterType(cluster.type().name()); + public boolean exclusiveClusterType(ClusterAllocationFeatures features, ClusterSpec cluster) { + return features.sharedHost().hasClusterType(cluster.type().name()); } /** @@ -211,10 +207,10 @@ public class NodeRepository extends AbstractComponent { * Exclusive allocation requires that the wanted node resources matches the advertised resources of the node * perfectly. */ - public boolean exclusiveAllocation(ClusterSpec clusterSpec) { + public boolean exclusiveAllocation(ClusterAllocationFeatures features, ClusterSpec clusterSpec) { return clusterSpec.isExclusive() || ( clusterSpec.type().isContainer() && zone.system().isPublic() && !zone.environment().isTest() ) || - ( !zone().cloud().allowHostSharing() && !sharedHosts.value().supportsClusterType(clusterSpec.type().name())); + ( !zone().cloud().allowHostSharing() && !features.sharedHost().supportsClusterType(clusterSpec.type().name())); } /** Whether the nodes of this cluster must be running on hosts that are specifically provisioned for the application. */ diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableResources.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableResources.java index 544436dc902..7c8501c05b9 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableResources.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableResources.java @@ -9,6 +9,7 @@ import com.yahoo.config.provision.NodeResources; import com.yahoo.vespa.hosted.provision.Node; import com.yahoo.vespa.hosted.provision.NodeList; import com.yahoo.vespa.hosted.provision.NodeRepository; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import java.time.Duration; import java.util.List; @@ -33,12 +34,13 @@ public class AllocatableResources { private final double fulfilment; /** Fake allocatable resources from requested capacity */ - public AllocatableResources(ClusterResources requested, + public AllocatableResources(ClusterAllocationFeatures features, + ClusterResources requested, ClusterSpec clusterSpec, NodeRepository nodeRepository) { this.nodes = requested.nodes(); this.groups = requested.groups(); - this.realResources = nodeRepository.resourcesCalculator().requestToReal(requested.nodeResources(), nodeRepository.exclusiveAllocation(clusterSpec), false); + this.realResources = nodeRepository.resourcesCalculator().requestToReal(requested.nodeResources(), nodeRepository.exclusiveAllocation(features, clusterSpec), false); this.advertisedResources = requested.nodeResources(); this.clusterSpec = clusterSpec; this.fulfilment = 1; @@ -167,7 +169,8 @@ public class AllocatableResources { .withBandwidthGbps(sum.bandwidthGbps() / nodes.size()); } - public static Optional from(ClusterResources wantedResources, + public static Optional from(ClusterAllocationFeatures features, + ClusterResources wantedResources, ApplicationId applicationId, ClusterSpec clusterSpec, Limits applicationLimits, @@ -175,10 +178,11 @@ public class AllocatableResources { ClusterModel model, NodeRepository nodeRepository) { var systemLimits = nodeRepository.nodeResourceLimits(); - boolean exclusive = nodeRepository.exclusiveAllocation(clusterSpec); + boolean exclusive = nodeRepository.exclusiveAllocation(features, clusterSpec); if (! exclusive) { // We decide resources: Add overhead to what we'll request (advertised) to make sure real becomes (at least) cappedNodeResources - var allocatableResources = calculateAllocatableResources(wantedResources, + var allocatableResources = calculateAllocatableResources(features, + wantedResources, nodeRepository, applicationId, clusterSpec, @@ -189,8 +193,9 @@ public class AllocatableResources { var worstCaseRealResources = nodeRepository.resourcesCalculator().requestToReal(allocatableResources.advertisedResources, exclusive, false); - if ( ! systemLimits.isWithinRealLimits(worstCaseRealResources, applicationId, clusterSpec)) { - allocatableResources = calculateAllocatableResources(wantedResources, + if ( ! systemLimits.isWithinRealLimits(features, worstCaseRealResources, applicationId, clusterSpec)) { + allocatableResources = calculateAllocatableResources(features, + wantedResources, nodeRepository, applicationId, clusterSpec, @@ -199,7 +204,7 @@ public class AllocatableResources { false); } - if ( ! systemLimits.isWithinRealLimits(allocatableResources.realResources, applicationId, clusterSpec)) + if ( ! systemLimits.isWithinRealLimits(features, allocatableResources.realResources, applicationId, clusterSpec)) return Optional.empty(); if ( ! anySatisfies(allocatableResources.realResources, availableRealHostResources)) return Optional.empty(); @@ -228,7 +233,7 @@ public class AllocatableResources { } if ( ! between(applicationLimits.min().nodeResources(), applicationLimits.max().nodeResources(), advertisedResources)) continue; - if ( ! systemLimits.isWithinRealLimits(realResources, applicationId, clusterSpec)) continue; + if ( ! systemLimits.isWithinRealLimits(features, realResources, applicationId, clusterSpec)) continue; var candidate = new AllocatableResources(wantedResources.with(realResources), advertisedResources, @@ -251,7 +256,8 @@ public class AllocatableResources { } } - private static AllocatableResources calculateAllocatableResources(ClusterResources wantedResources, + private static AllocatableResources calculateAllocatableResources(ClusterAllocationFeatures features, + ClusterResources wantedResources, NodeRepository nodeRepository, ApplicationId applicationId, ClusterSpec clusterSpec, @@ -263,7 +269,7 @@ public class AllocatableResources { advertisedResources = systemLimits.enlargeToLegal(advertisedResources, applicationId, clusterSpec, exclusive, true); // Ask for something legal advertisedResources = applicationLimits.cap(advertisedResources); // Overrides other conditions, even if it will then fail var realResources = nodeRepository.resourcesCalculator().requestToReal(advertisedResources, exclusive, bestCase); // What we'll really get - if ( ! systemLimits.isWithinRealLimits(realResources, applicationId, clusterSpec) + if ( ! systemLimits.isWithinRealLimits(features, realResources, applicationId, clusterSpec) && advertisedResources.storageType() == NodeResources.StorageType.any) { // Since local disk reserves some of the storage, try to constrain to remote disk advertisedResources = advertisedResources.with(NodeResources.StorageType.remote); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocationOptimizer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocationOptimizer.java index ff30f9d6163..7c09e3fa041 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocationOptimizer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocationOptimizer.java @@ -5,6 +5,7 @@ import com.yahoo.config.provision.ClusterResources; import com.yahoo.config.provision.IntRange; import com.yahoo.config.provision.NodeResources; import com.yahoo.vespa.hosted.provision.NodeRepository; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import java.util.Optional; @@ -34,7 +35,8 @@ public class AllocationOptimizer { * @return the best allocation, if there are any possible legal allocations, fulfilling the target * fully or partially, within the limits */ - public Optional findBestAllocation(Load loadAdjustment, + public Optional findBestAllocation(ClusterAllocationFeatures features, + Load loadAdjustment, ClusterModel model, Limits limits) { if (limits.isEmpty()) @@ -42,12 +44,12 @@ public class AllocationOptimizer { new ClusterResources(maximumNodes, maximumNodes, NodeResources.unspecified()), IntRange.empty()); else - limits = atLeast(minimumNodes, limits).fullySpecified(model.current().clusterSpec(), nodeRepository, model.application().id()); + limits = atLeast(minimumNodes, limits).fullySpecified(features, model.current().clusterSpec(), nodeRepository, model.application().id()); Optional bestAllocation = Optional.empty(); var availableRealHostResources = nodeRepository.zone().cloud().dynamicProvisioning() ? nodeRepository.flavors().getFlavors().stream().map(flavor -> flavor.resources()).toList() : nodeRepository.nodes().list().hosts().stream().map(host -> host.flavor().resources()) - .map(hostResources -> maxResourcesOf(hostResources, model)) + .map(hostResources -> maxResourcesOf(features, hostResources, model)) .toList(); for (int groups = limits.min().groups(); groups <= limits.max().groups(); groups++) { for (int nodes = limits.min().nodes(); nodes <= limits.max().nodes(); nodes++) { @@ -57,7 +59,8 @@ public class AllocationOptimizer { groups, nodeResourcesWith(nodes, groups, limits, loadAdjustment, model)); - var allocatableResources = AllocatableResources.from(resources, + var allocatableResources = AllocatableResources.from(features, + resources, model.application().id(), model.current().clusterSpec(), limits, @@ -73,8 +76,8 @@ public class AllocationOptimizer { } /** Returns the max resources of a host one node may allocate. */ - private NodeResources maxResourcesOf(NodeResources hostResources, ClusterModel model) { - if (nodeRepository.exclusiveAllocation(model.clusterSpec())) return hostResources; + private NodeResources maxResourcesOf(ClusterAllocationFeatures features, NodeResources hostResources, ClusterModel model) { + if (nodeRepository.exclusiveAllocation(features, model.clusterSpec())) return hostResources; // static, shared hosts: Allocate at most half of the host cpu to simplify management return hostResources.withVcpu(hostResources.vcpu() / 2); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java index 738abddc31a..60fd75051fc 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java @@ -7,6 +7,7 @@ import com.yahoo.vespa.hosted.provision.NodeRepository; import com.yahoo.vespa.hosted.provision.applications.Application; import com.yahoo.vespa.hosted.provision.applications.Cluster; import com.yahoo.vespa.hosted.provision.autoscale.Autoscaling.Status; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import java.time.Duration; @@ -54,7 +55,9 @@ public class Autoscaler { } private Autoscaling autoscale(Application application, Cluster cluster, NodeList clusterNodes, Limits limits) { - var model = new ClusterModel(nodeRepository, + ClusterAllocationFeatures features = ClusterAllocationFeatures.from(nodeRepository.flagSource(), application.id(), clusterNodes.clusterSpec().vespaVersion()); + var model = new ClusterModel(features, + nodeRepository, application, clusterNodes.not().retired().clusterSpec(), cluster, @@ -73,7 +76,7 @@ public class Autoscaler { var loadAdjustment = model.loadAdjustment(); // Ensure we only scale down if we'll have enough headroom to not scale up again given a small load increase - var target = allocationOptimizer.findBestAllocation(loadAdjustment, model, limits); + var target = allocationOptimizer.findBestAllocation(features, loadAdjustment, model, limits); if (target.isEmpty()) return Autoscaling.dontScale(Status.insufficient, "No allocations are possible within configured limits", model); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ClusterModel.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ClusterModel.java index 4c5ace3d51a..891d90acc03 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ClusterModel.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ClusterModel.java @@ -8,6 +8,7 @@ import com.yahoo.vespa.hosted.provision.NodeRepository; import com.yahoo.vespa.hosted.provision.applications.Application; import com.yahoo.vespa.hosted.provision.applications.Cluster; import com.yahoo.vespa.hosted.provision.provisioning.CapacityPolicies; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import java.time.Clock; import java.time.Duration; @@ -46,6 +47,7 @@ public class ClusterModel { // TODO: Measure this, and only take it into account with queries private static final double fixedCpuCostFraction = 0.1; + private final ClusterAllocationFeatures features; private final NodeRepository nodeRepository; private final Application application; private final ClusterSpec clusterSpec; @@ -74,7 +76,8 @@ public class ClusterModel { private Double maxQueryGrowthRate = null; private OptionalDouble averageQueryRate = null; - public ClusterModel(NodeRepository nodeRepository, + public ClusterModel(ClusterAllocationFeatures features, + NodeRepository nodeRepository, Application application, ClusterSpec clusterSpec, Cluster cluster, @@ -82,6 +85,7 @@ public class ClusterModel { AllocatableResources current, MetricsDb metricsDb, Clock clock) { + this.features = features; this.nodeRepository = nodeRepository; this.application = application; this.clusterSpec = clusterSpec; @@ -96,7 +100,8 @@ public class ClusterModel { this.at = clock.instant(); } - ClusterModel(NodeRepository nodeRepository, + ClusterModel(ClusterAllocationFeatures features, + NodeRepository nodeRepository, Application application, ClusterSpec clusterSpec, Cluster cluster, @@ -106,6 +111,7 @@ public class ClusterModel { Duration allocationDuration, ClusterTimeseries clusterTimeseries, ClusterNodesTimeseries nodeTimeseries) { + this.features = features; this.nodeRepository = nodeRepository; this.application = application; this.clusterSpec = clusterSpec; @@ -169,7 +175,7 @@ public class ClusterModel { } public boolean isExclusive() { - return nodeRepository.exclusiveAllocation(clusterSpec); + return nodeRepository.exclusiveAllocation(features, clusterSpec); } /** Returns the relative load adjustment that should be made to this cluster given available measurements. */ @@ -432,11 +438,12 @@ public class ClusterModel { double averageReal() { if (nodes.isEmpty()) { // we're estimating - var initialResources = new CapacityPolicies(nodeRepository).specifyFully(cluster.minResources().nodeResources(), + var initialResources = new CapacityPolicies(nodeRepository).specifyFully(features, + cluster.minResources().nodeResources(), clusterSpec, application.id()); return nodeRepository.resourcesCalculator().requestToReal(initialResources, - nodeRepository.exclusiveAllocation(clusterSpec), + nodeRepository.exclusiveAllocation(features, clusterSpec), false).memoryGb(); } else { diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Limits.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Limits.java index ab93e585c88..d6c4e65c3f1 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Limits.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Limits.java @@ -10,6 +10,7 @@ import com.yahoo.config.provision.NodeResources; import com.yahoo.vespa.hosted.provision.NodeRepository; import com.yahoo.vespa.hosted.provision.applications.Cluster; import com.yahoo.vespa.hosted.provision.provisioning.CapacityPolicies; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import java.util.Objects; @@ -65,12 +66,12 @@ public class Limits { return resources; } - public Limits fullySpecified(ClusterSpec clusterSpec, NodeRepository nodeRepository, ApplicationId applicationId) { + public Limits fullySpecified(ClusterAllocationFeatures features, ClusterSpec clusterSpec, NodeRepository nodeRepository, ApplicationId applicationId) { if (this.isEmpty()) throw new IllegalStateException("Unspecified limits can not be made fully specified"); var capacityPolicies = new CapacityPolicies(nodeRepository); - return new Limits(capacityPolicies.specifyFully(min, clusterSpec, applicationId), - capacityPolicies.specifyFully(max, clusterSpec, applicationId), + return new Limits(capacityPolicies.specifyFully(features, min, clusterSpec, applicationId), + capacityPolicies.specifyFully(features, max, clusterSpec, applicationId), groupSize); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java index 108f8d77837..0a44c1e2438 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java @@ -13,10 +13,7 @@ import com.yahoo.config.provision.NodeType; import com.yahoo.jdisc.Metric; import com.yahoo.lang.MutableInteger; import com.yahoo.transaction.Mutex; -import com.yahoo.vespa.flags.BooleanFlag; -import com.yahoo.vespa.flags.FetchVector; import com.yahoo.vespa.flags.FlagSource; -import com.yahoo.vespa.flags.Flags; import com.yahoo.vespa.flags.ListFlag; import com.yahoo.vespa.flags.PermanentFlags; import com.yahoo.vespa.flags.custom.ClusterCapacity; @@ -28,6 +25,7 @@ import com.yahoo.vespa.hosted.provision.NodeRepository; import com.yahoo.vespa.hosted.provision.node.Agent; import com.yahoo.vespa.hosted.provision.node.History; import com.yahoo.vespa.hosted.provision.node.IP; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import com.yahoo.vespa.hosted.provision.provisioning.HostProvisionRequest; import com.yahoo.vespa.hosted.provision.provisioning.HostProvisioner; import com.yahoo.vespa.hosted.provision.provisioning.HostProvisioner.HostSharing; @@ -62,7 +60,7 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { private final HostProvisioner hostProvisioner; private final ListFlag preprovisionCapacityFlag; - private final BooleanFlag makeExclusiveFlag; + private final FlagSource flagSource; private final ProvisioningThrottler throttler; HostCapacityMaintainer(NodeRepository nodeRepository, @@ -73,7 +71,7 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { super(nodeRepository, interval, metric); this.hostProvisioner = hostProvisioner; this.preprovisionCapacityFlag = PermanentFlags.PREPROVISION_CAPACITY.bindTo(flagSource); - this.makeExclusiveFlag = Flags.MAKE_EXCLUSIVE.bindTo(flagSource); + this.flagSource = flagSource; this.throttler = new ProvisioningThrottler(nodeRepository, metric); } @@ -159,7 +157,10 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { } private List provision(NodeList nodeList) { - return provisionUntilNoDeficit(nodeList).stream() + ApplicationId application = ApplicationId.defaultId(); + var features = ClusterAllocationFeatures.from(flagSource, application, Vtag.currentVersion); + + return provisionUntilNoDeficit(features, application, nodeList).stream() .sorted(comparing(node -> node.history().events().stream() .map(History.Event::at) .min(naturalOrder()) @@ -190,13 +191,8 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { * @throws IllegalStateException if there was an algorithmic problem, and in case message * should be sufficient (avoid no stack trace). */ - private List provisionUntilNoDeficit(NodeList nodeList) { + private List provisionUntilNoDeficit(ClusterAllocationFeatures features, ApplicationId application, NodeList nodeList) { List preprovisionCapacity = preprovisionCapacityFlag.value(); - ApplicationId application = ApplicationId.defaultId(); - boolean makeExclusive = makeExclusiveFlag.with(FetchVector.Dimension.TENANT_ID, application.tenant().value()) - .with(FetchVector.Dimension.INSTANCE_ID, application.serializedForm()) - .with(FetchVector.Dimension.VESPA_VERSION, Vtag.currentVersion.toFullString()) - .value(); // Worst-case each ClusterCapacity in preprovisionCapacity will require an allocation. int maxProvisions = preprovisionCapacity.size(); @@ -204,7 +200,7 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { var nodesPlusProvisioned = new ArrayList<>(nodeList.asList()); for (int numProvisions = 0;; ++numProvisions) { var nodesPlusProvisionedPlusAllocated = new ArrayList<>(nodesPlusProvisioned); - Optional deficit = allocatePreprovisionCapacity(application, preprovisionCapacity, nodesPlusProvisionedPlusAllocated, makeExclusive); + Optional deficit = allocatePreprovisionCapacity(application, preprovisionCapacity, nodesPlusProvisionedPlusAllocated, features); if (deficit.isEmpty()) { return nodesPlusProvisionedPlusAllocated; } @@ -214,21 +210,22 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { } ClusterCapacity clusterCapacityDeficit = deficit.get(); - nodesPlusProvisioned.addAll(provisionHosts(clusterCapacityDeficit.count(), + nodesPlusProvisioned.addAll(provisionHosts(features, + clusterCapacityDeficit.count(), toNodeResources(clusterCapacityDeficit), Optional.ofNullable(clusterCapacityDeficit.clusterType()), nodeList)); } } - private List provisionHosts(int count, NodeResources nodeResources, Optional clusterType, NodeList allNodes) { + private List provisionHosts(ClusterAllocationFeatures features, int count, NodeResources nodeResources, Optional clusterType, NodeList allNodes) { try { if (throttler.throttle(allNodes, Agent.HostCapacityMaintainer)) { throw new NodeAllocationException("Host provisioning is being throttled", true); } Version osVersion = nodeRepository().osVersions().targetFor(NodeType.host).orElse(Version.emptyVersion); List provisionIndices = nodeRepository().database().readProvisionIndices(count); - HostSharing sharingMode = nodeRepository().exclusiveAllocation(asSpec(clusterType, 0)) ? HostSharing.exclusive : HostSharing.shared; + HostSharing sharingMode = nodeRepository().exclusiveAllocation(features, asSpec(clusterType, 0)) ? HostSharing.exclusive : HostSharing.shared; HostProvisionRequest request = new HostProvisionRequest(provisionIndices, NodeType.host, nodeResources, ApplicationId.defaultId(), osVersion, sharingMode, clusterType.map(ClusterSpec.Type::valueOf), Optional.empty(), @@ -236,15 +233,16 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { List hosts = new ArrayList<>(); Runnable waiter; try (var lock = nodeRepository().nodes().lockUnallocated()) { - waiter = hostProvisioner.provisionHosts(request, - resources -> true, - provisionedHosts -> { - hosts.addAll(provisionedHosts.stream() - .map(host -> host.generateHost(Duration.ZERO)) - .map(host -> host.withExclusiveToApplicationId(null)) - .toList()); - nodeRepository().nodes().addNodes(hosts, Agent.HostCapacityMaintainer); - }); + waiter = hostProvisioner.provisionHosts(features, + request, + resources -> true, + provisionedHosts -> { + hosts.addAll(provisionedHosts.stream() + .map(host -> host.generateHost(Duration.ZERO)) + .map(host -> host.withExclusiveToApplicationId(null)) + .toList()); + nodeRepository().nodes().addNodes(hosts, Agent.HostCapacityMaintainer); + }); } waiter.run(); return hosts; @@ -266,11 +264,11 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { private Optional allocatePreprovisionCapacity(ApplicationId application, List preprovisionCapacity, ArrayList mutableNodes, - boolean makeExclusive) { + ClusterAllocationFeatures features) { for (int clusterIndex = 0; clusterIndex < preprovisionCapacity.size(); ++clusterIndex) { ClusterCapacity clusterCapacity = preprovisionCapacity.get(clusterIndex); LockedNodeList allNodes = new LockedNodeList(mutableNodes, () -> {}); - List candidates = findCandidates(application, clusterCapacity, clusterIndex, allNodes, makeExclusive); + List candidates = findCandidates(application, clusterCapacity, clusterIndex, allNodes, features); int deficit = Math.max(0, clusterCapacity.count() - candidates.size()); if (deficit > 0) { return Optional.of(clusterCapacity.withCount(deficit)); @@ -283,7 +281,8 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { return Optional.empty(); } - private List findCandidates(ApplicationId application, ClusterCapacity clusterCapacity, int clusterIndex, LockedNodeList allNodes, boolean makeExclusive) { + private List findCandidates(ApplicationId application, ClusterCapacity clusterCapacity, int clusterIndex, + LockedNodeList allNodes, ClusterAllocationFeatures features) { NodeResources nodeResources = toNodeResources(clusterCapacity); // We'll allocate each ClusterCapacity as a unique cluster in a dummy application @@ -296,17 +295,17 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { NodePrioritizer prioritizer = new NodePrioritizer(allNodes, application, cluster, nodeSpec, true, false, allocationContext, nodeRepository().nodes(), nodeRepository().resourcesCalculator(), nodeRepository().spareCount(), - nodeRepository().exclusiveAllocation(cluster), makeExclusive); + nodeRepository().exclusiveAllocation(features, cluster), features); List nodeCandidates = prioritizer.collect() .stream() .filter(node -> node.violatesExclusivity(cluster, application, - nodeRepository().exclusiveClusterType(cluster), - nodeRepository().exclusiveAllocation(cluster), + nodeRepository().exclusiveClusterType(features, cluster), + nodeRepository().exclusiveAllocation(features, cluster), false, nodeRepository().zone().cloud().allowHostSharing(), allNodes, - makeExclusive) + features) != NodeCandidate.ExclusivityViolation.YES) .toList(); MutableInteger index = new MutableInteger(0); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostFlavorUpgrader.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostFlavorUpgrader.java index b6897d5b1c9..795abd54771 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostFlavorUpgrader.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostFlavorUpgrader.java @@ -12,6 +12,7 @@ import com.yahoo.vespa.hosted.provision.NodeRepository; import com.yahoo.vespa.hosted.provision.node.Agent; import com.yahoo.vespa.hosted.provision.node.Allocation; import com.yahoo.vespa.hosted.provision.provisioning.HostProvisioner; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import java.time.Duration; import java.util.HashSet; @@ -71,7 +72,8 @@ public class HostFlavorUpgrader extends NodeRepositoryMaintainer { if (parent.isEmpty()) continue; if (exhaustedFlavors.contains(parent.get().flavor().name())) continue; Allocation allocation = node.allocation().get(); - Predicate realHostResourcesWithinLimits = resources -> nodeRepository().nodeResourceLimits().isWithinRealLimits(resources, allocation.owner(), allocation.membership().cluster()); + var features = ClusterAllocationFeatures.from(nodeRepository().flagSource(), allocation.owner(), allocation.membership().cluster().vespaVersion()); + Predicate realHostResourcesWithinLimits = resources -> nodeRepository().nodeResourceLimits().isWithinRealLimits(features, resources, allocation.owner(), allocation.membership().cluster()); if (!hostProvisioner.canUpgradeFlavor(parent.get(), node, realHostResourcesWithinLimits)) continue; if (parent.get().status().wantToUpgradeFlavor() && allocation.membership().retired()) continue; // Already upgrading diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/CapacityPolicies.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/CapacityPolicies.java index 1e9adea4e95..f1fca4a71e9 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/CapacityPolicies.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/CapacityPolicies.java @@ -86,22 +86,22 @@ public class CapacityPolicies { return target; } - public ClusterResources specifyFully(ClusterResources resources, ClusterSpec clusterSpec, ApplicationId applicationId) { - return resources.with(specifyFully(resources.nodeResources(), clusterSpec, applicationId)); + public ClusterResources specifyFully(ClusterAllocationFeatures features, ClusterResources resources, ClusterSpec clusterSpec, ApplicationId applicationId) { + return resources.with(specifyFully(features, resources.nodeResources(), clusterSpec, applicationId)); } - public NodeResources specifyFully(NodeResources resources, ClusterSpec clusterSpec, ApplicationId applicationId) { - NodeResources amended = resources.withUnspecifiedFieldsFrom(defaultResources(clusterSpec, applicationId).with(DiskSpeed.any)); + public NodeResources specifyFully(ClusterAllocationFeatures features, NodeResources resources, ClusterSpec clusterSpec, ApplicationId applicationId) { + NodeResources amended = resources.withUnspecifiedFieldsFrom(defaultResources(features, clusterSpec, applicationId).with(DiskSpeed.any)); // TODO jonmv: remove this after all apps are 8.248.8 or above; architecture for admin nodes was not picked up before this. if (clusterSpec.vespaVersion().isBefore(Version.fromString("8.248.8"))) amended = amended.with(resources.architecture()); return amended; } - private NodeResources defaultResources(ClusterSpec clusterSpec, ApplicationId applicationId) { + private NodeResources defaultResources(ClusterAllocationFeatures features, ClusterSpec clusterSpec, ApplicationId applicationId) { if (clusterSpec.type() == ClusterSpec.Type.admin) { Architecture architecture = adminClusterArchitecture(applicationId); - if (nodeRepository.exclusiveAllocation(clusterSpec)) { + if (nodeRepository.exclusiveAllocation(features, clusterSpec)) { return smallestExclusiveResources().with(architecture); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ClusterAllocationFeatures.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ClusterAllocationFeatures.java new file mode 100644 index 00000000000..7af176e8715 --- /dev/null +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ClusterAllocationFeatures.java @@ -0,0 +1,29 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.provision.provisioning; + +import com.yahoo.component.Version; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.vespa.flags.FetchVector; +import com.yahoo.vespa.flags.FlagSource; +import com.yahoo.vespa.flags.Flags; +import com.yahoo.vespa.flags.PermanentFlags; +import com.yahoo.vespa.flags.custom.SharedHost; + +/** + * Miscellaneous constants used while preparing an allocation for a cluster. + * + *

Typically used to access feature flags that was evaluated once and at the start of the preparation, + * to avoid inconsistencies if evaluated multiple times during preparation.

+ * + * @author hakonhall + */ +public record ClusterAllocationFeatures(boolean makeExclusive, SharedHost sharedHost) { + public static ClusterAllocationFeatures from(FlagSource flagSource, ApplicationId application, Version version) { + return new ClusterAllocationFeatures(Flags.MAKE_EXCLUSIVE.bindTo(flagSource) + .with(FetchVector.Dimension.TENANT_ID, application.tenant().value()) + .with(FetchVector.Dimension.INSTANCE_ID, application.serializedForm()) + .with(FetchVector.Dimension.VESPA_VERSION, version.toFullString()) + .value(), + PermanentFlags.SHARED_HOST.bindTo(flagSource).value()); + } +} diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java index 38cbfa7fe5f..5b4d003788c 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java @@ -53,7 +53,10 @@ public interface HostProvisioner { * @return a runnable that waits for the provisioning request to finish. It can be run without holding any locks, * but may fail with an exception that should be propagated to the user initiating prepare() */ - Runnable provisionHosts(HostProvisionRequest request, Predicate realHostResourcesWithinLimits, Consumer> whenProvisioned) throws NodeAllocationException; + Runnable provisionHosts(ClusterAllocationFeatures features, + HostProvisionRequest request, + Predicate realHostResourcesWithinLimits, + Consumer> whenProvisioned) throws NodeAllocationException; /** * Continue provisioning of given list of Nodes. diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java index 21340baf273..3f106feb50f 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java @@ -84,10 +84,10 @@ class NodeAllocation { private final NodeRepository nodeRepository; private final Optional requiredHostFlavor; - private final boolean makeExclusive; + private final ClusterAllocationFeatures features; NodeAllocation(NodeList allNodes, ApplicationId application, ClusterSpec cluster, NodeSpec requested, - Supplier nextIndex, NodeRepository nodeRepository, boolean makeExclusive) { + Supplier nextIndex, NodeRepository nodeRepository, ClusterAllocationFeatures features) { this.allNodes = allNodes; this.application = application; this.cluster = cluster; @@ -100,7 +100,7 @@ class NodeAllocation { .with(FetchVector.Dimension.CLUSTER_ID, cluster.id().value()) .value()) .filter(s -> !s.isBlank()); - this.makeExclusive = makeExclusive; + this.features = features; } /** @@ -133,7 +133,7 @@ class NodeAllocation { } } else if ( ! saturated() && hasCompatibleResources(candidate)) { - if ( ! nodeRepository.nodeResourceLimits().isWithinRealLimits(candidate, application, cluster)) { + if ( ! nodeRepository.nodeResourceLimits().isWithinRealLimits(features, candidate, application, cluster)) { ++rejectedDueToInsufficientRealResources; continue; } @@ -169,7 +169,7 @@ class NodeAllocation { boolean alreadyRetired = candidate.allocation().map(a -> a.membership().retired()).orElse(false); return alreadyRetired ? Retirement.alreadyRetired : Retirement.none; } - if ( ! nodeRepository.nodeResourceLimits().isWithinRealLimits(candidate, application, cluster)) return Retirement.outsideRealLimits; + if ( ! nodeRepository.nodeResourceLimits().isWithinRealLimits(features, candidate, application, cluster)) return Retirement.outsideRealLimits; if (violatesParentHostPolicy(candidate)) return Retirement.violatesParentHostPolicy; if ( ! hasCompatibleResources(candidate)) return Retirement.incompatibleResources; if (candidate.parent.map(node -> node.status().wantToUpgradeFlavor()).orElse(false)) return Retirement.violatesHostFlavorGeneration; @@ -198,10 +198,10 @@ class NodeAllocation { private NodeCandidate.ExclusivityViolation violatesExclusivity(NodeCandidate candidate) { return candidate.violatesExclusivity(cluster, application, - nodeRepository.exclusiveClusterType(cluster), - nodeRepository.exclusiveAllocation(cluster), + nodeRepository.exclusiveClusterType(features, cluster), + nodeRepository.exclusiveAllocation(features, cluster), nodeRepository.exclusiveProvisioning(cluster), - nodeRepository.zone().cloud().allowHostSharing(), allNodes, makeExclusive); + nodeRepository.zone().cloud().allowHostSharing(), allNodes, features); } /** diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java index 8c29b40bc26..28cef679189 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java @@ -596,7 +596,7 @@ public abstract class NodeCandidate implements Nodelike, Comparable prepare(ApplicationId application, ClusterSpec cluster, Capacity requested, ProvisionLogger logger) { log.log(Level.FINE, "Received deploy prepare request for " + requested + " for application " + application + ", cluster " + cluster); - validate(application, cluster, requested, logger); + var features = ClusterAllocationFeatures.from(nodeRepository.flagSource(), application, cluster.vespaVersion()); + validate(features, application, cluster, requested, logger); NodeResources resources; NodeSpec nodeSpec; if (requested.type() == NodeType.tenant) { cluster = capacityPolicies.decideExclusivity(requested, cluster); Capacity actual = capacityPolicies.applyOn(requested, application, cluster.isExclusive()); - ClusterResources target = decideTargetResources(application, cluster, actual); + ClusterResources target = decideTargetResources(features, application, cluster, actual); validate(actual, target, cluster, application); logIfDownscaled(requested.minResources().nodes(), actual.minResources().nodes(), cluster, logger); - resources = getNodeResources(cluster, target.nodeResources(), application); + resources = getNodeResources(features, cluster, target.nodeResources(), application); nodeSpec = NodeSpec.from(target.nodes(), target.groups(), resources, cluster.isExclusive(), actual.canFail(), requested.cloudAccount().orElse(nodeRepository.zone().cloud().account()), requested.clusterInfo().hostTTL()); } else { cluster = cluster.withExclusivity(true); - resources = getNodeResources(cluster, requested.minResources().nodeResources(), application); + resources = getNodeResources(features, cluster, requested.minResources().nodeResources(), application); nodeSpec = NodeSpec.from(requested.type(), nodeRepository.zone().cloud().account()); } - return asSortedHosts(preparer.prepare(application, cluster, nodeSpec), + return asSortedHosts(preparer.prepare(features, application, cluster, nodeSpec), requireCompatibleResources(resources, cluster)); } - private void validate(ApplicationId application, ClusterSpec cluster, Capacity requested, ProvisionLogger logger) { + private void validate(ClusterAllocationFeatures features, ApplicationId application, ClusterSpec cluster, Capacity requested, ProvisionLogger logger) { if (cluster.group().isPresent()) throw new IllegalArgumentException("Node requests cannot specify a group"); - nodeRepository.nodeResourceLimits().ensureWithinAdvertisedLimits("Min", requested.minResources().nodeResources(), application, cluster); - nodeRepository.nodeResourceLimits().ensureWithinAdvertisedLimits("Max", requested.maxResources().nodeResources(), application, cluster); + nodeRepository.nodeResourceLimits().ensureWithinAdvertisedLimits(features, "Min", requested.minResources().nodeResources(), application, cluster); + nodeRepository.nodeResourceLimits().ensureWithinAdvertisedLimits(features, "Max", requested.maxResources().nodeResources(), application, cluster); if (!requested.minResources().nodeResources().gpuResources().equals(requested.maxResources().nodeResources().gpuResources())) throw new IllegalArgumentException(requested + " is invalid: GPU capacity cannot have ranges"); @@ -132,8 +133,8 @@ public class NodeRepositoryProvisioner implements Provisioner { } } - private NodeResources getNodeResources(ClusterSpec cluster, NodeResources nodeResources, ApplicationId applicationId) { - return capacityPolicies.specifyFully(nodeResources, cluster, applicationId); + private NodeResources getNodeResources(ClusterAllocationFeatures features, ClusterSpec cluster, NodeResources nodeResources, ApplicationId applicationId) { + return capacityPolicies.specifyFully(features, nodeResources, cluster, applicationId); } @Override @@ -165,18 +166,19 @@ public class NodeRepositoryProvisioner implements Provisioner { * Returns the target cluster resources, a value between the min and max in the requested capacity, * and updates the application store with the received min and max. */ - private ClusterResources decideTargetResources(ApplicationId applicationId, ClusterSpec clusterSpec, Capacity requested) { + private ClusterResources decideTargetResources(ClusterAllocationFeatures features, ApplicationId applicationId, ClusterSpec clusterSpec, Capacity requested) { try (Mutex lock = nodeRepository.applications().lock(applicationId)) { var application = nodeRepository.applications().get(applicationId).orElse(Application.empty(applicationId)) .withCluster(clusterSpec.id(), clusterSpec.isExclusive(), requested); nodeRepository.applications().put(application, lock); var cluster = application.cluster(clusterSpec.id()).get(); - return cluster.target().resources().orElseGet(() -> currentResources(application, clusterSpec, cluster, requested)); + return cluster.target().resources().orElseGet(() -> currentResources(features, application, clusterSpec, cluster, requested)); } } /** Returns the current resources of this cluster, or requested min if none */ - private ClusterResources currentResources(Application application, + private ClusterResources currentResources(ClusterAllocationFeatures features, + Application application, ClusterSpec clusterSpec, Cluster cluster, Capacity requested) { @@ -187,19 +189,20 @@ public class NodeRepositoryProvisioner implements Provisioner { boolean firstDeployment = nodes.isEmpty(); var current = firstDeployment // start at min, preserve current resources otherwise - ? new AllocatableResources(initialResourcesFrom(requested, clusterSpec, application.id()), clusterSpec, nodeRepository) + ? new AllocatableResources(features, initialResourcesFrom(features, requested, clusterSpec, application.id()), clusterSpec, nodeRepository) : new AllocatableResources(nodes, nodeRepository); - var model = new ClusterModel(nodeRepository, application, clusterSpec, cluster, nodes, current, nodeRepository.metricsDb(), nodeRepository.clock()); - return within(Limits.of(requested), model, firstDeployment); + var model = new ClusterModel(features, nodeRepository, application, clusterSpec, cluster, nodes, current, nodeRepository.metricsDb(), nodeRepository.clock()); + return within(features, Limits.of(requested), model, firstDeployment); } - private ClusterResources initialResourcesFrom(Capacity requested, ClusterSpec clusterSpec, ApplicationId applicationId) { - return capacityPolicies.specifyFully(requested.minResources(), clusterSpec, applicationId); + private ClusterResources initialResourcesFrom(ClusterAllocationFeatures features, Capacity requested, ClusterSpec clusterSpec, ApplicationId applicationId) { + return capacityPolicies.specifyFully(features, requested.minResources(), clusterSpec, applicationId); } /** Make the minimal adjustments needed to the current resources to stay within the limits */ - private ClusterResources within(Limits limits, + private ClusterResources within(ClusterAllocationFeatures features, + Limits limits, ClusterModel model, boolean firstDeployment) { if (limits.min().equals(limits.max())) return limits.min(); @@ -209,10 +212,11 @@ public class NodeRepositoryProvisioner implements Provisioner { return model.current().advertisedResources(); // Otherwise, find an allocation that preserves the current resources as well as possible - return allocationOptimizer.findBestAllocation(Load.one(), + return allocationOptimizer.findBestAllocation(features, + Load.one(), model, limits) - .orElseThrow(() -> newNoAllocationPossible(model.current().clusterSpec(), limits)) + .orElseThrow(() -> newNoAllocationPossible(features, model.current().clusterSpec(), limits)) .advertisedResources(); } @@ -277,10 +281,10 @@ public class NodeRepositoryProvisioner implements Provisioner { return nodeResources; } - private IllegalArgumentException newNoAllocationPossible(ClusterSpec spec, Limits limits) { + private IllegalArgumentException newNoAllocationPossible(ClusterAllocationFeatures features, ClusterSpec spec, Limits limits) { StringBuilder message = new StringBuilder("No allocation possible within ").append(limits); - if (nodeRepository.exclusiveAllocation(spec) && findNearestNodeResources(limits).isPresent()) + if (nodeRepository.exclusiveAllocation(features, spec) && findNearestNodeResources(limits).isPresent()) message.append(". Nearest allowed node resources: ").append(findNearestNodeResources(limits).get()); return new IllegalArgumentException(message.toString()); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeResourceLimits.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeResourceLimits.java index cd331cbd5fa..f4e527c81c4 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeResourceLimits.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeResourceLimits.java @@ -31,8 +31,8 @@ public class NodeResourceLimits { } /** Validates the resources applications ask for (which are in "advertised" resource space) */ - public void ensureWithinAdvertisedLimits(String type, NodeResources requested, ApplicationId applicationId, ClusterSpec cluster) { - boolean exclusive = nodeRepository.exclusiveAllocation(cluster); + public void ensureWithinAdvertisedLimits(ClusterAllocationFeatures features, String type, NodeResources requested, ApplicationId applicationId, ClusterSpec cluster) { + boolean exclusive = nodeRepository.exclusiveAllocation(features, cluster); if (! requested.vcpuIsUnspecified() && requested.vcpu() < minAdvertisedVcpu(applicationId, cluster, exclusive)) illegal(type, "vcpu", "", cluster, requested.vcpu(), minAdvertisedVcpu(applicationId, cluster, exclusive)); if (! requested.memoryGbIsUnspecified() && requested.memoryGb() < minAdvertisedMemoryGb(applicationId, cluster, exclusive)) @@ -48,17 +48,17 @@ public class NodeResourceLimits { } /** Returns whether the real resources we'll end up with on a given tenant node are within limits */ - public boolean isWithinRealLimits(NodeCandidate candidateNode, ApplicationId applicationId, ClusterSpec cluster) { + public boolean isWithinRealLimits(ClusterAllocationFeatures features, NodeCandidate candidateNode, ApplicationId applicationId, ClusterSpec cluster) { if (candidateNode.type() != NodeType.tenant) return true; // Resource limits only apply to tenant nodes - return isWithinRealLimits(nodeRepository.resourcesCalculator().realResourcesOf(candidateNode, nodeRepository), + return isWithinRealLimits(features, nodeRepository.resourcesCalculator().realResourcesOf(candidateNode, nodeRepository), applicationId, cluster); } /** Returns whether the real resources we'll end up with on a given tenant node are within limits */ - public boolean isWithinRealLimits(NodeResources realResources, ApplicationId applicationId, ClusterSpec cluster) { + public boolean isWithinRealLimits(ClusterAllocationFeatures features, NodeResources realResources, ApplicationId applicationId, ClusterSpec cluster) { if (realResources.isUnspecified()) return true; - if (realResources.vcpu() < minRealVcpu(applicationId, cluster)) return false; + if (realResources.vcpu() < minRealVcpu(features, applicationId, cluster)) return false; if (realResources.memoryGb() < minRealMemoryGb(cluster)) return false; if (realResources.diskGb() < minRealDiskGb()) return false; return true; @@ -115,8 +115,8 @@ public class NodeResourceLimits { return 4; } - private double minRealVcpu(ApplicationId applicationId, ClusterSpec cluster) { - return minAdvertisedVcpu(applicationId, cluster, nodeRepository.exclusiveAllocation(cluster)); + private double minRealVcpu(ClusterAllocationFeatures features, ApplicationId applicationId, ClusterSpec cluster) { + return minAdvertisedVcpu(applicationId, cluster, nodeRepository.exclusiveAllocation(features, cluster)); } private static double minRealMemoryGb(ClusterSpec cluster) { diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Preparer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Preparer.java index 978a69978b8..94288fd44fa 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Preparer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/Preparer.java @@ -13,9 +13,6 @@ import com.yahoo.jdisc.Metric; import com.yahoo.text.internal.SnippetGenerator; import com.yahoo.transaction.Mutex; import com.yahoo.vespa.applicationmodel.InfrastructureApplication; -import com.yahoo.vespa.flags.BooleanFlag; -import com.yahoo.vespa.flags.FetchVector; -import com.yahoo.vespa.flags.Flags; import com.yahoo.vespa.hosted.provision.LockedNodeList; import com.yahoo.vespa.hosted.provision.Node; import com.yahoo.vespa.hosted.provision.NodeList; @@ -50,42 +47,37 @@ public class Preparer { private final Optional hostProvisioner; private final Optional loadBalancerProvisioner; private final ProvisioningThrottler throttler; - private final BooleanFlag makeExclusiveFlag; public Preparer(NodeRepository nodeRepository, Optional hostProvisioner, Optional loadBalancerProvisioner, Metric metric) { this.nodeRepository = nodeRepository; this.hostProvisioner = hostProvisioner; this.loadBalancerProvisioner = loadBalancerProvisioner; this.throttler = new ProvisioningThrottler(nodeRepository, metric); - this.makeExclusiveFlag = Flags.MAKE_EXCLUSIVE.bindTo(nodeRepository.flagSource()); } /** * Ensure sufficient nodes are reserved or active for the given application, group and cluster * - * @param application the application we are allocating to - * @param cluster the cluster and group we are allocating to - * @param requested a specification of the requested nodes + * @param features misc constants used in preparation + * @param application the application we are allocating to + * @param cluster the cluster and group we are allocating to + * @param requested a specification of the requested nodes * @return the list of nodes this cluster group will have allocated if activated */ // Note: This operation may make persisted changes to the set of reserved and inactive nodes, // but it may not change the set of active nodes, as the active nodes must stay in sync with the // active config model which is changed on activate - public List prepare(ApplicationId application, ClusterSpec cluster, NodeSpec requested) { + public List prepare(ClusterAllocationFeatures features, ApplicationId application, ClusterSpec cluster, NodeSpec requested) { log.log(Level.FINE, () -> "Preparing " + cluster.type().name() + " " + cluster.id() + " with requested resources " + requested.resources().orElse(NodeResources.unspecified())); loadBalancerProvisioner.ifPresent(provisioner -> provisioner.prepare(application, cluster, requested)); - boolean makeExclusive = makeExclusiveFlag.with(FetchVector.Dimension.TENANT_ID, application.tenant().value()) - .with(FetchVector.Dimension.INSTANCE_ID, application.serializedForm()) - .with(FetchVector.Dimension.VESPA_VERSION, cluster.vespaVersion().toFullString()) - .value(); // Try preparing in memory without global unallocated lock. Most of the time there should be no changes, // and we can return nodes previously allocated. LockedNodeList allNodes = nodeRepository.nodes().list(PROBE_LOCK); NodeIndices indices = new NodeIndices(cluster.id(), allNodes); - NodeAllocation probeAllocation = prepareAllocation(application, cluster, requested, indices::probeNext, allNodes, makeExclusive); + NodeAllocation probeAllocation = prepareAllocation(application, cluster, requested, indices::probeNext, allNodes, features); if (probeAllocation.fulfilledAndNoChanges()) { List acceptedNodes = probeAllocation.finalNodes(); indices.commitProbe(); @@ -93,28 +85,28 @@ public class Preparer { } else { // There were some changes, so re-do the allocation with locks indices.resetProbe(); - return prepareWithLocks(application, cluster, requested, indices, makeExclusive); + return prepareWithLocks(application, cluster, requested, indices, features); } } - private ApplicationMutex parentLockOrNull(boolean makeExclusive, NodeType type) { - return NodeCandidate.canMakeHostExclusive(makeExclusive, type, nodeRepository.zone().cloud().allowHostSharing()) ? + private ApplicationMutex parentLockOrNull(ClusterAllocationFeatures features, NodeType type) { + return NodeCandidate.canMakeHostExclusive(features.makeExclusive(), type, nodeRepository.zone().cloud().allowHostSharing()) ? nodeRepository.applications().lock(InfrastructureApplication.withNodeType(type.parentNodeType()).id()) : null; } /// Note that this will write to the node repo. - private List prepareWithLocks(ApplicationId application, ClusterSpec cluster, NodeSpec requested, NodeIndices indices, boolean makeExclusive) { + private List prepareWithLocks(ApplicationId application, ClusterSpec cluster, NodeSpec requested, NodeIndices indices, ClusterAllocationFeatures features) { Runnable waiter = null; List acceptedNodes; try (Mutex lock = nodeRepository.applications().lock(application); - ApplicationMutex parentLockOrNull = parentLockOrNull(makeExclusive, requested.type()); + ApplicationMutex parentLockOrNull = parentLockOrNull(features, requested.type()); Mutex allocationLock = nodeRepository.nodes().lockUnallocated()) { LockedNodeList allNodes = nodeRepository.nodes().list(allocationLock); - NodeAllocation allocation = prepareAllocation(application, cluster, requested, indices::next, allNodes, makeExclusive); + NodeAllocation allocation = prepareAllocation(application, cluster, requested, indices::next, allNodes, features); NodeType hostType = allocation.nodeType().hostType(); if (canProvisionDynamically(hostType) && allocation.hostDeficit().isPresent()) { - HostSharing sharing = hostSharing(cluster, hostType); + HostSharing sharing = hostSharing(features, cluster, hostType); Version osVersion = nodeRepository.osVersions().targetFor(hostType).orElse(Version.emptyVersion); NodeAllocation.HostDeficit deficit = allocation.hostDeficit().get(); Set hosts = new LinkedHashSet<>(); @@ -147,8 +139,9 @@ public class Preparer { Optional.of(cluster.id()), requested.cloudAccount(), deficit.dueToFlavorUpgrade()); - Predicate realHostResourcesWithinLimits = resources -> nodeRepository.nodeResourceLimits().isWithinRealLimits(resources, application, cluster); - waiter = hostProvisioner.get().provisionHosts(request, realHostResourcesWithinLimits, whenProvisioned); + Predicate realHostResourcesWithinLimits = resources -> + nodeRepository.nodeResourceLimits().isWithinRealLimits(features, resources, application, cluster); + waiter = hostProvisioner.get().provisionHosts(features, request, realHostResourcesWithinLimits, whenProvisioned); } catch (NodeAllocationException e) { // Mark the nodes that were written to ZK in the consumer for deprovisioning. While these hosts do // not exist, we cannot remove them from ZK here because other nodes may already have been @@ -162,7 +155,7 @@ public class Preparer { // Non-dynamically provisioned zone with a deficit because we just now retired some nodes. // Try again, but without retiring indices.resetProbe(); - List accepted = prepareWithLocks(application, cluster, cns.withoutRetiring(), indices, makeExclusive); + List accepted = prepareWithLocks(application, cluster, cns.withoutRetiring(), indices, features); log.warning("Prepared " + application + " " + cluster.id() + " without retirement due to lack of capacity"); return accepted; } @@ -194,9 +187,9 @@ public class Preparer { } private NodeAllocation prepareAllocation(ApplicationId application, ClusterSpec cluster, NodeSpec requested, - Supplier nextIndex, LockedNodeList allNodes, boolean makeExclusive) { + Supplier nextIndex, LockedNodeList allNodes, ClusterAllocationFeatures features) { validateAccount(requested.cloudAccount(), application, allNodes); - NodeAllocation allocation = new NodeAllocation(allNodes, application, cluster, requested, nextIndex, nodeRepository, makeExclusive); + NodeAllocation allocation = new NodeAllocation(allNodes, application, cluster, requested, nextIndex, nodeRepository, features); var allocationContext = IP.Allocation.Context.from(nodeRepository.zone().cloud().name(), requested.cloudAccount().isExclave(nodeRepository.zone()), nodeRepository.nameResolver()); @@ -210,8 +203,8 @@ public class Preparer { nodeRepository.nodes(), nodeRepository.resourcesCalculator(), nodeRepository.spareCount(), - nodeRepository.exclusiveAllocation(cluster), - makeExclusive); + nodeRepository.exclusiveAllocation(features, cluster), + features); allocation.offer(prioritizer.collect()); return allocation; } @@ -238,10 +231,10 @@ public class Preparer { (hostType == NodeType.host || hostType.isConfigServerHostLike()); } - private HostSharing hostSharing(ClusterSpec cluster, NodeType hostType) { + private HostSharing hostSharing(ClusterAllocationFeatures features, ClusterSpec cluster, NodeType hostType) { if ( hostType.isSharable()) return nodeRepository.exclusiveProvisioning(cluster) ? HostSharing.provision : - nodeRepository.exclusiveAllocation(cluster) ? HostSharing.exclusive : + nodeRepository.exclusiveAllocation(features, cluster) ? HostSharing.exclusive : HostSharing.any; else return HostSharing.any; diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/ApplicationSerializer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/ApplicationSerializer.java index 225eb3e4e8d..f5d6028022a 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/ApplicationSerializer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/ApplicationSerializer.java @@ -13,6 +13,7 @@ import com.yahoo.vespa.hosted.provision.applications.ScalingEvent; import com.yahoo.vespa.hosted.provision.autoscale.Autoscaling; import com.yahoo.vespa.hosted.provision.autoscale.Limits; import com.yahoo.vespa.hosted.provision.autoscale.Load; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import java.net.URI; import java.util.List; @@ -24,33 +25,37 @@ import java.util.List; */ public class ApplicationSerializer { - public static Slime toSlime(Application application, + public static Slime toSlime(ClusterAllocationFeatures features, + Application application, NodeList applicationNodes, NodeRepository nodeRepository, URI applicationUri) { Slime slime = new Slime(); - toSlime(application, applicationNodes, nodeRepository, slime.setObject(), applicationUri); + toSlime(features, application, applicationNodes, nodeRepository, slime.setObject(), applicationUri); return slime; } - private static void toSlime(Application application, + private static void toSlime(ClusterAllocationFeatures features, + Application application, NodeList applicationNodes, NodeRepository nodeRepository, Cursor object, URI applicationUri) { object.setString("url", applicationUri.toString()); object.setString("id", application.id().toFullString()); - clustersToSlime(application, applicationNodes, nodeRepository, object.setObject("clusters")); + clustersToSlime(features, application, applicationNodes, nodeRepository, object.setObject("clusters")); } - private static void clustersToSlime(Application application, + private static void clustersToSlime(ClusterAllocationFeatures features, + Application application, NodeList applicationNodes, NodeRepository nodeRepository, Cursor clustersObject) { - application.clusters().values().forEach(cluster -> toSlime(application, cluster, applicationNodes, nodeRepository, clustersObject)); + application.clusters().values().forEach(cluster -> toSlime(features, application, cluster, applicationNodes, nodeRepository, clustersObject)); } - private static void toSlime(Application application, + private static void toSlime(ClusterAllocationFeatures features, + Application application, Cluster cluster, NodeList applicationNodes, NodeRepository nodeRepository, @@ -60,7 +65,7 @@ public class ApplicationSerializer { ClusterResources currentResources = nodes.toResources(); Cursor clusterObject = clustersObject.setObject(cluster.id().value()); clusterObject.setString("type", nodes.clusterSpec().type().name()); - Limits limits = Limits.of(cluster).fullySpecified(nodes.clusterSpec(), nodeRepository, application.id()); + Limits limits = Limits.of(cluster).fullySpecified(features, nodes.clusterSpec(), nodeRepository, application.id()); toSlime(limits.min(), clusterObject.setObject("min")); toSlime(limits.max(), clusterObject.setObject("max")); if ( ! cluster.groupSize().isEmpty()) diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java index 9080030f026..09eb111653d 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.provision.restapi; import com.yahoo.component.Version; +import com.yahoo.component.Vtag; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ApplicationLockException; import com.yahoo.config.provision.CloudAccount; @@ -46,6 +47,7 @@ import com.yahoo.vespa.hosted.provision.node.filter.NodeOsVersionFilter; import com.yahoo.vespa.hosted.provision.node.filter.NodeTypeFilter; import com.yahoo.vespa.hosted.provision.node.filter.ParentHostFilter; import com.yahoo.vespa.hosted.provision.maintenance.InfraApplicationRedeployer; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import com.yahoo.vespa.hosted.provision.restapi.NodesResponse.ResponseType; import com.yahoo.vespa.orchestrator.Orchestrator; import com.yahoo.yolean.Exceptions; @@ -463,7 +465,9 @@ public class NodesV2ApiHandler extends ThreadedHttpRequestHandler { Optional application = nodeRepository.applications().get(id); if (application.isEmpty()) return ErrorResponse.notFoundError("No application '" + id + "'"); - Slime slime = ApplicationSerializer.toSlime(application.get(), + var features = ClusterAllocationFeatures.from(nodeRepository.flagSource(), id, Vtag.currentVersion); + Slime slime = ApplicationSerializer.toSlime(features, + application.get(), nodeRepository.nodes().list(Node.State.active).owner(id), nodeRepository, withPath("/nodes/v2/applications/" + id, uri)); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java index b5bb91af71a..f249d10c21d 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java @@ -12,6 +12,7 @@ import com.yahoo.config.provision.NodeType; import com.yahoo.vespa.hosted.provision.Node; import com.yahoo.vespa.hosted.provision.node.Agent; import com.yahoo.vespa.hosted.provision.node.IP; +import com.yahoo.vespa.hosted.provision.provisioning.ClusterAllocationFeatures; import com.yahoo.vespa.hosted.provision.provisioning.FatalProvisioningException; import com.yahoo.vespa.hosted.provision.provisioning.HostIpConfig; import com.yahoo.vespa.hosted.provision.provisioning.HostProvisionRequest; @@ -73,7 +74,10 @@ public class MockHostProvisioner implements HostProvisioner { } @Override - public Runnable provisionHosts(HostProvisionRequest request, Predicate realHostResourcesWithinLimits, Consumer> whenProvisioned) throws NodeAllocationException { + public Runnable provisionHosts(ClusterAllocationFeatures features, + HostProvisionRequest request, + Predicate realHostResourcesWithinLimits, + Consumer> whenProvisioned) throws NodeAllocationException { if (behaviour(Behaviour.failProvisionRequest)) throw new NodeAllocationException("No capacity for provision request", true); Flavor hostFlavor = hostFlavors.get(request.clusterType().orElse(ClusterSpec.Type.content)); if (hostFlavor == null) @@ -264,7 +268,7 @@ public class MockHostProvisioner implements HostProvisioner { /** Fail call to {@link MockHostProvisioner#provision(com.yahoo.vespa.hosted.provision.Node)} */ failProvisioning, - /** Fail call to {@link MockHostProvisioner#provisionHosts(HostProvisionRequest, Predicate, Consumer)} */ + /** Fail call to {@link MockHostProvisioner#provisionHosts(ClusterAllocationFeatures, HostProvisionRequest, Predicate, Consumer)} */ failProvisionRequest, /** Fail call to {@link MockHostProvisioner#deprovision(com.yahoo.vespa.hosted.provision.Node)} */ -- cgit v1.2.3