aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.h
blob: 07e05dc1585fde7cc704fad852a283f8e10da0eb (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
69
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "documentdbconfig.h"
#include <mutex>

class FNET_Transport;

namespace config {
    class ConfigRetriever;
    class DirSpec;
}
namespace proton {

class BootstrapConfig;

/**
 * This class manages the subscription for documentdb configs.
 */
class DocumentDBConfigManager
{
public:
    using SP = std::shared_ptr<DocumentDBConfigManager>;
    using BootstrapConfigSP = std::shared_ptr<BootstrapConfig>;

private:
    vespalib::string     _configId;
    vespalib::string     _docTypeName;
    BootstrapConfigSP    _bootstrapConfig;
    DocumentDBConfig::SP _pendingConfigSnapshot;
    bool                 _ignoreForwardedConfig;
    mutable std::mutex   _pendingConfigMutex;

    search::index::Schema::SP
    buildSchema(const DocumentDBConfig::AttributesConfig & newAttributesConfig,
                const DocumentDBConfig::IndexschemaConfig & newIndexschemaConfig);

public:
    DocumentDBConfigManager(const vespalib::string &configId, const vespalib::string &docTypeName);
    ~DocumentDBConfigManager();
    void update(FNET_Transport & transport, const config::ConfigSnapshot & snapshot);

    DocumentDBConfig::SP getConfig() const;

    void forwardConfig(const BootstrapConfigSP & config);
    config::ConfigKeySet createConfigKeySet() const;
    const vespalib::string & getConfigId() const { return _configId; }
};

/**
 * Simple helper class to use a config holder in tests and fileconfig manager.
 */
class DocumentDBConfigHelper
{
public:
    DocumentDBConfigHelper(const config::DirSpec &spec, const vespalib::string &docTypeName);
    ~DocumentDBConfigHelper();

    bool nextGeneration(FNET_Transport & transport, vespalib::duration timeout);
    DocumentDBConfig::SP getConfig() const;
    void forwardConfig(const std::shared_ptr<BootstrapConfig> & config);
private:
    DocumentDBConfigManager _mgr;
    std::unique_ptr<config::ConfigRetriever> _retriever;
};

} // namespace proton