// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "indexenvironment.h" #include #include #include #include #include namespace streaming { /** handle per-document-type indexing environment */ class IndexEnvPrototype { private: search::fef::TableManager _tableManager; streaming::IndexEnvironment _prototype; public: IndexEnvPrototype(); void detectFields(const vespa::config::search::vsm::VsmfieldsConfig &fields); void set_ranking_assets_repo(std::shared_ptr repo) { _prototype.set_ranking_assets_repo(std::move(repo)); } std::unique_ptr clone() const { return std::make_unique(_prototype); } const IndexEnvironment& current() const { return _prototype; } }; /** * This class subscribes to the rank-profiles config and keeps a setup per rank profile. **/ class RankManager { public: /** collection of field ids for an index **/ using View = std::vector; using IRankingAssetsRepo = search::fef::IRankingAssetsRepo; /** * This class represents a snapshot of the rank-profiles config with associated setup per rank profile. * A new instance of this class is created as part of reload config. **/ class Snapshot { private: using NamedPropertySet = std::pair; using ViewMap = vespalib::hash_map; using Map = vespalib::hash_map; IndexEnvPrototype _protoEnv; std::vector _properties; // property set per rank profile std::vector _indexEnv; // index environment per rank profile std::vector> _rankSetup; // rank setup per rank profile Map _rpmap; ViewMap _views; void addProperties(const vespa::config::search::RankProfilesConfig & cfg); void buildFieldMappings(const vsm::VsmfieldsHandle & fields); bool initRankSetup(const search::fef::BlueprintFactory & factory); bool setup(const RankManager & manager); int getIndex(const vespalib::string & key) const { auto found = _rpmap.find(key); return (found != _rpmap.end()) ? found->second : 0; } public: Snapshot(); ~Snapshot(); const std::vector & getProperties() const { return _properties; } bool setup(const RankManager & manager, const vespa::config::search::RankProfilesConfig & cfg, std::shared_ptr ranking_assets_repo); const search::fef::RankSetup & getRankSetup(const vespalib::string &rankProfile) const { return *(_rankSetup[getIndex(rankProfile)]); } const IndexEnvironment & getIndexEnvironment(const vespalib::string &rankProfile) const { return _indexEnv[getIndex(rankProfile)]; } const View *getView(const vespalib::string & index) const { auto itr = _views.find(index); if (itr != _views.end()) { return &itr->second; } return nullptr; } }; private: search::fef::BlueprintFactory _blueprintFactory; vespalib::PtrHolder _snapshot; const vsm::VSMAdapter * _vsmAdapter; void configureRankProfiles(const vespa::config::search::RankProfilesConfig & cfg, std::shared_ptr ranking_assets_repo); virtual void notify(const vsm::VSMConfigSnapshot & snapshot, std::shared_ptr ranking_assets_repo); public: RankManager(vsm::VSMAdapter * const vsmAdapter); virtual ~RankManager(); void configure(const vsm::VSMConfigSnapshot & snap, std::shared_ptr ranking_assets_repo); /** * Retrieves the current snapshot of the rank-profiles config. **/ std::shared_ptr getSnapshot() const { return _snapshot.get(); } }; } // namespace streaming