aboutsummaryrefslogtreecommitdiffstats
path: root/vdslib/src/vespa/vdslib/state/cluster_state_bundle.h
blob: c8889ad7da4f1a28a771105d48d3e534abe05a87 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/document/bucket/bucketspace.h>
#include <iosfwd>
#include <optional>
#include <string>
#include <unordered_map>
#include <memory>

namespace storage::lib {

class ClusterState;

/**
 * Class representing the baseline cluster state and the derived cluster
 * state for each bucket space.
 */
class ClusterStateBundle
{
public:

    /**
     * Represents feed blocking status of the entire cluster.
     *
     * Feed blocking only applies to client feed, and is turned on
     * when this object is present and _block_feed_in_cluster is true.
     * Feed generated by internal maintenance operations (e.g. merging) is not affected.
     */
    class FeedBlock {
    private:
        bool _block_feed_in_cluster;
        vespalib::string _description;

    public:
        FeedBlock(bool block_feed_in_cluster_in,
                  const vespalib::string& description_in);
        bool block_feed_in_cluster() const { return _block_feed_in_cluster; }
        const vespalib::string& description() const { return _description; }
        bool operator==(const FeedBlock& rhs) const;
        bool operator!=(const FeedBlock& rhs) const { return !operator==(rhs); }
    };

    using BucketSpaceStateMapping = std::unordered_map<
        document::BucketSpace,
        std::shared_ptr<const ClusterState>,
        document::BucketSpace::hash
    >;
    std::shared_ptr<const ClusterState> _baselineClusterState;
    BucketSpaceStateMapping _derivedBucketSpaceStates;
    std::optional<FeedBlock> _feed_block;
    bool _deferredActivation;
public:
    explicit ClusterStateBundle(const ClusterState &baselineClusterState);
    ClusterStateBundle(const ClusterState& baselineClusterState,
                       BucketSpaceStateMapping derivedBucketSpaceStates);
    ClusterStateBundle(const ClusterState& baselineClusterState,
                       BucketSpaceStateMapping derivedBucketSpaceStates,
                       bool deferredActivation);
    ClusterStateBundle(const ClusterState& baselineClusterState,
                       BucketSpaceStateMapping derivedBucketSpaceStates,
                       const FeedBlock& feed_block_in,
                       bool deferredActivation);

    ClusterStateBundle(const ClusterStateBundle&);
    ClusterStateBundle& operator=(const ClusterStateBundle&);
    ClusterStateBundle(ClusterStateBundle&&) noexcept;
    ClusterStateBundle& operator=(ClusterStateBundle&&) noexcept;

    ~ClusterStateBundle();
    const std::shared_ptr<const ClusterState> &getBaselineClusterState() const;
    const std::shared_ptr<const ClusterState> &getDerivedClusterState(document::BucketSpace bucketSpace) const;
    const BucketSpaceStateMapping& getDerivedClusterStates() const noexcept {
        return _derivedBucketSpaceStates;
    }
    [[nodiscard]] bool block_feed_in_cluster() const noexcept {
        return _feed_block.has_value() && _feed_block->block_feed_in_cluster();
    }
    const std::optional<FeedBlock>& feed_block() const { return _feed_block; }
    uint32_t getVersion() const;
    bool deferredActivation() const noexcept { return _deferredActivation; }
    std::string toString() const;
    bool operator==(const ClusterStateBundle &rhs) const noexcept;
    bool operator!=(const ClusterStateBundle &rhs) const noexcept { return !operator==(rhs); }
};

std::ostream& operator<<(std::ostream&, const ClusterStateBundle&);

}