/root/doris/be/src/util/s3_util.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "util/s3_util.h" |
19 | | |
20 | | #include <aws/core/auth/AWSAuthSigner.h> |
21 | | #include <aws/core/auth/AWSCredentials.h> |
22 | | #include <aws/core/auth/AWSCredentialsProviderChain.h> |
23 | | #include <aws/core/client/DefaultRetryStrategy.h> |
24 | | #include <aws/core/utils/logging/LogLevel.h> |
25 | | #include <aws/core/utils/logging/LogSystemInterface.h> |
26 | | #include <aws/core/utils/memory/stl/AWSStringStream.h> |
27 | | #include <aws/s3/S3Client.h> |
28 | | #include <bvar/reducer.h> |
29 | | #include <util/string_util.h> |
30 | | |
31 | | #include <atomic> |
32 | | #ifdef USE_AZURE |
33 | | #include <azure/storage/blobs/blob_container_client.hpp> |
34 | | #endif |
35 | | #include <cstdlib> |
36 | | #include <filesystem> |
37 | | #include <functional> |
38 | | #include <memory> |
39 | | #include <ostream> |
40 | | #include <utility> |
41 | | |
42 | | #include "common/config.h" |
43 | | #include "common/logging.h" |
44 | | #include "common/status.h" |
45 | | #include "cpp/obj_retry_strategy.h" |
46 | | #include "cpp/sync_point.h" |
47 | | #ifdef USE_AZURE |
48 | | #include "io/fs/azure_obj_storage_client.h" |
49 | | #endif |
50 | | #include "io/fs/obj_storage_client.h" |
51 | | #include "io/fs/s3_obj_storage_client.h" |
52 | | #include "runtime/exec_env.h" |
53 | | #include "s3_uri.h" |
54 | | #include "vec/exec/scan/scanner_scheduler.h" |
55 | | |
56 | | namespace doris { |
57 | | namespace s3_bvar { |
58 | | bvar::LatencyRecorder s3_get_latency("s3_get"); |
59 | | bvar::LatencyRecorder s3_put_latency("s3_put"); |
60 | | bvar::LatencyRecorder s3_delete_object_latency("s3_delete_object"); |
61 | | bvar::LatencyRecorder s3_delete_objects_latency("s3_delete_objects"); |
62 | | bvar::LatencyRecorder s3_head_latency("s3_head"); |
63 | | bvar::LatencyRecorder s3_multi_part_upload_latency("s3_multi_part_upload"); |
64 | | bvar::LatencyRecorder s3_list_latency("s3_list"); |
65 | | bvar::LatencyRecorder s3_list_object_versions_latency("s3_list_object_versions"); |
66 | | bvar::LatencyRecorder s3_get_bucket_version_latency("s3_get_bucket_version"); |
67 | | bvar::LatencyRecorder s3_copy_object_latency("s3_copy_object"); |
68 | | }; // namespace s3_bvar |
69 | | |
70 | | namespace { |
71 | | |
72 | 2 | doris::Status is_s3_conf_valid(const S3ClientConf& conf) { |
73 | 2 | if (conf.endpoint.empty()) { |
74 | 0 | return Status::InvalidArgument<false>("Invalid s3 conf, empty endpoint"); |
75 | 0 | } |
76 | 2 | if (conf.region.empty()) { |
77 | 0 | return Status::InvalidArgument<false>("Invalid s3 conf, empty region"); |
78 | 0 | } |
79 | 2 | if (conf.ak.empty()) { |
80 | 0 | return Status::InvalidArgument<false>("Invalid s3 conf, empty ak"); |
81 | 0 | } |
82 | 2 | if (conf.sk.empty()) { |
83 | 0 | return Status::InvalidArgument<false>("Invalid s3 conf, empty sk"); |
84 | 0 | } |
85 | 2 | return Status::OK(); |
86 | 2 | } |
87 | | |
88 | | // Return true is convert `str` to int successfully |
89 | 0 | bool to_int(std::string_view str, int& res) { |
90 | 0 | auto [_, ec] = std::from_chars(str.data(), str.data() + str.size(), res); |
91 | 0 | return ec == std::errc {}; |
92 | 0 | } |
93 | | |
94 | | constexpr char USE_PATH_STYLE[] = "use_path_style"; |
95 | | |
96 | | constexpr char AZURE_PROVIDER_STRING[] = "AZURE"; |
97 | | constexpr char S3_PROVIDER[] = "provider"; |
98 | | constexpr char S3_AK[] = "AWS_ACCESS_KEY"; |
99 | | constexpr char S3_SK[] = "AWS_SECRET_KEY"; |
100 | | constexpr char S3_ENDPOINT[] = "AWS_ENDPOINT"; |
101 | | constexpr char S3_REGION[] = "AWS_REGION"; |
102 | | constexpr char S3_TOKEN[] = "AWS_TOKEN"; |
103 | | constexpr char S3_MAX_CONN_SIZE[] = "AWS_MAX_CONN_SIZE"; |
104 | | constexpr char S3_REQUEST_TIMEOUT_MS[] = "AWS_REQUEST_TIMEOUT_MS"; |
105 | | constexpr char S3_CONN_TIMEOUT_MS[] = "AWS_CONNECTION_TIMEOUT_MS"; |
106 | | |
107 | 2 | auto metric_func_factory(bvar::Adder<int64_t>& ns_bvar, bvar::Adder<int64_t>& req_num_bvar) { |
108 | 2 | return [&](int64_t ns) { |
109 | 0 | if (ns > 0) { |
110 | 0 | ns_bvar << ns; |
111 | 0 | } else { |
112 | 0 | req_num_bvar << 1; |
113 | 0 | } |
114 | 0 | }; |
115 | 2 | } |
116 | | |
117 | | } // namespace |
118 | | |
119 | | bvar::Adder<int64_t> get_rate_limit_ns("get_rate_limit_ns"); |
120 | | bvar::Adder<int64_t> get_rate_limit_exceed_req_num("get_rate_limit_exceed_req_num"); |
121 | | bvar::Adder<int64_t> put_rate_limit_ns("put_rate_limit_ns"); |
122 | | bvar::Adder<int64_t> put_rate_limit_exceed_req_num("put_rate_limit_exceed_req_num"); |
123 | | |
124 | 0 | S3RateLimiterHolder* S3ClientFactory::rate_limiter(S3RateLimitType type) { |
125 | 0 | CHECK(type == S3RateLimitType::GET || type == S3RateLimitType::PUT) << to_string(type); |
126 | 0 | return _rate_limiters[static_cast<size_t>(type)].get(); |
127 | 0 | } |
128 | | |
129 | 0 | int reset_s3_rate_limiter(S3RateLimitType type, size_t max_speed, size_t max_burst, size_t limit) { |
130 | 0 | if (type == S3RateLimitType::UNKNOWN) { |
131 | 0 | return -1; |
132 | 0 | } |
133 | 0 | return S3ClientFactory::instance().rate_limiter(type)->reset(max_speed, max_burst, limit); |
134 | 0 | } |
135 | | |
136 | | class DorisAWSLogger final : public Aws::Utils::Logging::LogSystemInterface { |
137 | | public: |
138 | 0 | DorisAWSLogger() : _log_level(Aws::Utils::Logging::LogLevel::Info) {} |
139 | 0 | DorisAWSLogger(Aws::Utils::Logging::LogLevel log_level) : _log_level(log_level) {} |
140 | 0 | ~DorisAWSLogger() final = default; |
141 | 0 | Aws::Utils::Logging::LogLevel GetLogLevel() const final { return _log_level; } |
142 | | void Log(Aws::Utils::Logging::LogLevel log_level, const char* tag, const char* format_str, |
143 | 0 | ...) final { |
144 | 0 | _log_impl(log_level, tag, format_str); |
145 | 0 | } |
146 | | void LogStream(Aws::Utils::Logging::LogLevel log_level, const char* tag, |
147 | 0 | const Aws::OStringStream& message_stream) final { |
148 | 0 | _log_impl(log_level, tag, message_stream.str().c_str()); |
149 | 0 | } |
150 | | |
151 | 0 | void Flush() final {} |
152 | | |
153 | | private: |
154 | 0 | void _log_impl(Aws::Utils::Logging::LogLevel log_level, const char* tag, const char* message) { |
155 | 0 | switch (log_level) { |
156 | 0 | case Aws::Utils::Logging::LogLevel::Off: |
157 | 0 | break; |
158 | 0 | case Aws::Utils::Logging::LogLevel::Fatal: |
159 | 0 | LOG(FATAL) << "[" << tag << "] " << message; |
160 | 0 | break; |
161 | 0 | case Aws::Utils::Logging::LogLevel::Error: |
162 | 0 | LOG(ERROR) << "[" << tag << "] " << message; |
163 | 0 | break; |
164 | 0 | case Aws::Utils::Logging::LogLevel::Warn: |
165 | 0 | LOG(WARNING) << "[" << tag << "] " << message; |
166 | 0 | break; |
167 | 0 | case Aws::Utils::Logging::LogLevel::Info: |
168 | 0 | LOG(INFO) << "[" << tag << "] " << message; |
169 | 0 | break; |
170 | 0 | case Aws::Utils::Logging::LogLevel::Debug: |
171 | 0 | LOG(INFO) << "[" << tag << "] " << message; |
172 | 0 | break; |
173 | 0 | case Aws::Utils::Logging::LogLevel::Trace: |
174 | 0 | LOG(INFO) << "[" << tag << "] " << message; |
175 | 0 | break; |
176 | 0 | default: |
177 | 0 | break; |
178 | 0 | } |
179 | 0 | } |
180 | | |
181 | | std::atomic<Aws::Utils::Logging::LogLevel> _log_level; |
182 | | }; |
183 | | |
184 | 1 | S3ClientFactory::S3ClientFactory() { |
185 | 1 | _aws_options = Aws::SDKOptions {}; |
186 | 1 | auto logLevel = static_cast<Aws::Utils::Logging::LogLevel>(config::aws_log_level); |
187 | 1 | _aws_options.loggingOptions.logLevel = logLevel; |
188 | 1 | _aws_options.loggingOptions.logger_create_fn = [logLevel] { |
189 | 0 | return std::make_shared<DorisAWSLogger>(logLevel); |
190 | 0 | }; |
191 | 1 | Aws::InitAPI(_aws_options); |
192 | 1 | _ca_cert_file_path = get_valid_ca_cert_path(); |
193 | 1 | _rate_limiters = { |
194 | 1 | std::make_unique<S3RateLimiterHolder>( |
195 | 1 | S3RateLimitType::GET, config::s3_get_token_per_second, |
196 | 1 | config::s3_get_bucket_tokens, config::s3_get_token_limit, |
197 | 1 | metric_func_factory(get_rate_limit_ns, get_rate_limit_exceed_req_num)), |
198 | 1 | std::make_unique<S3RateLimiterHolder>( |
199 | 1 | S3RateLimitType::PUT, config::s3_put_token_per_second, |
200 | 1 | config::s3_put_bucket_tokens, config::s3_put_token_limit, |
201 | 1 | metric_func_factory(put_rate_limit_ns, put_rate_limit_exceed_req_num))}; |
202 | 1 | } |
203 | | |
204 | 2 | std::string S3ClientFactory::get_valid_ca_cert_path() { |
205 | 2 | auto vec_ca_file_path = doris::split(config::ca_cert_file_paths, ";"); |
206 | 2 | auto it = vec_ca_file_path.begin(); |
207 | 2 | for (; it != vec_ca_file_path.end(); ++it) { |
208 | 2 | if (std::filesystem::exists(*it)) { |
209 | 2 | return *it; |
210 | 2 | } |
211 | 2 | } |
212 | 0 | return ""; |
213 | 2 | } |
214 | | |
215 | 1 | S3ClientFactory::~S3ClientFactory() { |
216 | 1 | Aws::ShutdownAPI(_aws_options); |
217 | 1 | } |
218 | | |
219 | 2 | S3ClientFactory& S3ClientFactory::instance() { |
220 | 2 | static S3ClientFactory ret; |
221 | 2 | return ret; |
222 | 2 | } |
223 | | |
224 | 2 | std::shared_ptr<io::ObjStorageClient> S3ClientFactory::create(const S3ClientConf& s3_conf) { |
225 | 2 | if (!is_s3_conf_valid(s3_conf).ok()) { |
226 | 0 | return nullptr; |
227 | 0 | } |
228 | | |
229 | 2 | uint64_t hash = s3_conf.get_hash(); |
230 | 2 | { |
231 | 2 | std::lock_guard l(_lock); |
232 | 2 | auto it = _cache.find(hash); |
233 | 2 | if (it != _cache.end()) { |
234 | 0 | return it->second; |
235 | 0 | } |
236 | 2 | } |
237 | | |
238 | 2 | auto obj_client = (s3_conf.provider == io::ObjStorageType::AZURE) |
239 | 2 | ? _create_azure_client(s3_conf) |
240 | 2 | : _create_s3_client(s3_conf); |
241 | | |
242 | 2 | { |
243 | 2 | uint64_t hash = s3_conf.get_hash(); |
244 | 2 | std::lock_guard l(_lock); |
245 | 2 | _cache[hash] = obj_client; |
246 | 2 | } |
247 | 2 | return obj_client; |
248 | 2 | } |
249 | | |
250 | | std::shared_ptr<io::ObjStorageClient> S3ClientFactory::_create_azure_client( |
251 | 0 | const S3ClientConf& s3_conf) { |
252 | 0 | #ifdef USE_AZURE |
253 | 0 | auto cred = |
254 | 0 | std::make_shared<Azure::Storage::StorageSharedKeyCredential>(s3_conf.ak, s3_conf.sk); |
255 | |
|
256 | 0 | const std::string container_name = s3_conf.bucket; |
257 | 0 | const std::string uri = fmt::format("{}://{}.blob.core.windows.net/{}", |
258 | 0 | config::s3_client_http_scheme, s3_conf.ak, container_name); |
259 | |
|
260 | 0 | auto containerClient = std::make_shared<Azure::Storage::Blobs::BlobContainerClient>(uri, cred); |
261 | 0 | LOG_INFO("create one azure client with {}", s3_conf.to_string()); |
262 | 0 | return std::make_shared<io::AzureObjStorageClient>(std::move(containerClient)); |
263 | | #else |
264 | | LOG_FATAL("BE is not compiled with azure support, export BUILD_AZURE=ON before building"); |
265 | | return nullptr; |
266 | | #endif |
267 | 0 | } |
268 | | |
269 | | std::shared_ptr<io::ObjStorageClient> S3ClientFactory::_create_s3_client( |
270 | 2 | const S3ClientConf& s3_conf) { |
271 | 2 | TEST_SYNC_POINT_RETURN_WITH_VALUE( |
272 | 1 | "s3_client_factory::create", |
273 | 1 | std::make_shared<io::S3ObjStorageClient>(std::make_shared<Aws::S3::S3Client>())); |
274 | 1 | Aws::Client::ClientConfiguration aws_config = S3ClientFactory::getClientConfiguration(); |
275 | 1 | aws_config.endpointOverride = s3_conf.endpoint; |
276 | 1 | aws_config.region = s3_conf.region; |
277 | 1 | std::string ca_cert = get_valid_ca_cert_path(); |
278 | 1 | if ("" != _ca_cert_file_path) { |
279 | 1 | aws_config.caFile = _ca_cert_file_path; |
280 | 1 | } else { |
281 | | // config::ca_cert_file_paths is valmutable,get newest value if file path invaild |
282 | 0 | _ca_cert_file_path = get_valid_ca_cert_path(); |
283 | 0 | if ("" != _ca_cert_file_path) { |
284 | 0 | aws_config.caFile = _ca_cert_file_path; |
285 | 0 | } |
286 | 0 | } |
287 | 1 | if (s3_conf.max_connections > 0) { |
288 | 0 | aws_config.maxConnections = s3_conf.max_connections; |
289 | 1 | } else { |
290 | 1 | #ifdef BE_TEST |
291 | | // the S3Client may shared by many threads. |
292 | | // So need to set the number of connections large enough. |
293 | 1 | aws_config.maxConnections = config::doris_scanner_thread_pool_thread_num; |
294 | | #else |
295 | | aws_config.maxConnections = |
296 | | ExecEnv::GetInstance()->scanner_scheduler()->remote_thread_pool_max_thread_num(); |
297 | | #endif |
298 | 1 | } |
299 | | |
300 | 1 | if (s3_conf.request_timeout_ms > 0) { |
301 | 0 | aws_config.requestTimeoutMs = s3_conf.request_timeout_ms; |
302 | 0 | } |
303 | 1 | if (s3_conf.connect_timeout_ms > 0) { |
304 | 0 | aws_config.connectTimeoutMs = s3_conf.connect_timeout_ms; |
305 | 0 | } |
306 | | |
307 | 1 | if (config::s3_client_http_scheme == "http") { |
308 | 1 | aws_config.scheme = Aws::Http::Scheme::HTTP; |
309 | 1 | } |
310 | | |
311 | 1 | aws_config.retryStrategy = std::make_shared<S3CustomRetryStrategy>( |
312 | 1 | config::max_s3_client_retry /*scaleFactor = 25*/); |
313 | 1 | std::shared_ptr<Aws::S3::S3Client> new_client; |
314 | 1 | if (!s3_conf.ak.empty() && !s3_conf.sk.empty()) { |
315 | 1 | Aws::Auth::AWSCredentials aws_cred(s3_conf.ak, s3_conf.sk); |
316 | 1 | DCHECK(!aws_cred.IsExpiredOrEmpty()); |
317 | 1 | if (!s3_conf.token.empty()) { |
318 | 0 | aws_cred.SetSessionToken(s3_conf.token); |
319 | 0 | } |
320 | 1 | new_client = std::make_shared<Aws::S3::S3Client>( |
321 | 1 | std::move(aws_cred), std::move(aws_config), |
322 | 1 | Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, |
323 | 1 | s3_conf.use_virtual_addressing); |
324 | 1 | } else { |
325 | 0 | std::shared_ptr<Aws::Auth::AWSCredentialsProvider> aws_provider_chain = |
326 | 0 | std::make_shared<Aws::Auth::DefaultAWSCredentialsProviderChain>(); |
327 | 0 | new_client = std::make_shared<Aws::S3::S3Client>( |
328 | 0 | std::move(aws_provider_chain), std::move(aws_config), |
329 | 0 | Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, |
330 | 0 | s3_conf.use_virtual_addressing); |
331 | 0 | } |
332 | | |
333 | 1 | auto obj_client = std::make_shared<io::S3ObjStorageClient>(std::move(new_client)); |
334 | 1 | LOG_INFO("create one s3 client with {}", s3_conf.to_string()); |
335 | 1 | return obj_client; |
336 | 2 | } |
337 | | |
338 | | Status S3ClientFactory::convert_properties_to_s3_conf( |
339 | 0 | const std::map<std::string, std::string>& prop, const S3URI& s3_uri, S3Conf* s3_conf) { |
340 | 0 | StringCaseMap<std::string> properties(prop.begin(), prop.end()); |
341 | 0 | if (auto it = properties.find(S3_AK); it != properties.end()) { |
342 | 0 | s3_conf->client_conf.ak = it->second; |
343 | 0 | } |
344 | 0 | if (auto it = properties.find(S3_SK); it != properties.end()) { |
345 | 0 | s3_conf->client_conf.sk = it->second; |
346 | 0 | } |
347 | 0 | if (auto it = properties.find(S3_TOKEN); it != properties.end()) { |
348 | 0 | s3_conf->client_conf.token = it->second; |
349 | 0 | } |
350 | 0 | if (auto it = properties.find(S3_ENDPOINT); it != properties.end()) { |
351 | 0 | s3_conf->client_conf.endpoint = it->second; |
352 | 0 | } |
353 | 0 | if (auto it = properties.find(S3_REGION); it != properties.end()) { |
354 | 0 | s3_conf->client_conf.region = it->second; |
355 | 0 | } |
356 | 0 | if (auto it = properties.find(S3_MAX_CONN_SIZE); it != properties.end()) { |
357 | 0 | if (!to_int(it->second, s3_conf->client_conf.max_connections)) { |
358 | 0 | return Status::InvalidArgument("invalid {} value \"{}\"", S3_MAX_CONN_SIZE, it->second); |
359 | 0 | } |
360 | 0 | } |
361 | 0 | if (auto it = properties.find(S3_REQUEST_TIMEOUT_MS); it != properties.end()) { |
362 | 0 | if (!to_int(it->second, s3_conf->client_conf.request_timeout_ms)) { |
363 | 0 | return Status::InvalidArgument("invalid {} value \"{}\"", S3_REQUEST_TIMEOUT_MS, |
364 | 0 | it->second); |
365 | 0 | } |
366 | 0 | } |
367 | 0 | if (auto it = properties.find(S3_CONN_TIMEOUT_MS); it != properties.end()) { |
368 | 0 | if (!to_int(it->second, s3_conf->client_conf.connect_timeout_ms)) { |
369 | 0 | return Status::InvalidArgument("invalid {} value \"{}\"", S3_CONN_TIMEOUT_MS, |
370 | 0 | it->second); |
371 | 0 | } |
372 | 0 | } |
373 | 0 | if (auto it = properties.find(S3_PROVIDER); it != properties.end()) { |
374 | | // S3 Provider properties should be case insensitive. |
375 | 0 | if (0 == strcasecmp(it->second.c_str(), AZURE_PROVIDER_STRING)) { |
376 | 0 | s3_conf->client_conf.provider = io::ObjStorageType::AZURE; |
377 | 0 | } |
378 | 0 | } |
379 | |
|
380 | 0 | if (s3_uri.get_bucket().empty()) { |
381 | 0 | return Status::InvalidArgument("Invalid S3 URI {}, bucket is not specified", |
382 | 0 | s3_uri.to_string()); |
383 | 0 | } |
384 | 0 | s3_conf->bucket = s3_uri.get_bucket(); |
385 | | // For azure's compatibility |
386 | 0 | s3_conf->client_conf.bucket = s3_uri.get_bucket(); |
387 | 0 | s3_conf->prefix = ""; |
388 | | |
389 | | // See https://sdk.amazonaws.com/cpp/api/LATEST/class_aws_1_1_s3_1_1_s3_client.html |
390 | 0 | s3_conf->client_conf.use_virtual_addressing = true; |
391 | 0 | if (auto it = properties.find(USE_PATH_STYLE); it != properties.end()) { |
392 | 0 | s3_conf->client_conf.use_virtual_addressing = it->second != "true"; |
393 | 0 | } |
394 | |
|
395 | 0 | if (auto st = is_s3_conf_valid(s3_conf->client_conf); !st.ok()) { |
396 | 0 | return st; |
397 | 0 | } |
398 | 0 | return Status::OK(); |
399 | 0 | } |
400 | | |
401 | 0 | S3Conf S3Conf::get_s3_conf(const cloud::ObjectStoreInfoPB& info) { |
402 | 0 | S3Conf ret { |
403 | 0 | .bucket = info.bucket(), |
404 | 0 | .prefix = info.prefix(), |
405 | 0 | .client_conf {.endpoint = info.endpoint(), |
406 | 0 | .region = info.region(), |
407 | 0 | .ak = info.ak(), |
408 | 0 | .sk = info.sk(), |
409 | 0 | .token {}, |
410 | 0 | .bucket = info.bucket(), |
411 | 0 | .provider = io::ObjStorageType::AWS, |
412 | 0 | .use_virtual_addressing = |
413 | 0 | info.has_use_path_style() ? !info.use_path_style() : true}, |
414 | 0 | .sse_enabled = info.sse_enabled(), |
415 | 0 | }; |
416 | |
|
417 | 0 | io::ObjStorageType type = io::ObjStorageType::AWS; |
418 | 0 | switch (info.provider()) { |
419 | 0 | case cloud::ObjectStoreInfoPB_Provider_OSS: |
420 | 0 | type = io::ObjStorageType::OSS; |
421 | 0 | break; |
422 | 0 | case cloud::ObjectStoreInfoPB_Provider_S3: |
423 | 0 | type = io::ObjStorageType::AWS; |
424 | 0 | break; |
425 | 0 | case cloud::ObjectStoreInfoPB_Provider_COS: |
426 | 0 | type = io::ObjStorageType::COS; |
427 | 0 | break; |
428 | 0 | case cloud::ObjectStoreInfoPB_Provider_OBS: |
429 | 0 | type = io::ObjStorageType::OBS; |
430 | 0 | break; |
431 | 0 | case cloud::ObjectStoreInfoPB_Provider_BOS: |
432 | 0 | type = io::ObjStorageType::BOS; |
433 | 0 | break; |
434 | 0 | case cloud::ObjectStoreInfoPB_Provider_GCP: |
435 | 0 | type = io::ObjStorageType::GCP; |
436 | 0 | break; |
437 | 0 | case cloud::ObjectStoreInfoPB_Provider_AZURE: |
438 | 0 | type = io::ObjStorageType::AZURE; |
439 | 0 | break; |
440 | 0 | default: |
441 | 0 | LOG_FATAL("unknown provider type {}, info {}", info.provider(), ret.to_string()); |
442 | 0 | __builtin_unreachable(); |
443 | 0 | } |
444 | 0 | ret.client_conf.provider = type; |
445 | 0 | return ret; |
446 | 0 | } |
447 | | |
448 | 0 | S3Conf S3Conf::get_s3_conf(const TS3StorageParam& param) { |
449 | 0 | S3Conf ret { |
450 | 0 | .bucket = param.bucket, |
451 | 0 | .prefix = param.root_path, |
452 | 0 | .client_conf = { |
453 | 0 | .endpoint = param.endpoint, |
454 | 0 | .region = param.region, |
455 | 0 | .ak = param.ak, |
456 | 0 | .sk = param.sk, |
457 | 0 | .token = param.token, |
458 | 0 | .bucket = param.bucket, |
459 | 0 | .provider = io::ObjStorageType::AWS, |
460 | 0 | .max_connections = param.max_conn, |
461 | 0 | .request_timeout_ms = param.request_timeout_ms, |
462 | 0 | .connect_timeout_ms = param.conn_timeout_ms, |
463 | | // When using cold heat separation in minio, user might use ip address directly, |
464 | | // which needs enable use_virtual_addressing to true |
465 | 0 | .use_virtual_addressing = !param.use_path_style, |
466 | 0 | }}; |
467 | 0 | io::ObjStorageType type = io::ObjStorageType::AWS; |
468 | 0 | switch (param.provider) { |
469 | 0 | case TObjStorageType::UNKNOWN: |
470 | 0 | LOG_INFO("Receive one legal storage resource, set provider type to aws, param detail {}", |
471 | 0 | ret.to_string()); |
472 | 0 | type = io::ObjStorageType::AWS; |
473 | 0 | break; |
474 | 0 | case TObjStorageType::AWS: |
475 | 0 | type = io::ObjStorageType::AWS; |
476 | 0 | break; |
477 | 0 | case TObjStorageType::AZURE: |
478 | 0 | type = io::ObjStorageType::AZURE; |
479 | 0 | break; |
480 | 0 | case TObjStorageType::BOS: |
481 | 0 | type = io::ObjStorageType::BOS; |
482 | 0 | break; |
483 | 0 | case TObjStorageType::COS: |
484 | 0 | type = io::ObjStorageType::COS; |
485 | 0 | break; |
486 | 0 | case TObjStorageType::OBS: |
487 | 0 | type = io::ObjStorageType::OBS; |
488 | 0 | break; |
489 | 0 | case TObjStorageType::OSS: |
490 | 0 | type = io::ObjStorageType::OSS; |
491 | 0 | break; |
492 | 0 | case TObjStorageType::GCP: |
493 | 0 | type = io::ObjStorageType::GCP; |
494 | 0 | break; |
495 | 0 | default: |
496 | 0 | LOG_FATAL("unknown provider type {}, info {}", param.provider, ret.to_string()); |
497 | 0 | __builtin_unreachable(); |
498 | 0 | } |
499 | 0 | ret.client_conf.provider = type; |
500 | 0 | return ret; |
501 | 0 | } |
502 | | |
503 | | } // end namespace doris |