// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "rankmanager.h" #include #include #include #include #include #include #include #include class FNET_Transport; class Fast_NormalizeWordFolder; namespace search::fef { struct IRankingAssetsRepo; class OnnxModels; class RankingAssetsBuilder; class RankingConstants; class RankingExpressions; } namespace streaming { class SearchEnvironmentSnapshot; class SearchEnvironment : public storage::VisitorEnvironment { private: class Env : public config::SimpleConfigurable { public: using SP = std::shared_ptr; Env(const config::ConfigUri& configUri, const Fast_NormalizeWordFolder& wf, FNET_Transport* transport, const vespalib::string& file_distributor_connection_spec); ~Env() override; void configure(const config::ConfigSnapshot & snapshot) override; static config::ConfigKeySet createKeySet(const vespalib::string & configId); std::shared_ptr get_snapshot(); private: template void configure_ranking_asset(std::shared_ptr &ranking_asset, const config::ConfigSnapshot& snapshot, search::fef::RankingAssetsBuilder& builder); const vespalib::string _configId; config::SimpleConfigurer _configurer; std::unique_ptr _vsmAdapter; std::unique_ptr _rankManager; std::shared_ptr _snapshot; std::mutex _lock; vespalib::eval::ConstantTensorLoader _tensor_loader; vespalib::eval::ConstantValueCache _constant_value_cache; uint64_t _generation; std::shared_ptr _onnx_models; std::shared_ptr _ranking_constants; std::shared_ptr _ranking_expressions; std::shared_ptr _ranking_assets_repo; FNET_Transport* const _transport; const vespalib::string _file_distributor_connection_spec; }; using EnvMap = vespalib::hash_map; using EnvMapUP = std::unique_ptr; using ThreadLocals = std::vector; static __thread EnvMap * _localEnvMap; EnvMap _envMap; ThreadLocals _threadLocals; std::mutex _lock; std::unique_ptr _wordFolder; config::ConfigUri _configUri; FNET_Transport* const _transport; vespalib::string _file_distributor_connection_spec; Env & getEnv(const vespalib::string & config_id); public: SearchEnvironment(const config::ConfigUri & configUri, FNET_Transport* transport, const vespalib::string& file_distributor_connection_spec); ~SearchEnvironment(); std::shared_ptr get_snapshot(const vespalib::string& config_id); std::optional get_oldest_config_generation(); // Should only be used by unit tests to simulate that the calling thread is finished. void clear_thread_local_env_map(); }; }