10#include <unordered_set>
12#include <userver/cache/cache_statistics.hpp>
13#include <userver/cache/caching_component_base.hpp>
14#include <userver/cache/update_type.hpp>
15#include <userver/components/component_fwd.hpp>
16#include <userver/concurrent/variable.hpp>
17#include <userver/dynamic_config/client/client.hpp>
18#include <userver/dynamic_config/storage/component.hpp>
19#include <userver/dynamic_config/updater/additional_keys_token.hpp>
20#include <userver/dynamic_config/updates_sink/component.hpp>
21#include <userver/engine/mutex.hpp>
22#include <userver/utils/impl/transparent_hash.hpp>
24USERVER_NAMESPACE_BEGIN
74class DynamicConfigClientUpdater
final :
public CachingComponentBase<dynamic_config::DocsMap> {
80 DynamicConfigClientUpdater(
const ComponentConfig&,
const ComponentContext&);
82 ~DynamicConfigClientUpdater() override;
92 Update(
cache::
UpdateType update_type,
const std::chrono::system_clock::time_point& last_update,
const std::chrono::system_clock::time_point& now,
cache::UpdateStatisticsScope&)
95 void UpdateFull(
const std::vector<std::string>& docs_map_keys,
cache::UpdateStatisticsScope&);
97 void UpdateIncremental(
const std::vector<std::string>& docs_map_keys,
cache::UpdateStatisticsScope&);
99 void SetDisabledKillSwitchesToDefault(
100 dynamic_config::DocsMap& docs_map,
101 const std::vector<std::string>& kill_switches_disabled
104 dynamic_config::DocsMap MergeDocsMap(
105 const dynamic_config::DocsMap& current,
106 dynamic_config::DocsMap&& update,
107 const std::vector<std::string>& removed
109 void StoreIfEnabled(
const dynamic_config::DocsMap& value);
111 using DocsMapKeys = utils::impl::TransparentSet<std::string>;
112 using AdditionalDocsMapKeys = std::unordered_set<std::shared_ptr<std::vector<std::string>>>;
114 std::vector<std::string> GetDocsMapKeysToFetch(AdditionalDocsMapKeys& additional_docs_map_keys);
116 void UpdateAdditionalKeys(
const std::vector<std::string>& keys);
118 bool IsDuplicate(
cache::
UpdateType update_type,
const dynamic_config::DocsMap& new_value)
const;
121 const bool load_only_my_values_;
122 const bool store_enabled_;
124 dynamic_config::Client& config_client_;
126 dynamic_config::Client::Timestamp server_timestamp_;
128 engine::Mutex update_config_mutex_;
129 dynamic_config::DocsMap docs_map_defaults_;
130 DocsMapKeys docs_map_keys_;
131 concurrent::Variable<AdditionalDocsMapKeys> additional_docs_map_keys_;
135inline constexpr bool kHasValidate<DynamicConfigClientUpdater> =
true;