aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/nodeinfo.h
blob: 35ab96363fa885b05819f22b46ca6cc6562014d3 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * \class storage::distributor::NodeInfo
 * \ingroup distributor
 *
 * \brief Keeps track of node state for all storage nodes.
 */
#pragma once

#include <vector>
#include <vespa/vespalib/util/time.h>

namespace storage::framework{
    struct Clock;
}
namespace storage::distributor {

class NodeInfo {
public:
    explicit NodeInfo(const framework::Clock& clock) noexcept;
    uint32_t getPendingCount(uint16_t idx) const;
    bool isBusy(uint16_t idx) const;
    void setBusy(uint16_t idx, vespalib::duration for_duration);
    void incPending(uint16_t idx);
    void decPending(uint16_t idx);
    void clearPending(uint16_t idx);

private:
    struct SingleNodeInfo {
        SingleNodeInfo() noexcept : _pending(0), _busyUntilTime() {}

        uint32_t                      _pending;
        mutable vespalib::steady_time _busyUntilTime;
    };

    mutable std::vector<SingleNodeInfo> _nodes;
    const framework::Clock&             _clock;

    const SingleNodeInfo& getNode(uint16_t idx) const;
    SingleNodeInfo& getNode(uint16_t idx);
};

}