aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/Resource/StaticResourceManager.h
blob: 066dbf4ebf8aac3436bcb63dd0b10a764fd182c5 (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
#pragma once

#include <IO/IResourceManager.h>
#include <IO/SchedulerRoot.h>
#include <IO/Resource/ClassifiersConfig.h>

#include <mutex>

namespace DB
{

/*
 * Reads `<resources>` from config at startup and registers them in single `SchedulerRoot`.
 * Do not support configuration updates, server restart is required.
 */
class StaticResourceManager : public IResourceManager
{
public:
    // Just initialization, any further updates are ignored for the sake of simplicity
    // NOTE: manager must be initialized before any acquire() calls to avoid races
    void updateConfiguration(const Poco::Util::AbstractConfiguration & config) override;

    ClassifierPtr acquire(const String & classifier_name) override;

private:
    struct Resource
    {
        std::unordered_map<String, SchedulerNodePtr> nodes; // by paths

        Resource(
            const String & name,
            EventQueue * event_queue,
            const Poco::Util::AbstractConfiguration & config,
            const std::string & config_prefix);
    };

    struct Classifier : public IClassifier
    {
        Classifier(const StaticResourceManager & manager, const ClassifierDescription & cfg);
        ResourceLink get(const String & resource_name) override;
        std::unordered_map<String, ResourceLink> resources; // accessible resources by names
    };

    SchedulerRoot scheduler;
    std::unordered_map<String, Resource> resources; // by name
    std::unique_ptr<ClassifiersConfig> classifiers;
};

}