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
|
// Copyright Yahoo. 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 <cassert>
#include <vespa/log/log.h>
LOG_SETUP(".storage.component.register");
namespace storage {
StorageComponentRegisterImpl::StorageComponentRegisterImpl()
: _componentLock(),
_components(),
_clusterName(),
_nodeType(nullptr),
_index(0xffff),
_docTypeRepo(),
_bucketIdFactory(),
_distribution(),
_nodeStateUpdater(nullptr),
_bucketSpacesConfig()
{
}
StorageComponentRegisterImpl::~StorageComponentRegisterImpl() = default;
void
StorageComponentRegisterImpl::registerStorageComponent(StorageComponent& smc)
{
std::lock_guard lock(_componentLock);
_components.push_back(&smc);
assert(_nodeType != nullptr);
smc.setNodeInfo(_clusterName, *_nodeType, _index);
if (_nodeStateUpdater != nullptr) {
smc.setNodeStateUpdater(*_nodeStateUpdater);
}
smc.setDocumentTypeRepo(_docTypeRepo);
smc.setBucketIdFactory(_bucketIdFactory);
smc.setDistribution(_distribution);
}
void
StorageComponentRegisterImpl::setNodeInfo(vespalib::stringref clusterName,
const lib::NodeType& nodeType,
uint16_t index)
{
std::lock_guard lock(_componentLock);
if (_nodeType != nullptr) {
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)
{
std::lock_guard lock(_componentLock);
if (_nodeStateUpdater != 0) {
throw vespalib::IllegalStateException(
"Node state updater already set. Should never be altered live.",
VESPA_STRLOC);
}
_nodeStateUpdater = &updater;
for (auto& component : _components) {
component->setNodeStateUpdater(updater);
}
}
void
StorageComponentRegisterImpl::setDocumentTypeRepo(std::shared_ptr<const document::DocumentTypeRepo> repo)
{
std::lock_guard lock(_componentLock);
_docTypeRepo = repo;
for (auto& component : _components) {
component->setDocumentTypeRepo(repo);
}
}
void
StorageComponentRegisterImpl::setBucketIdFactory(const document::BucketIdFactory& factory)
{
std::lock_guard lock(_componentLock);
_bucketIdFactory = factory;
for (auto& component : _components) {
component->setBucketIdFactory(factory);
}
}
void
StorageComponentRegisterImpl::setDistribution(std::shared_ptr<lib::Distribution> distribution)
{
std::lock_guard lock(_componentLock);
_distribution = distribution;
for (auto& component : _components) {
component->setDistribution(distribution);
}
}
void
StorageComponentRegisterImpl::setBucketSpacesConfig(const BucketspacesConfig& config)
{
std::lock_guard lock(_componentLock);
_bucketSpacesConfig = config;
}
} // storage
|