diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-10-12 08:11:59 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-10-12 08:11:59 +0200 |
commit | 0c006afda8be00c251cfe05dfa2d2d0d0b5aa286 (patch) | |
tree | 1b059caaa8947c4d662e0b12455c6246c2df1818 /config-model/src/main/java | |
parent | 982a1b1804b8773be2c5db13535fa0b0e33928b1 (diff) |
Defer changes until restart
In container clusters, if it is determined that a restart is required to swicth
to a new config generation, mark that config as applicable only after a restart.
This avoids wasting resources on a config change just before a restart, and the
potential of prematurely applying config changes which depend on other changes
which are not effective before a restart has been done.
Diffstat (limited to 'config-model/src/main/java')
6 files changed, 43 insertions, 33 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/provision/InMemoryProvisioner.java b/config-model/src/main/java/com/yahoo/config/model/provision/InMemoryProvisioner.java index 4c6dccebae4..4302a4dcd48 100644 --- a/config-model/src/main/java/com/yahoo/config/model/provision/InMemoryProvisioner.java +++ b/config-model/src/main/java/com/yahoo/config/model/provision/InMemoryProvisioner.java @@ -48,6 +48,9 @@ public class InMemoryProvisioner implements HostProvisioner { /** Hosts which should be returned as retired */ private final Set<String> retiredHostNames; + /** If false, nodes returned will have the resources of the host, if true node resources will be as requested */ + private final boolean sharedHosts; + /** Free hosts of each resource size */ private final ListMap<NodeResources, Host> freeNodes = new ListMap<>(); private final Map<ClusterSpec, List<HostSpec>> allocations = new LinkedHashMap<>(); @@ -63,33 +66,34 @@ public class InMemoryProvisioner implements HostProvisioner { private Provisioned provisioned = new Provisioned(); /** Creates this with a number of nodes with resources 1, 3, 9, 1 */ - public InMemoryProvisioner(int nodeCount) { - this(nodeCount, defaultResources); + public InMemoryProvisioner(int nodeCount, boolean sharedHosts) { + this(nodeCount, defaultResources, sharedHosts); } /** Creates this with a number of nodes with given resources */ - public InMemoryProvisioner(int nodeCount, NodeResources resources) { - this(Map.of(resources, createHostInstances(nodeCount)), true, false, 0); + public InMemoryProvisioner(int nodeCount, NodeResources resources, boolean sharedHosts) { + this(Map.of(resources, createHostInstances(nodeCount)), true, false, sharedHosts, 0); } /** Creates this with a set of host names of the flavor 'default' */ - public InMemoryProvisioner(boolean failOnOutOfCapacity, String... hosts) { - this(Map.of(defaultResources, toHostInstances(hosts)), failOnOutOfCapacity, false, 0); + public InMemoryProvisioner(boolean failOnOutOfCapacity, boolean sharedHosts, String... hosts) { + this(Map.of(defaultResources, toHostInstances(hosts)), failOnOutOfCapacity, false, sharedHosts, 0); } /** Creates this with a set of hosts of the flavor 'default' */ - public InMemoryProvisioner(Hosts hosts, boolean failOnOutOfCapacity, String ... retiredHostNames) { - this(Map.of(defaultResources, hosts.asCollection()), failOnOutOfCapacity, false, 0, retiredHostNames); + public InMemoryProvisioner(Hosts hosts, boolean failOnOutOfCapacity, boolean sharedHosts, String ... retiredHostNames) { + this(Map.of(defaultResources, hosts.asCollection()), failOnOutOfCapacity, false, sharedHosts, 0, retiredHostNames); } /** Creates this with a set of hosts of the flavor 'default' */ - public InMemoryProvisioner(Hosts hosts, boolean failOnOutOfCapacity, int startIndexForClusters, String ... retiredHostNames) { - this(Map.of(defaultResources, hosts.asCollection()), failOnOutOfCapacity, false, startIndexForClusters, retiredHostNames); + public InMemoryProvisioner(Hosts hosts, boolean failOnOutOfCapacity, boolean sharedHosts, int startIndexForClusters, String ... retiredHostNames) { + this(Map.of(defaultResources, hosts.asCollection()), failOnOutOfCapacity, false, sharedHosts, startIndexForClusters, retiredHostNames); } public InMemoryProvisioner(Map<NodeResources, Collection<Host>> hosts, boolean failOnOutOfCapacity, boolean useMaxResources, + boolean sharedHosts, int startIndexForClusters, String ... retiredHostNames) { this.failOnOutOfCapacity = failOnOutOfCapacity; @@ -97,8 +101,9 @@ public class InMemoryProvisioner implements HostProvisioner { for (Map.Entry<NodeResources, Collection<Host>> hostsWithResources : hosts.entrySet()) for (Host host : hostsWithResources.getValue()) freeNodes.put(hostsWithResources.getKey(), host); - this.retiredHostNames = Set.of(retiredHostNames); + this.sharedHosts = sharedHosts; this.startIndexForClusters = startIndexForClusters; + this.retiredHostNames = Set.of(retiredHostNames); } private static Collection<Host> toHostInstances(String[] hostnames) { @@ -160,6 +165,7 @@ public class InMemoryProvisioner implements HostProvisioner { if (retiredHostNames.contains(host.hostname())) i.set(retire(host)); } + return allocation; } @@ -212,8 +218,9 @@ public class InMemoryProvisioner implements HostProvisioner { Host newHost = freeNodes.removeValue(hostResources.get(), 0); if (freeNodes.get(hostResources.get()).isEmpty()) freeNodes.removeAll(hostResources.get()); ClusterMembership membership = ClusterMembership.from(clusterGroup, nextIndex++); + NodeResources resources = sharedHosts ? requestedResources : hostResources.get(); allocation.add(new HostSpec(newHost.hostname(), - hostResources.get(), hostResources.get(), requestedResources, + resources, resources, requestedResources, membership, newHost.version(), Optional.empty(), Optional.empty())); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/Validation.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/Validation.java index cc4653fc183..d300e31c3dc 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/Validation.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/Validation.java @@ -117,11 +117,11 @@ public class Validation { for (var clusterToRestart : clustersToBeRestarted) { var containerCluster = model.getContainerClusters().get(clusterToRestart.value()); if (containerCluster != null) - containerCluster.deferChangesUntilRestart(); + containerCluster.setDeferChangesUntilRestart(true); var contentCluster = model.getContentClusters().get(clusterToRestart.value()); if (contentCluster != null) - contentCluster.deferChangesUntilRestart(); + contentCluster.setDeferChangesUntilRestart(true); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/ContainerRestartValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/ContainerRestartValidator.java index 17e4f031f3e..4f9ffc95ab0 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/ContainerRestartValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/ContainerRestartValidator.java @@ -7,7 +7,6 @@ import com.yahoo.container.QrConfig; import com.yahoo.vespa.model.VespaModel; import com.yahoo.config.application.api.ValidationOverrides; import com.yahoo.vespa.model.container.ApplicationContainer; -import com.yahoo.vespa.model.container.ApplicationContainerCluster; import com.yahoo.vespa.model.container.Container; import com.yahoo.vespa.model.container.ContainerCluster; @@ -16,8 +15,6 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import static java.util.stream.Collectors.toList; - /** * Returns a restart action for each container that has turned on {@link QrConfig#restartOnDeploy()}. * diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java b/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java index ca4140fe5c5..1d991721ea7 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java @@ -58,6 +58,9 @@ public abstract class Container extends AbstractService implements public static final int BASEPORT = Defaults.getDefaults().vespaWebServicePort(); public static final String SINGLENODE_CONTAINER_SERVICESPEC = "default_singlenode_container"; + /** The cluster this contasiner belongs to, or null if it is not added to any cluster */ + private ContainerCluster owner = null; + protected final AbstractConfigProducer parent; private final String name; private boolean requireSpecificPorts = true; @@ -94,6 +97,8 @@ public abstract class Container extends AbstractService implements addChild(new SimpleComponent("com.yahoo.container.jdisc.ConfiguredApplication$ApplicationContext")); } + void setOwner(ContainerCluster<?> owner) { this.owner = owner; } + /** True if this container is retired (slated for removal) */ public boolean isRetired() { return retired; } @@ -296,17 +301,14 @@ public abstract class Container extends AbstractService implements @Override public void getConfig(QrConfig.Builder builder) { - builder. - rpc(new Rpc.Builder() + builder.rpc(new Rpc.Builder() .enabled(rpcServerEnabled()) .port(getRpcPort()) - .slobrokId(serviceSlobrokId())). - filedistributor(filedistributorConfig()); - if (clusterName != null) { - builder.discriminator(clusterName + "." + name); - } else { - builder.discriminator(name); - } + .slobrokId(serviceSlobrokId())) + .filedistributor(filedistributorConfig()) + .discriminator((clusterName != null ? clusterName + "." : "" ) + name) + .restartOnDeploy(owner != null && owner.getDeferChangesUntilRestart()); + } /** Returns the jvm args set explicitly for this node */ diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java index 2d7d49f03ed..0bafd3cfdcf 100755 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java @@ -147,7 +147,7 @@ public abstract class ContainerCluster<CONTAINER extends Container> private final ComponentGroup<Component<?, ?>> componentGroup; private final boolean isHostedVespa; - private Map<String, String> concreteDocumentTypes = new LinkedHashMap<>(); + private final Map<String, String> concreteDocumentTypes = new LinkedHashMap<>(); private ApplicationMetaData applicationMetaData = null; @@ -158,6 +158,8 @@ public abstract class ContainerCluster<CONTAINER extends Container> private String jvmGCOptions = null; private String environmentVars = null; + private boolean deferChangesUntilRestart = false; + public ContainerCluster(AbstractConfigProducer<?> parent, String configSubId, String clusterId, DeployState deployState) { super(parent, configSubId); this.name = clusterId; @@ -288,6 +290,7 @@ public abstract class ContainerCluster<CONTAINER extends Container> } public void addContainer(CONTAINER container) { + container.setOwner(this); container.setClusterName(name); container.setProp("clustername", name) .setProp("index", this.containers.size()); @@ -618,11 +621,13 @@ public abstract class ContainerCluster<CONTAINER extends Container> protected abstract boolean messageBusEnabled(); /** - * Mark that the config emitted by this cluster currently should be applied by clients already running with + * Mark whether the config emitted by this cluster currently should be applied by clients already running with * a previous generation of it only by restarting the consuming processes. */ - public void deferChangesUntilRestart() { - + public void setDeferChangesUntilRestart(boolean deferChangesUntilRestart) { + this.deferChangesUntilRestart = deferChangesUntilRestart; } + public boolean getDeferChangesUntilRestart() { return deferChangesUntilRestart; } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java index 1a994cd4636..66a96690dab 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java @@ -744,11 +744,10 @@ public class ContentCluster extends AbstractConfigProducer implements } /** - * Mark that the config emitted by this cluster currently should be applied by clients already running with + * Mark whether the config emitted by this cluster currently should be applied by clients already running with * a previous generation of it only by restarting the consuming processes. */ - public void deferChangesUntilRestart() { - + public void setDeferChangesUntilRestart(boolean deferChangesUntilRestart) { } } |