config.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #pragma once
  2. #include "fwd.h"
  3. #include "common.h"
  4. #include <library/cpp/yt/misc/enum.h>
  5. #include <library/cpp/yson/node/node.h>
  6. #include <util/generic/maybe.h>
  7. #include <util/generic/string.h>
  8. #include <util/generic/hash_set.h>
  9. #include <util/datetime/base.h>
  10. namespace NYT {
  11. enum EEncoding : int
  12. {
  13. E_IDENTITY /* "identity" */,
  14. E_GZIP /* "gzip" */,
  15. E_BROTLI /* "br" */,
  16. E_Z_LZ4 /* "z-lz4" */,
  17. };
  18. enum class ENodeReaderFormat : int
  19. {
  20. Yson, // Always use YSON format,
  21. Skiff, // Always use Skiff format, throw exception if it's not possible (non-strict schema, dynamic table etc.)
  22. Auto, // Use Skiff format if it's possible, YSON otherwise
  23. };
  24. enum class ETraceHttpRequestsMode
  25. {
  26. // Never dump http requests.
  27. Never /* "never" */,
  28. // Dump failed http requests.
  29. Error /* "error" */,
  30. // Dump all http requests.
  31. Always /* "always" */,
  32. };
  33. DEFINE_ENUM(EUploadDeduplicationMode,
  34. // For each file only one process' thread from all possible hosts can upload it to the file cache at the same time.
  35. // The others will wait for the uploading to finish and use already cached file.
  36. ((Global) (0))
  37. // For each file and each particular host only one process' thread can upload it to the file cache at the same time.
  38. // The others will wait for the uploading to finish and use already cached file.
  39. ((Host) (1))
  40. // All processes' threads will upload a file to the cache concurrently.
  41. ((Disabled) (2))
  42. );
  43. ////////////////////////////////////////////////////////////////////////////////
  44. /// Enum describing possible versions of table writer implemetation.
  45. enum class ETableWriterVersion
  46. {
  47. /// Allow library to choose version of writer.
  48. Auto,
  49. /// Stable but slower version of writer.
  50. V1,
  51. /// Unstable but faster version of writer (going to be default in the future).
  52. V2,
  53. };
  54. ////////////////////////////////////////////////////////////////////////////////
  55. struct TConfig
  56. : public TThrRefBase
  57. {
  58. TString Hosts;
  59. TString Pool;
  60. TString Token;
  61. TString Prefix;
  62. TString ApiVersion;
  63. TString LogLevel;
  64. TString LogPath;
  65. ///
  66. /// For historical reasons mapreduce client uses its own logging system.
  67. ///
  68. /// If this options is set to true library switches to yt/yt/core logging by default.
  69. /// But if user calls @ref NYT::SetLogger library switches back to logger provided by user
  70. /// (except for messages from yt/yt/core).
  71. ///
  72. /// This is temporary option. In future it would be true by default, and then removed.
  73. ///
  74. /// https://st.yandex-team.ru/YT-23645
  75. bool LogUseCore = false;
  76. // Compression for data that is sent to YT cluster.
  77. EEncoding ContentEncoding;
  78. // Compression for data that is read from YT cluster.
  79. EEncoding AcceptEncoding;
  80. TString GlobalTxId;
  81. bool ForceIpV4;
  82. bool ForceIpV6;
  83. bool UseHosts;
  84. TDuration HostListUpdateInterval;
  85. TNode Spec;
  86. TNode TableWriter;
  87. TDuration ConnectTimeout;
  88. TDuration SocketTimeout;
  89. TDuration AddressCacheExpirationTimeout;
  90. TDuration TxTimeout;
  91. TDuration PingTimeout;
  92. TDuration PingInterval;
  93. int AsyncHttpClientThreads;
  94. int AsyncTxPingerPoolThreads;
  95. // How often should we poll for lock state
  96. TDuration WaitLockPollInterval;
  97. TDuration RetryInterval;
  98. TDuration ChunkErrorsRetryInterval;
  99. TDuration RateLimitExceededRetryInterval;
  100. TDuration StartOperationRetryInterval;
  101. int RetryCount;
  102. int ReadRetryCount;
  103. int StartOperationRetryCount;
  104. /// @brief Period for checking status of running operation.
  105. TDuration OperationTrackerPollPeriod = TDuration::Seconds(5);
  106. TString RemoteTempFilesDirectory;
  107. TString RemoteTempTablesDirectory;
  108. // @brief Keep temp tables produced by TTempTable (despite their name). Should not be used in user programs,
  109. // but may be useful for setting via environment variable for debugging purposes.
  110. bool KeepTempTables = false;
  111. //
  112. // Infer schemas for nonexstent tables from typed rows (e.g. protobuf)
  113. // when writing from operation or client writer.
  114. // This options can be overridden in TOperationOptions and TTableWriterOptions.
  115. bool InferTableSchema;
  116. bool UseClientProtobuf;
  117. ENodeReaderFormat NodeReaderFormat;
  118. bool ProtobufFormatWithDescriptors;
  119. int ConnectionPoolSize;
  120. /// Defines replication factor that is used for files that are uploaded to YT
  121. /// to use them in operations.
  122. int FileCacheReplicationFactor = 10;
  123. /// @brief Used when waiting for other process which uploads the same file to the file cache.
  124. ///
  125. /// If CacheUploadDeduplicationMode is not Disabled, current process can wait for some other
  126. /// process which is uploading the same file. This value is proportional to the timeout of waiting,
  127. /// actual timeout computes as follows: fileSizeGb * CacheLockTimeoutPerGb.
  128. /// Default timeout assumes that host has uploading speed equal to 20 Mb/s.
  129. /// If timeout was reached, the file will be uploaded by current process without any other waits.
  130. TDuration CacheLockTimeoutPerGb;
  131. /// @brief Used to prevent concurrent uploading of the same file to the file cache.
  132. /// NB: Each mode affects only users with the same mode enabled.
  133. EUploadDeduplicationMode CacheUploadDeduplicationMode;
  134. // @brief Minimum byte size for files to undergo deduplication at upload
  135. i64 CacheUploadDeduplicationThreshold;
  136. bool MountSandboxInTmpfs;
  137. /// @brief Set upload options (e.g.) for files created by library.
  138. ///
  139. /// Path itself is always ignored but path options (e.g. `BypassArtifactCache`) are used when uploading system files:
  140. /// cppbinary, job state, etc
  141. TRichYPath ApiFilePathOptions;
  142. // Testing options, should never be used in user programs.
  143. bool UseAbortableResponse = false;
  144. bool EnableDebugMetrics = false;
  145. //
  146. // There is optimization used with local YT that enables to skip binary upload and use real binary path.
  147. // When EnableLocalModeOptimization is set to false this optimization is completely disabled.
  148. bool EnableLocalModeOptimization = true;
  149. //
  150. // If you want see stderr even if you jobs not failed set this true.
  151. bool WriteStderrSuccessfulJobs = false;
  152. //
  153. // This configuration is useful for debug.
  154. // If set to ETraceHttpRequestsMode::Error library will dump all http error requests.
  155. // If set to ETraceHttpRequestsMode::All library will dump all http requests.
  156. // All tracing occurres as DEBUG level logging.
  157. ETraceHttpRequestsMode TraceHttpRequestsMode = ETraceHttpRequestsMode::Never;
  158. TString SkynetApiHost;
  159. // Sets SO_PRIORITY option on the socket
  160. TMaybe<int> SocketPriority;
  161. // Framing settings
  162. // (cf. https://ytsaurus.tech/docs/en/user-guide/proxy/http-reference#framing).
  163. THashSet<TString> CommandsWithFraming;
  164. /// Which implemetation of table writer to use.
  165. ETableWriterVersion TableWriterVersion = ETableWriterVersion::Auto;
  166. /// Redirects stdout to stderr for jobs.
  167. bool RedirectStdoutToStderr = false;
  168. static bool GetBool(const char* var, bool defaultValue = false);
  169. static int GetInt(const char* var, int defaultValue);
  170. static TDuration GetDuration(const char* var, TDuration defaultValue);
  171. static EEncoding GetEncoding(const char* var);
  172. static EUploadDeduplicationMode GetUploadingDeduplicationMode(
  173. const char* var,
  174. EUploadDeduplicationMode defaultValue);
  175. static void ValidateToken(const TString& token);
  176. static TString LoadTokenFromFile(const TString& tokenPath);
  177. static TNode LoadJsonSpec(const TString& strSpec);
  178. static TRichYPath LoadApiFilePathOptions(const TString& ysonMap);
  179. void LoadToken();
  180. void LoadSpec();
  181. void LoadTimings();
  182. void Reset();
  183. TConfig();
  184. static TConfigPtr Get();
  185. };
  186. ////////////////////////////////////////////////////////////////////////////////
  187. struct TProcessState
  188. {
  189. TString FqdnHostName;
  190. TString UserName;
  191. int Pid;
  192. TString ClientVersion;
  193. TString BinaryPath;
  194. TString BinaryName;
  195. TProcessState();
  196. static TProcessState* Get();
  197. };
  198. ////////////////////////////////////////////////////////////////////////////////
  199. } // namespace NYT