aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/frameworkimpl/component/storagecomponentregisterimpl.cpp
blob: 2f9430c49bbf3161da7ec9227bdce6cd4473c25d (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "storagecomponentregisterimpl.h"
#include <vespa/vespalib/util/exceptions.h>

#include <vespa/log/log.h>

LOG_SETUP(".storage.component.register");

namespace storage {

StorageComponentRegisterImpl::StorageComponentRegisterImpl()
    : _componentLock(),
      _components(),
      _clusterName(),
      _nodeType(nullptr),
      _index(0xffff),
      _docTypeRepo(),
      _loadTypes(new documentapi::LoadTypeSet),
      _priorityConfig(),
      _bucketIdFactory(),
      _distribution(),
      _nodeStateUpdater(nullptr),
      _bucketSpacesConfig()
{
}

StorageComponentRegisterImpl::~StorageComponentRegisterImpl() { }

void
StorageComponentRegisterImpl::registerStorageComponent(StorageComponent& smc)
{
    vespalib::LockGuard lock(_componentLock);
    _components.push_back(&smc);
    assert(_nodeType != 0);
    smc.setNodeInfo(_clusterName, *_nodeType, _index);
    if (_nodeStateUpdater != 0) {
        smc.setNodeStateUpdater(*_nodeStateUpdater);
    }
    smc.setDocumentTypeRepo(_docTypeRepo);
    smc.setLoadTypes(_loadTypes);
    smc.setPriorityConfig(_priorityConfig);
    smc.setBucketIdFactory(_bucketIdFactory);
    smc.setDistribution(_distribution);
    smc.enableMultipleBucketSpaces(_bucketSpacesConfig.enableMultipleBucketSpaces);
}

void
StorageComponentRegisterImpl::setNodeInfo(vespalib::stringref clusterName,
                                          const lib::NodeType& nodeType,
                                          uint16_t index)
{
    vespalib::LockGuard lock(_componentLock);
    if (_nodeType != 0) {
        LOG(warning, "Node info already set. May be valid in tests, but is a "
                     "bug in production. Node info should not be updated live");
    }
    _clusterName = clusterName;
    _nodeType = &nodeType;
    _index = index;
}

void
StorageComponentRegisterImpl::setNodeStateUpdater(NodeStateUpdater& updater)
{
    vespalib::LockGuard lock(_componentLock);
    if (_nodeStateUpdater != 0) {
        throw vespalib::IllegalStateException(
                "Node state updater already set. Should never be altered live.",
                VESPA_STRLOC);
    }
    _nodeStateUpdater = &updater;
    for (uint32_t i=0; i<_components.size(); ++i) {
        _components[i]->setNodeStateUpdater(updater);
    }
}

void
StorageComponentRegisterImpl::setDocumentTypeRepo(document::DocumentTypeRepo::SP repo)
{
    vespalib::LockGuard lock(_componentLock);
    _docTypeRepo = repo;
    for (uint32_t i=0; i<_components.size(); ++i) {
        _components[i]->setDocumentTypeRepo(repo);
    }
}

void
StorageComponentRegisterImpl::setLoadTypes(documentapi::LoadTypeSet::SP loadTypes)
{
    vespalib::LockGuard lock(_componentLock);
    _loadTypes = loadTypes;
    for (uint32_t i=0; i<_components.size(); ++i) {
        _components[i]->setLoadTypes(loadTypes);
    }
}

void
StorageComponentRegisterImpl::setPriorityConfig(const PriorityConfig& config)
{
    vespalib::LockGuard lock(_componentLock);
    _priorityConfig = config;
    for (uint32_t i=0; i<_components.size(); ++i) {
        _components[i]->setPriorityConfig(config);
    }
}

void
StorageComponentRegisterImpl::setBucketIdFactory(const document::BucketIdFactory& factory)
{
    vespalib::LockGuard lock(_componentLock);
    _bucketIdFactory = factory;
    for (uint32_t i=0; i<_components.size(); ++i) {
        _components[i]->setBucketIdFactory(factory);
    }
}

void
StorageComponentRegisterImpl::setDistribution(lib::Distribution::SP distribution)
{
    vespalib::LockGuard lock(_componentLock);
    _distribution = distribution;
    for (uint32_t i=0; i<_components.size(); ++i) {
        _components[i]->setDistribution(distribution);
    }
}

void
StorageComponentRegisterImpl::setBucketSpacesConfig(const BucketspacesConfig& config)
{
    vespalib::LockGuard lock(_componentLock);
    _bucketSpacesConfig = config;
    for (size_t i = 0; i < _components.size(); ++i) {
        _components[i]->enableMultipleBucketSpaces(config.enableMultipleBucketSpaces);
    }
}

} // storage