aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/bucket_space_state_map.cpp
blob: ea87a0c29a75e28024645fb4adb741c74e238f82 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "bucket_space_state_map.h"
#include <vespa/document/bucket/fixed_bucket_spaces.h>

using document::BucketSpace;

namespace storage::distributor {

BucketSpaceState::BucketSpaceState()
    : _cluster_state(),
      _distribution()
{
}

void
BucketSpaceState::set_cluster_state(std::shared_ptr<const lib::ClusterState> cluster_state)
{
    _cluster_state = std::move(cluster_state);
}

void
BucketSpaceState::set_distribution(std::shared_ptr<const lib::Distribution> distribution)
{
    _distribution = distribution;
}

BucketSpaceStateMap::BucketSpaceStateMap()
    : _map()
{
    _map.emplace(document::FixedBucketSpaces::default_space(), std::make_unique<BucketSpaceState>());
    _map.emplace(document::FixedBucketSpaces::global_space(), std::make_unique<BucketSpaceState>());
}

const BucketSpaceState&
BucketSpaceStateMap::get(document::BucketSpace space) const
{
    auto itr = _map.find(space);
    assert(itr != _map.end());
    return *itr->second;
}

BucketSpaceState&
BucketSpaceStateMap::get(document::BucketSpace space)
{
    auto itr = _map.find(space);
    assert(itr != _map.end());
    return *itr->second;
}

void
BucketSpaceStateMap::set_cluster_state(std::shared_ptr<const lib::ClusterState> cluster_state)
{
    for (auto& space : _map) {
        space.second->set_cluster_state(cluster_state);
    }
}

void
BucketSpaceStateMap::set_distribution(std::shared_ptr<const lib::Distribution> distribution)
{
    for (auto& space : _map) {
        space.second->set_distribution(distribution);
    }
}

const lib::ClusterState&
BucketSpaceStateMap::get_cluster_state(document::BucketSpace space) const
{
    auto itr = _map.find(space);
    assert(itr != _map.end());
    return itr->second->get_cluster_state();
}

const lib::Distribution&
BucketSpaceStateMap::get_distribution(document::BucketSpace space) const
{
    auto itr = _map.find(space);
    assert(itr != _map.end());
    return itr->second->get_distribution();
}

}