// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "executor_thread_service.h" #include "i_proton_configurer.h" #include #include #include #include #include #include namespace proton { class DocumentDBDirectoryHolder; class IDocumentDBConfigOwner; class IProtonConfigurerOwner; class BootstrapConfig; class IProtonDiskLayout; /* * Class to handle config changes to proton using config snapshots spanning * all document types. */ class ProtonConfigurer : public IProtonConfigurer { using DocumentDBs = std::map, std::weak_ptr>>; using InitializeThreads = std::shared_ptr; class ReconfigureTask; ExecutorThreadService _executor; IProtonConfigurerOwner &_owner; DocumentDBs _documentDBs; std::shared_ptr _pendingConfigSnapshot; std::shared_ptr _activeConfigSnapshot; mutable std::mutex _mutex; bool _allowReconfig; vespalib::SimpleComponentConfigProducer _componentConfig; const std::unique_ptr &_diskLayout; vespalib::MonitoredRefCount _pendingReconfigureTasks; void performReconfigure(); bool skipConfig(const ProtonConfigSnapshot *configSnapshot, bool initialConfig); void applyConfig(std::shared_ptr configSnapshot, InitializeThreads initializeThreads, bool initialConfig); void configureDocumentDB(const ProtonConfigSnapshot &configSnapshot, const DocTypeName &docTypeName, document::BucketSpace bucketSpace, const vespalib::string &configId, InitializeThreads initializeThreads); void pruneDocumentDBs(const ProtonConfigSnapshot &configSnapshot); void pruneInitialDocumentDBDirs(const ProtonConfigSnapshot &configSnapshot); public: ProtonConfigurer(vespalib::ThreadExecutor &executor, IProtonConfigurerOwner &owner, const std::unique_ptr &diskLayout); ~ProtonConfigurer() override; void setAllowReconfig(bool allowReconfig); std::shared_ptr getPendingConfigSnapshot(); std::shared_ptr getActiveConfigSnapshot() const; void reconfigure(std::shared_ptr configSnapshot) override; void applyInitialConfig(InitializeThreads initializeThreads); vespalib::SimpleComponentConfigProducer &getComponentConfig() { return _componentConfig; } }; } // namespace proton