aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/maintenance/prioritizedbucket.h
blob: 5124cc238e745c283e107a58a8fdaa4a5af7cb33 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <iosfwd>
#include <vespa/document/bucket/bucket.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/storage/distributor/maintenance/maintenancepriority.h>

namespace storage::distributor {

class PrioritizedBucket {
public:
    using Priority = MaintenancePriority::Priority;

    static const PrioritizedBucket INVALID;

    PrioritizedBucket() noexcept
        : _bucket(),
          _priority(MaintenancePriority::NO_MAINTENANCE_NEEDED)
    {}

    PrioritizedBucket(const document::Bucket &bucket, Priority pri) noexcept
        : _bucket(bucket),
          _priority(pri)
    {
    }

    document::Bucket getBucket() const noexcept { return _bucket; }

    Priority getPriority() const noexcept {
        return _priority;
    }

    [[nodiscard]] bool valid() const noexcept {
        return _bucket.getBucketId().getRawId() != 0;
    }

    std::string toString() const {
        return vespalib::make_string("PrioritizedBucket(%s, pri %s)",
                                     _bucket.toString().c_str(),
                                     MaintenancePriority::toString(_priority));
    }

    bool operator==(const PrioritizedBucket& other) const noexcept {
        return _bucket == other._bucket && _priority == other._priority;
    }

    [[nodiscard]] bool requiresMaintenance() const noexcept {
        return _priority != MaintenancePriority::NO_MAINTENANCE_NEEDED;
    }

    [[nodiscard]] bool moreImportantThan(const PrioritizedBucket& other) const noexcept {
        return _priority > other._priority;
    }

    [[nodiscard]] bool moreImportantThan(Priority otherPri) const noexcept {
        return _priority > otherPri;
    }

private:
    document::Bucket _bucket;
    Priority _priority;
};

std::ostream&
operator<<(std::ostream& os, const PrioritizedBucket& bucket);

}