config.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #pragma once
  2. #include "fwd.h"
  3. #include "common.h"
  4. #include "node.h"
  5. #include <library/cpp/yt/misc/enum.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. // Compression for data that is sent to YT cluster.
  65. EEncoding ContentEncoding;
  66. // Compression for data that is read from YT cluster.
  67. EEncoding AcceptEncoding;
  68. TString GlobalTxId;
  69. bool ForceIpV4;
  70. bool ForceIpV6;
  71. bool UseHosts;
  72. TDuration HostListUpdateInterval;
  73. TNode Spec;
  74. TNode TableWriter;
  75. TDuration ConnectTimeout;
  76. TDuration SocketTimeout;
  77. TDuration AddressCacheExpirationTimeout;
  78. TDuration TxTimeout;
  79. TDuration PingTimeout;
  80. TDuration PingInterval;
  81. bool UseAsyncTxPinger;
  82. int AsyncHttpClientThreads;
  83. int AsyncTxPingerPoolThreads;
  84. // How often should we poll for lock state
  85. TDuration WaitLockPollInterval;
  86. TDuration RetryInterval;
  87. TDuration ChunkErrorsRetryInterval;
  88. TDuration RateLimitExceededRetryInterval;
  89. TDuration StartOperationRetryInterval;
  90. int RetryCount;
  91. int ReadRetryCount;
  92. int StartOperationRetryCount;
  93. /// @brief Period for checking status of running operation.
  94. TDuration OperationTrackerPollPeriod = TDuration::Seconds(5);
  95. TString RemoteTempFilesDirectory;
  96. TString RemoteTempTablesDirectory;
  97. //
  98. // Infer schemas for nonexstent tables from typed rows (e.g. protobuf)
  99. // when writing from operation or client writer.
  100. // This options can be overridden in TOperationOptions and TTableWriterOptions.
  101. bool InferTableSchema;
  102. bool UseClientProtobuf;
  103. ENodeReaderFormat NodeReaderFormat;
  104. bool ProtobufFormatWithDescriptors;
  105. int ConnectionPoolSize;
  106. /// Defines replication factor that is used for files that are uploaded to YT
  107. /// to use them in operations.
  108. int FileCacheReplicationFactor = 10;
  109. /// @brief Used when waiting for other process which uploads the same file to the file cache.
  110. ///
  111. /// If CacheUploadDeduplicationMode is not Disabled, current process can wait for some other
  112. /// process which is uploading the same file. This value is proportional to the timeout of waiting,
  113. /// actual timeout computes as follows: fileSizeGb * CacheLockTimeoutPerGb.
  114. /// Default timeout assumes that host has uploading speed equal to 20 Mb/s.
  115. /// If timeout was reached, the file will be uploaded by current process without any other waits.
  116. TDuration CacheLockTimeoutPerGb;
  117. /// @brief Used to prevent concurrent uploading of the same file to the file cache.
  118. /// NB: Each mode affects only users with the same mode enabled.
  119. EUploadDeduplicationMode CacheUploadDeduplicationMode;
  120. bool MountSandboxInTmpfs;
  121. /// @brief Set upload options (e.g.) for files created by library.
  122. ///
  123. /// Path itself is always ignored but path options (e.g. `BypassArtifactCache`) are used when uploading system files:
  124. /// cppbinary, job state, etc
  125. TRichYPath ApiFilePathOptions;
  126. // Testing options, should never be used in user programs.
  127. bool UseAbortableResponse = false;
  128. bool EnableDebugMetrics = false;
  129. //
  130. // There is optimization used with local YT that enables to skip binary upload and use real binary path.
  131. // When EnableLocalModeOptimization is set to false this optimization is completely disabled.
  132. bool EnableLocalModeOptimization = true;
  133. //
  134. // If you want see stderr even if you jobs not failed set this true.
  135. bool WriteStderrSuccessfulJobs = false;
  136. //
  137. // This configuration is useful for debug.
  138. // If set to ETraceHttpRequestsMode::Error library will dump all http error requests.
  139. // If set to ETraceHttpRequestsMode::All library will dump all http requests.
  140. // All tracing occurres as DEBUG level logging.
  141. ETraceHttpRequestsMode TraceHttpRequestsMode = ETraceHttpRequestsMode::Never;
  142. TString SkynetApiHost;
  143. // Sets SO_PRIORITY option on the socket
  144. TMaybe<int> SocketPriority;
  145. // Framing settings
  146. // (cf. https://ytsaurus.tech/docs/en/user-guide/proxy/http-reference#framing).
  147. THashSet<TString> CommandsWithFraming;
  148. /// Which implemetation of table writer to use.
  149. ETableWriterVersion TableWriterVersion = ETableWriterVersion::Auto;
  150. static bool GetBool(const char* var, bool defaultValue = false);
  151. static int GetInt(const char* var, int defaultValue);
  152. static TDuration GetDuration(const char* var, TDuration defaultValue);
  153. static EEncoding GetEncoding(const char* var);
  154. static EUploadDeduplicationMode GetUploadingDeduplicationMode(
  155. const char* var,
  156. EUploadDeduplicationMode defaultValue);
  157. static void ValidateToken(const TString& token);
  158. static TString LoadTokenFromFile(const TString& tokenPath);
  159. static TNode LoadJsonSpec(const TString& strSpec);
  160. static TRichYPath LoadApiFilePathOptions(const TString& ysonMap);
  161. void LoadToken();
  162. void LoadSpec();
  163. void LoadTimings();
  164. void Reset();
  165. TConfig();
  166. static TConfigPtr Get();
  167. };
  168. ////////////////////////////////////////////////////////////////////////////////
  169. struct TProcessState
  170. {
  171. TString FqdnHostName;
  172. TString UserName;
  173. TVector<TString> CommandLine;
  174. // Command line with everything that looks like tokens censored.
  175. TVector<TString> CensoredCommandLine;
  176. int Pid;
  177. TString ClientVersion;
  178. TProcessState();
  179. void SetCommandLine(int argc, const char* argv[]);
  180. static TProcessState* Get();
  181. };
  182. ////////////////////////////////////////////////////////////////////////////////
  183. } // namespace NYT