blob: 163a22801616e2cfbd18a3f2ffef957567d10098 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "distributorcomponentregisterimpl.h"
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vdslib/state/cluster_state_bundle.h>
#include <vespa/vdslib/state/clusterstate.h>
namespace storage {
DistributorComponentRegisterImpl::DistributorComponentRegisterImpl()
: _timeCalculator(0),
_clusterState(std::make_shared<lib::ClusterState>())
{
}
DistributorComponentRegisterImpl::~DistributorComponentRegisterImpl() = default;
void
DistributorComponentRegisterImpl::handleNewState() noexcept
{
auto clusterStateBundle = getNodeStateUpdater().getClusterStateBundle();
_clusterState = std::make_shared<lib::ClusterState>(*clusterStateBundle->getBaselineClusterState());
}
void
DistributorComponentRegisterImpl::registerDistributorComponent(DistributorManagedComponent& smc)
{
std::lock_guard lock(_componentLock);
_components.push_back(&smc);
if (_timeCalculator != 0) {
smc.setTimeCalculator(*_timeCalculator);
}
smc.setDistributorConfig(_distributorConfig);
smc.setVisitorConfig(_visitorConfig);
}
void
DistributorComponentRegisterImpl::setTimeCalculator(UniqueTimeCalculator& utc)
{
std::lock_guard lock(_componentLock);
if (_timeCalculator != 0) {
throw vespalib::IllegalStateException(
"Time calculator already set. Cannot be updated live",
VESPA_STRLOC);
}
_timeCalculator = &utc;
for (uint32_t i=0; i<_components.size(); ++i) {
_components[i]->setTimeCalculator(*_timeCalculator);
}
}
void
DistributorComponentRegisterImpl::setDistributorConfig(const DistributorConfig& c)
{
std::lock_guard lock(_componentLock);
_distributorConfig = c;
for (uint32_t i=0; i<_components.size(); ++i) {
_components[i]->setDistributorConfig(c);
}
}
void
DistributorComponentRegisterImpl::setVisitorConfig(const VisitorConfig& c)
{
std::lock_guard lock(_componentLock);
_visitorConfig = c;
for (uint32_t i=0; i<_components.size(); ++i) {
_components[i]->setVisitorConfig(c);
}
}
void
DistributorComponentRegisterImpl::setNodeStateUpdater(NodeStateUpdater& updater)
{
StorageComponentRegisterImpl::setNodeStateUpdater(updater);
auto clusterStateBundle = updater.getClusterStateBundle();
if (clusterStateBundle) {
_clusterState = std::make_shared<lib::ClusterState>(*clusterStateBundle->getBaselineClusterState());
}
updater.addStateListener(*this);
}
} // storage
|