aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/content/StorageNode.java
blob: 9b093730deaade5db0f8ebea84c9ff619f7dc0e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.content;

import com.yahoo.config.model.api.ModelContext;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.producer.TreeConfigProducer;
import com.yahoo.vespa.config.content.StorFilestorConfig;
import com.yahoo.vespa.config.content.core.StorServerConfig;
import com.yahoo.vespa.defaults.Defaults;
import com.yahoo.vespa.model.application.validation.RestartConfigs;
import com.yahoo.vespa.model.builder.xml.dom.ModelElement;
import com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder;
import com.yahoo.vespa.model.content.engines.PersistenceEngine;
import com.yahoo.vespa.model.content.engines.ProtonProvider;
import com.yahoo.vespa.model.content.storagecluster.StorageCluster;
import org.w3c.dom.Element;
import java.util.Optional;

/**
 * Class to provide config related to a specific storage node.
 */
@RestartConfigs({StorFilestorConfig.class})
public class StorageNode extends ContentNode implements StorServerConfig.Producer, StorFilestorConfig.Producer {

    static final String rootFolder = Defaults.getDefaults().underVespaHome("var/db/vespa/search/");

    private final Double capacity;
    private final boolean retired;
    private final StorageCluster cluster;

    public static class Builder extends VespaDomBuilder.DomConfigProducerBuilder<StorageNode, StorageNode> {

        @Override
        protected StorageNode doBuild(DeployState deployState, TreeConfigProducer<StorageNode> ancestor, Element producerSpec) {
            ModelElement e = new ModelElement(producerSpec);
            return new StorageNode(deployState.getProperties(), (StorageCluster)ancestor, e.doubleAttribute("capacity"), e.integerAttribute("distribution-key"), false);
        }

    }

    StorageNode(ModelContext.Properties properties, StorageCluster cluster, Double capacity, int distributionKey, boolean retired) {
        super(properties.featureFlags(), cluster, cluster.getClusterName(),
              rootFolder + cluster.getClusterName() + "/storage/" + distributionKey,
              distributionKey);
        this.retired = retired;
        this.capacity = capacity;
        this.cluster = cluster;
    }

    @Override
    public Optional<String> getStartupCommand() {
        return isProviderProton()
                ? Optional.empty()
                : Optional.of("exec sbin/vespa-storaged -c $VESPA_CONFIG_ID");
    }

    public double getCapacity() {
        if (capacity != null) {
            return capacity;
        } else {
            return 1.0;
        }
    }

    /** Whether this node is configured as retired, which means all content should migrate off the node */
    public boolean isRetired() { return retired; }

    private boolean isProviderProton() {
        for (var producer : getChildren().values()) {
            if (producer instanceof ProtonProvider) {
                return true;
            }
        }
        return false;
    }

    @Override
    public void getConfig(StorServerConfig.Builder builder) {
        super.getConfig(builder);

        builder.node_capacity(getCapacity());

        for (var producer : getChildren().values()) {
            ((PersistenceEngine)producer).getConfig(builder);
        }
    }

    @Override
    public void getConfig(StorFilestorConfig.Builder builder) {
        if (getHostResource() != null && ! getHostResource().realResources().isUnspecified()) {
            builder.num_threads(Math.max(4, (int)getHostResource().realResources().vcpu()));
        }
        cluster.getConfig(builder);
    }

}