blob: e218058f01e60432ef62e7fcff3e1fbd5bde51f0 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/searchcore/proton/server/ibucketstatecalculator.h>
#include <vespa/document/bucket/bucketidlist.h>
#include <vespa/document/bucket/bucket.h>
#include <set>
namespace proton::test {
using BucketIdVector = document::bucket::BucketIdList;
typedef std::set<document::BucketId> BucketIdSet;
class BucketStateCalculator : public IBucketStateCalculator
{
private:
BucketIdSet _ready;
mutable BucketIdVector _asked;
bool _clusterUp;
bool _nodeUp;
bool _nodeRetired;
bool _nodeMaintenance;
public:
typedef std::shared_ptr<BucketStateCalculator> SP;
BucketStateCalculator() :
_ready(),
_asked(),
_clusterUp(true),
_nodeUp(true),
_nodeRetired(false),
_nodeMaintenance(false)
{
}
BucketStateCalculator &addReady(const document::BucketId &bucket) {
_ready.insert(bucket);
return *this;
}
BucketStateCalculator &remReady(const document::BucketId &bucket) {
_ready.erase(bucket);
return *this;
}
BucketStateCalculator &setClusterUp(bool value) noexcept {
_clusterUp = value;
return *this;
}
BucketStateCalculator & setNodeUp(bool value) noexcept {
_nodeUp = value;
return *this;
}
BucketStateCalculator& setNodeRetired(bool retired) noexcept {
_nodeRetired = retired;
return *this;
}
BucketStateCalculator& setNodeMaintenance(bool maintenance) noexcept {
_nodeMaintenance = maintenance;
if (maintenance) {
_nodeUp = false;
_nodeRetired = false;
}
return *this;
}
const BucketIdVector &asked() const noexcept { return _asked; }
void resetAsked() { _asked.clear(); }
// Implements IBucketStateCalculator
vespalib::Trinary shouldBeReady(const document::Bucket &bucket) const override {
_asked.push_back(bucket.getBucketId());
return (_ready.count(bucket.getBucketId()) == 1) ? vespalib::Trinary::True : vespalib::Trinary::False;
}
bool clusterUp() const override { return _clusterUp; }
bool nodeUp() const override { return _nodeUp; }
bool nodeRetired() const override { return _nodeRetired; }
bool nodeInitializing() const override { return false; }
bool nodeMaintenance() const noexcept override { return _nodeMaintenance; }
};
}
|