C++ YT Wrapper
C++ library for working with YT clusters
Loading...
Searching...
No Matches
patchable_field.h
1#pragma once
2
3#include "fwd.h"
4
5#include <library/cpp/yson/node/node.h>
6
7namespace NYT {
8
10
11namespace NDetail {
12
13const TNode::TMapType& GetDynamicConfiguration(const IClientPtr& client, const TString& configProfile);
14
15} // namespace NDetail
16
18
19// |NYT::TConfig| field supporting per-client overriding with cluster configuration.
20// |T| must be one of |TNode| value types.
21template <typename T>
22class TPatchableField
23{
24public:
25 static constexpr char ConfigProfile[] = "default";
26
27 TPatchableField(TString name, T defaultValue)
28 : Name_(std::move(name))
29 , Value_(std::move(defaultValue))
30 { }
31
32 const T& Get(const IClientPtr& client)
33 {
34 if (!Patched_) {
35 const auto& clusterConfig = NDetail::GetDynamicConfiguration(client, ConfigProfile);
36 auto iter = clusterConfig.find(Name_);
37 if (!iter.IsEnd()) {
38 if (iter->second.IsOfType<T>()) {
39 Value_ = iter->second.As<T>();
40 } else {
41 ythrow yexception() << Name_ << " must be " << typeid(T).name();
42 }
43 }
44 }
45 return Value_;
46 }
47
48 void Set(const T& value)
49 {
50 Value_ = value;
51 Patched_ = true;
52 }
53
54private:
55 TString Name_;
56 T Value_;
57 bool Patched_ = false;
58};
59
61
62} // namespace NYT
Main namespace of YT client.
Definition abortable_stream.h:7