aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/activecopy.h
blob: 2085b9632ebb929d452489a270c8664d12dfa49f (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "ideal_service_layer_nodes_bundle.h"
#include <vespa/storage/bucketdb/bucketdatabase.h>

namespace storage::lib { class Distribution; }
namespace storage::distributor {

class ActiveList;
struct ActiveStateOrder;

class ActiveCopy {
    using Index = IdealServiceLayerNodesBundle::Index;
    using Node2Index = IdealServiceLayerNodesBundle::Node2Index;
public:
    constexpr ActiveCopy() noexcept
        : _nodeIndex(Index::invalid()),
          _ideal(Index::invalid()),
          _doc_count(0),
          _entryIndex(Index::invalid()),
          _ready(false),
          _active(false)
    { }
    ActiveCopy(uint16_t node, const BucketCopy & copy, uint16_t ideal, uint16_t entryIndex_in) noexcept
        : _nodeIndex(node),
          _ideal(ideal),
          _doc_count(copy.getDocumentCount()),
          _entryIndex(entryIndex_in),
          _ready(copy.ready()),
          _active(copy.active())
    { }

    vespalib::string getReason() const;
    friend std::ostream& operator<<(std::ostream& out, const ActiveCopy& e);

    static ActiveList calculate(const Node2Index & idealState, const lib::Distribution&,
                                const BucketDatabase::Entry&, uint32_t max_activation_inhibited_out_of_sync_groups);
    uint16_t nodeIndex() const noexcept { return _nodeIndex; }
    Index entryIndex() const noexcept { return Index(_entryIndex); }
private:
    friend ActiveStateOrder;
    bool valid_ideal() const noexcept { return _ideal < Index::invalid(); }
    uint16_t _nodeIndex;
    uint16_t _ideal;
    uint32_t _doc_count;
    uint16_t _entryIndex;  // Index in BucketCopyList
    bool     _ready;
    bool     _active;
};

class ActiveList : public vespalib::Printable {
public:
    ActiveList() noexcept {}
    ActiveList(std::vector<ActiveCopy>&& v) noexcept : _v(std::move(v)) { }

    const ActiveCopy& operator[](size_t i) const noexcept { return _v[i]; }
    [[nodiscard]] bool contains(uint16_t) const noexcept;
    [[nodiscard]] bool empty() const noexcept { return _v.empty(); }
    size_t size() const noexcept { return _v.size(); }
    void print(std::ostream&, bool verbose, const std::string& indent) const override;
private:
    std::vector<ActiveCopy> _v;
};

}