aboutsummaryrefslogtreecommitdiffstats
path: root/storageserver/src/vespa/storageserver/app/servicelayerprocess.cpp
blob: bb284bfc1080e4c2093beba1d2382afd112809ce (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "servicelayerprocess.h"
#include <vespa/config/helper/configgetter.hpp>
#include <vespa/storage/common/content_bucket_db_options.h>
#include <vespa/storage/common/i_storage_chain_builder.h>
#include <vespa/storage/config/config-stor-server.h>
#include <vespa/storage/storageserver/servicelayernode.h>
#include <vespa/storageframework/defaultimplementation/clock/realclock.h>
#include <vespa/searchvisitor/searchvisitor.h>

#include <vespa/log/log.h>
LOG_SETUP(".storageserver.service_layer_process");

namespace storage {

namespace {

ContentBucketDbOptions
bucket_db_options_from_config(const config::ConfigUri& config_uri) {
    using vespa::config::content::core::StorServerConfig;
    auto server_config = config::ConfigGetter<StorServerConfig>::getConfig(
            config_uri.getConfigId(), config_uri.getContext());
    // For now, limit to max 8 bits, i.e. 256 sub DBs.
    // 0 bits (the default value) disables striping entirely.
    auto n_stripe_bits = std::min(std::max(server_config->contentNodeBucketDbStripeBits, 0), 8);
    ContentBucketDbOptions opts;
    opts.n_stripe_bits = n_stripe_bits;
    return opts;
}

}

ServiceLayerProcess::ServiceLayerProcess(const config::ConfigUri& configUri)
    : Process(configUri),
      _externalVisitors(),
      _persistence_cfg_handle(),
      _visitor_cfg_handle(),
      _filestor_cfg_handle(),
      _node(),
      _storage_chain_builder(),
      _context(std::make_unique<framework::defaultimplementation::RealClock>(),
               bucket_db_options_from_config(configUri))
{
}

ServiceLayerProcess::~ServiceLayerProcess() = default;

void
ServiceLayerProcess::shutdown()
{
    Process::shutdown();
    _node.reset();
}

void
ServiceLayerProcess::setupConfig(vespalib::duration subscribe_timeout)
{
    _persistence_cfg_handle = _configSubscriber.subscribe<PersistenceConfig>(_configUri.getConfigId(), subscribe_timeout);
    _visitor_cfg_handle     = _configSubscriber.subscribe<StorVisitorConfig>(_configUri.getConfigId(), subscribe_timeout);
    _filestor_cfg_handle    = _configSubscriber.subscribe<StorFilestorConfig>(_configUri.getConfigId(), subscribe_timeout);
    // We reuse the StorServerConfig subscription from the parent Process
    Process::setupConfig(subscribe_timeout);
}

void
ServiceLayerProcess::updateConfig()
{
    Process::updateConfig();
    if (_server_cfg_handle->isChanged()) {
        _node->on_configure(*_server_cfg_handle->getConfig());
    }
    if (_persistence_cfg_handle->isChanged()) {
        _node->on_configure(*_persistence_cfg_handle->getConfig());
    }
    if (_visitor_cfg_handle->isChanged()) {
        _node->on_configure(*_visitor_cfg_handle->getConfig());
    }
    if (_filestor_cfg_handle->isChanged()) {
        _node->on_configure(*_filestor_cfg_handle->getConfig());
    }
}

bool
ServiceLayerProcess::configUpdated()
{
    return Process::configUpdated();
}

void
ServiceLayerProcess::createNode()
{
    add_external_visitors();
    setupProvider();

    StorageNode::BootstrapConfigs bc;
    bc.bucket_spaces_cfg = _bucket_spaces_cfg_handle->getConfig();
    bc.bouncer_cfg       = _bouncer_cfg_handle->getConfig();
    bc.comm_mgr_cfg      = _comm_mgr_cfg_handle->getConfig();
    bc.distribution_cfg  = _distribution_cfg_handle->getConfig();
    bc.server_cfg        = _server_cfg_handle->getConfig();

    ServiceLayerNode::ServiceLayerBootstrapConfigs sbc;
    sbc.storage_bootstrap_configs = std::move(bc);
    sbc.persistence_cfg = _persistence_cfg_handle->getConfig();
    sbc.visitor_cfg     = _visitor_cfg_handle->getConfig();
    sbc.filestor_cfg    = _filestor_cfg_handle->getConfig();

    _node = std::make_unique<ServiceLayerNode>(_configUri, _context, std::move(sbc), *this, getProvider(), _externalVisitors);
    if (_storage_chain_builder) {
        _node->set_storage_chain_builder(std::move(_storage_chain_builder));
    }
    _node->init();
}

StorageNode&
ServiceLayerProcess::getNode() {
    return *_node;
}

StorageNodeContext&
ServiceLayerProcess::getContext() {
    return _context;
}

std::string
ServiceLayerProcess::getComponentName() const {
    return "servicelayer";
}

void
ServiceLayerProcess::set_storage_chain_builder(std::unique_ptr<IStorageChainBuilder> builder)
{
    _storage_chain_builder = std::move(builder);
}

void
ServiceLayerProcess::add_external_visitors()
{
    _externalVisitors["searchvisitor"] = std::make_shared<streaming::SearchVisitorFactory>(_configUri, nullptr, "");
}

} // storage