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

#include "prioritizedbucket.h"
#include <vespa/storage/bucketdb/bucketdatabase.h>
#include <boost/iterator/iterator_facade.hpp>

namespace storage::distributor {

class BucketPriorityDatabase
{
protected:
    class ConstIteratorImpl
    {
    public:
        virtual ~ConstIteratorImpl() = default;
        virtual void increment() noexcept = 0;
        virtual bool equal(const ConstIteratorImpl& other) const noexcept = 0;
        virtual PrioritizedBucket dereference() const noexcept = 0;
    };

    using ConstIteratorImplPtr = std::unique_ptr<ConstIteratorImpl>;
public:
    class ConstIterator
        : public boost::iterator_facade<
              ConstIterator,
              PrioritizedBucket const,
              boost::forward_traversal_tag,
              PrioritizedBucket
        >
    {
        ConstIteratorImplPtr _impl;
    public:
        explicit ConstIterator(ConstIteratorImplPtr impl) noexcept
            : _impl(std::move(impl))
        {}
        ConstIterator(const ConstIterator &) = delete;
        ConstIterator(ConstIterator &&) noexcept = default;

        virtual ~ConstIterator() = default;
    private:
        friend class boost::iterator_core_access;

        void increment() noexcept {
            _impl->increment();
        }

        [[nodiscard]] bool equal(const ConstIterator& other) const noexcept {
            return _impl->equal(*other._impl);
        }

        PrioritizedBucket dereference() const noexcept {
            return _impl->dereference();
        }
    };

    using const_iterator = ConstIterator;

    virtual ~BucketPriorityDatabase() = default;
    
    virtual const_iterator begin() const = 0;
    virtual const_iterator end() const = 0;
    virtual void setPriority(const PrioritizedBucket&) = 0;
};

}