C++ YT Wrapper
C++ library for working with YT clusters
Loading...
Searching...
No Matches
config.h
1#pragma once
2
3#include "fwd.h"
4#include "common.h"
5#include "patchable_field.h"
6
7#include <library/cpp/yt/misc/enum.h>
8
9#include <library/cpp/yt/yson_string/public.h>
10
11#include <library/cpp/yson/node/node.h>
12
13#include <util/generic/maybe.h>
14#include <util/generic/string.h>
15#include <util/generic/hash.h>
16#include <util/generic/hash_set.h>
17
18#include <util/datetime/base.h>
19
20namespace NYT {
21
23
24namespace NYson {
25
27
28struct IYsonConsumer;
29
30enum class EYsonFormat : int;
31
33
34} // namespace NYson
35
37
38namespace NLogLevel {
39 inline constexpr std::string_view Fatal = "fatal";
40 inline constexpr std::string_view Error = "error";
41 inline constexpr std::string_view Info = "info";
42 inline constexpr std::string_view Debug = "debug";
43} // namespace NLogLevel
44
46
47extern const TString DefaultHosts;
48extern const TString DefaultRemoteTempTablesDirectory;
49extern const TString DefaultRemoteTempFilesDirectory;
50
52
53enum EEncoding : int
54{
55 E_IDENTITY /* "identity" */,
56 E_GZIP /* "gzip" */,
57 E_BROTLI /* "br" */,
58 E_Z_LZ4 /* "z-lz4" */,
59};
60
61enum class ENodeReaderFormat : int
62{
63 Yson, // Always use YSON format,
64 Skiff, // Always use Skiff format, throw exception if it's not possible (non-strict schema, dynamic table etc.)
65 Auto, // Use Skiff format if it's possible, YSON otherwise
66};
67
68enum class ETraceHttpRequestsMode
69{
70 // Never dump http requests.
71 Never /* "never" */,
72 // Dump failed http requests.
73 Error /* "error" */,
74 // Dump all http requests.
75 Always /* "always" */,
76};
77
78DEFINE_ENUM(EUploadDeduplicationMode,
79 // For each file only one process' thread from all possible hosts can upload it to the file cache at the same time.
80 // The others will wait for the uploading to finish and use already cached file.
81 ((Global) (0))
82
83 // For each file and each particular host only one process' thread can upload it to the file cache at the same time.
84 // The others will wait for the uploading to finish and use already cached file.
85 ((Host) (1))
86
87 // All processes' threads will upload a file to the cache concurrently.
88 ((Disabled) (2))
89);
90
92
95{
97 Auto,
98
101
104};
105
107
108struct TConfig
109 : public TThrRefBase
110{
111 TString Hosts;
112 TString Pool;
113 TString Token;
114 TString Prefix;
115 TString ApiVersion;
116 TString LogLevel;
117 TString LogPath;
118 THashSet<TString> LogExcludeCategories = {"Bus", "Net", "Dns", "Concurrency"};
119
123
128
131
136 THashMap<TString, TString> ProxyUrlAliasingRules;
137
147 bool LogUseCore = true;
148
149 // Compression for data that is sent to YT cluster.
150 EEncoding ContentEncoding;
151
152 // Compression for data that is read from YT cluster.
153 EEncoding AcceptEncoding;
154
155 TString GlobalTxId;
156
157 bool ForceIpV4;
158 bool ForceIpV6;
159 bool UseHosts;
160
163
164 bool UseTLS;
165
166 TDuration HostListUpdateInterval;
167
168 TNode Spec;
169 TNode TableWriter;
170
171 TDuration ConnectTimeout;
172 TDuration SocketTimeout;
173 TDuration AddressCacheExpirationTimeout;
174 TDuration TxTimeout;
175 TDuration PingTimeout;
176 TDuration PingInterval;
177
178 int AsyncHttpClientThreads;
179 int AsyncTxPingerPoolThreads;
180
181 // How often should we poll for lock state
182 TDuration WaitLockPollInterval;
183
184 TDuration RetryInterval;
185 TDuration ChunkErrorsRetryInterval;
186
187 TDuration RateLimitExceededRetryInterval;
188 TDuration StartOperationRetryInterval;
189
190 int RetryCount;
191 int ReadRetryCount;
192 int StartOperationRetryCount;
193
194 // The CheckClusterLiveness operation should be retried, but fewer times than other operations.
195 int CheckLivenessRetryCount;
196
198 TDuration OperationTrackerPollPeriod = TDuration::Seconds(5);
199
200 TString RemoteTempFilesDirectory;
201 TString RemoteTempTablesDirectory;
202 // @brief Keep temp tables produced by TTempTable (despite their name). Should not be used in user programs,
203 // but may be useful for setting via environment variable for debugging purposes.
204 bool KeepTempTables = false;
205
206 //
207 // Infer schemas for nonexstent tables from typed rows (e.g. protobuf)
208 // when writing from operation or client writer.
209 // This options can be overridden in TOperationOptions and TTableWriterOptions.
210 bool InferTableSchema;
211
212 bool UseClientProtobuf;
213 ENodeReaderFormat NodeReaderFormat;
214 bool ProtobufFormatWithDescriptors;
215
216 int ConnectionPoolSize;
217
221
230
233 EUploadDeduplicationMode CacheUploadDeduplicationMode;
234
235 // @brief Minimum byte size for files to undergo deduplication at upload
236 i64 CacheUploadDeduplicationThreshold;
237
244 bool LockFileStorage = false;
245
246 bool MountSandboxInTmpfs;
247
253
254 // Testing options, should never be used in user programs.
255 bool UseAbortableResponse = false;
256 bool EnableDebugMetrics = false;
257
262 bool UseHaltingResponse = false;
263
269
270 //
271 // There is optimization used with local YT that enables to skip binary upload and use real binary path.
272 // When EnableLocalModeOptimization is set to false this optimization is completely disabled.
273 bool EnableLocalModeOptimization = true;
274
275 //
276 // If you want see stderr even if you jobs not failed set this true.
277 bool WriteStderrSuccessfulJobs = false;
278
279 //
280 // This configuration is useful for debug.
281 // If set to ETraceHttpRequestsMode::Error library will dump all http error requests.
282 // If set to ETraceHttpRequestsMode::All library will dump all http requests.
283 // All tracing occurres as DEBUG level logging.
284 ETraceHttpRequestsMode TraceHttpRequestsMode = ETraceHttpRequestsMode::Never;
285
286 TString SkynetApiHost;
287
288 // Sets SO_PRIORITY option on the socket
289 TMaybe<int> SocketPriority;
290
291 // Framing settings
292 // (cf. https://ytsaurus.tech/docs/en/user-guide/proxy/http-reference#framing).
293 THashSet<TString> CommandsWithFraming;
294
297
300
303
305 TString ConfigRemotePatchPath = "//sys/client_config";
306
308 TPatchableField<TString> OperationLinkPattern = TPatchableField<TString>("operation_link_pattern", "https://yt.yandex-team.ru/{cluster_ui_host}/operations/{operation_id}");
309
312
314 // and the native client sends lightweight control requests via a separate multiplexing band.
316
317 static bool GetBool(const char* var, bool defaultValue = false);
318 static int GetInt(const char* var, int defaultValue);
319 static TDuration GetDuration(const char* var, TDuration defaultValue);
320 static EEncoding GetEncoding(const char* var);
321 static EUploadDeduplicationMode GetUploadingDeduplicationMode(
322 const char* var,
323 EUploadDeduplicationMode defaultValue);
324
325 static void ValidateToken(const TString& token);
326 static TString LoadTokenFromFile(const TString& tokenPath);
327
328 static TNode LoadJsonSpec(const TString& strSpec);
329
330 static TRichYPath LoadApiFilePathOptions(const TString& ysonMap);
331
332 void LoadToken();
333 void LoadSpec();
334 void LoadTimings();
335 void LoadProxyUrlAliasingRules();
336
337 void Reset();
338
339 TConfig();
340
341 static TConfigPtr Get();
342};
343
345
346void Serialize(const TConfig& config, NYson::IYsonConsumer* consumer);
347
348void Deserialize(TConfig& config, const TNode& node);
349
351
352TString ConfigToYsonString(const TConfig& config, NYson::EYsonFormat format = NYson::EYsonFormat::Pretty);
353
354TConfig ConfigFromYsonString(TString serializedConfig);
355
357
358struct TProcessState
359{
360 TString FqdnHostName;
361 TString UserName;
362
363 int Pid;
364 TString ClientVersion;
365 TString BinaryPath;
366 TString BinaryName;
367
368 TProcessState();
369
370 static TProcessState* Get();
371};
372
374
375} // namespace NYT
Definition patchable_field.h:23
Main namespace of YT client.
Definition abortable_stream.h:7
ETableWriterVersion
Enum describing possible versions of table writer implemetation.
Definition config.h:95
@ Auto
Allow library to choose version of writer.
Definition config.h:97
@ V1
Stable but slower version of writer.
Definition config.h:100
@ V2
Unstable but faster version of writer (going to be default in the future).
Definition config.h:103
@ Disabled
Auto merge is disabled.
Definition operation.h:159
Definition config.h:110
TDuration CacheLockTimeoutPerGb
Used when waiting for other process which uploads the same file to the file cache.
Definition config.h:229
TPatchableField< TString > OperationLinkPattern
Pattern for generating operation web link in |GetOperationWebInterfaceUrl|.
Definition config.h:308
THashMap< TString, TString > ProxyUrlAliasingRules
Proxy url aliasing rules to be used for connection.
Definition config.h:136
TString StructuredLog
Path to the structured log file for recording telemetry data in JSON format. This allows later retrie...
Definition config.h:122
bool EnableControlMultiplexingBand
If true, all RPC requests share a single connection,.
Definition config.h:315
TRichYPath ApiFilePathOptions
Set upload options (e.g.) for files created by library.
Definition config.h:252
bool LockFileStorage
Take a shared lock on the file cache directory during operation preparation.
Definition config.h:244
TPatchableField< i64 > FileCacheReplicationFactor
Definition config.h:220
bool PreferHttps
Use https if no schema was provided in proxy url.
Definition config.h:162
bool RedirectStdoutToStderr
Redirects stdout to stderr for jobs.
Definition config.h:299
TDuration OperationTrackerPollPeriod
Period for checking status of running operation.
Definition config.h:198
TString HttpProxyRole
Represents the role involved in HTTP proxy configuration.
Definition config.h:127
ETableWriterVersion TableWriterVersion
Which implemetation of table writer to use.
Definition config.h:296
bool EnableDebugCommandLineArguments
Append job and operation IDs as shell command options.
Definition config.h:302
bool UseHaltingResponse
Simulate a response that halts (stops sending data) mid-stream.
Definition config.h:262
bool LogUseCore
Definition config.h:147
TString ConfigRemotePatchPath
Path to document node with cluster config for |IClientGetDynamicConfiguration|.
Definition config.h:305
bool EnableClientTracing
Allow to create trace_id on client side and propogate with request.
Definition config.h:311
i64 HaltingResponseBytesLimit
Maximum number of bytes sent before the response is halted.
Definition config.h:268
TString RpcProxyRole
Represents the role involved in RPC proxy configuration.
Definition config.h:130
EUploadDeduplicationMode CacheUploadDeduplicationMode
Used to prevent concurrent uploading of the same file to the file cache. NB: Each mode affects only u...
Definition config.h:233
Path with additional attributes.
Definition common.h:1040