aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/ResourceLink.h
blob: 2da5e75fcba3008a98170de9d9355b7ba55e4b53 (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
#pragma once

#include <base/types.h>

#include <IO/ResourceRequest.h>
#include <IO/ISchedulerQueue.h>


namespace DB
{

/*
 * Everything required for resource consumption. Connection to a specific resource queue.
 */
struct ResourceLink
{
    ISchedulerQueue * queue = nullptr;
    bool operator==(const ResourceLink &) const = default;

    void adjust(ResourceCost estimated_cost, ResourceCost real_cost) const
    {
        if (queue)
            queue->adjustBudget(estimated_cost, real_cost);
    }

    void consumed(ResourceCost cost) const
    {
        if (queue)
            queue->consumeBudget(cost);
    }

    void accumulate(ResourceCost cost) const
    {
        if (queue)
            queue->accumulateBudget(cost);
    }
};

}