common/cpp/obj-client/s3_obj_storage_client.h
Line | Count | Source |
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 | | #pragma once |
19 | | |
20 | | #include <aws/core/client/AWSError.h> |
21 | | #include <aws/core/http/HttpResponse.h> |
22 | | #include <aws/core/http/URI.h> |
23 | | #include <aws/core/utils/Array.h> |
24 | | #include <aws/core/utils/HashingUtils.h> |
25 | | #include <aws/core/utils/Outcome.h> |
26 | | #include <aws/core/utils/memory/stl/AWSAllocator.h> |
27 | | #include <aws/core/utils/memory/stl/AWSMap.h> |
28 | | #include <aws/core/utils/memory/stl/AWSStreamFwd.h> |
29 | | #include <aws/core/utils/memory/stl/AWSString.h> |
30 | | #include <aws/core/utils/memory/stl/AWSStringStream.h> |
31 | | #include <aws/core/utils/memory/stl/AWSVector.h> |
32 | | #include <aws/core/utils/threading/Executor.h> |
33 | | #include <aws/s3/S3Client.h> |
34 | | #include <aws/s3/S3Errors.h> |
35 | | #include <aws/s3/model/AbortMultipartUploadRequest.h> |
36 | | #include <aws/s3/model/AbortMultipartUploadResult.h> |
37 | | #include <aws/s3/model/CompleteMultipartUploadRequest.h> |
38 | | #include <aws/s3/model/CompleteMultipartUploadResult.h> |
39 | | #include <aws/s3/model/CompletedMultipartUpload.h> |
40 | | #include <aws/s3/model/CompletedPart.h> |
41 | | #include <aws/s3/model/CopyObjectRequest.h> |
42 | | #include <aws/s3/model/CopyObjectResult.h> |
43 | | #include <aws/s3/model/CreateMultipartUploadRequest.h> |
44 | | #include <aws/s3/model/CreateMultipartUploadResult.h> |
45 | | #include <aws/s3/model/Delete.h> |
46 | | #include <aws/s3/model/DeleteObjectRequest.h> |
47 | | #include <aws/s3/model/DeleteObjectResult.h> |
48 | | #include <aws/s3/model/DeleteObjectsRequest.h> |
49 | | #include <aws/s3/model/DeleteObjectsResult.h> |
50 | | #include <aws/s3/model/Error.h> |
51 | | #include <aws/s3/model/GetBucketLifecycleConfigurationRequest.h> |
52 | | #include <aws/s3/model/GetBucketLifecycleConfigurationResult.h> |
53 | | #include <aws/s3/model/GetBucketVersioningRequest.h> |
54 | | #include <aws/s3/model/GetObjectRequest.h> |
55 | | #include <aws/s3/model/GetObjectResult.h> |
56 | | #include <aws/s3/model/HeadObjectRequest.h> |
57 | | #include <aws/s3/model/HeadObjectResult.h> |
58 | | #include <aws/s3/model/ListObjectsV2Request.h> |
59 | | #include <aws/s3/model/ListObjectsV2Result.h> |
60 | | #include <aws/s3/model/Object.h> |
61 | | #include <aws/s3/model/ObjectIdentifier.h> |
62 | | #include <aws/s3/model/PutObjectRequest.h> |
63 | | #include <aws/s3/model/PutObjectResult.h> |
64 | | #include <aws/s3/model/UploadPartRequest.h> |
65 | | #include <aws/s3/model/UploadPartResult.h> |
66 | | #include <fmt/core.h> |
67 | | #include <gen_cpp/Status_types.h> |
68 | | #include <glog/logging.h> |
69 | | |
70 | | #include <memory> |
71 | | #include <ranges> |
72 | | |
73 | | #include "client_bvar.h" |
74 | | #include "cpp/obj_retry_strategy.h" |
75 | | #include "cpp/sync_point.h" |
76 | | #include "obj_storage_client.h" |
77 | | #include "s3_common.h" |
78 | | |
79 | | namespace Aws::S3 { |
80 | | class S3Client; |
81 | | namespace Model { |
82 | | class CompletedPart; |
83 | | } |
84 | | } // namespace Aws::S3 |
85 | | |
86 | | namespace doris { |
87 | | |
88 | | ObjStorageStatus s3fs_error(const Aws::S3::S3Error& err, std::string_view msg); |
89 | | |
90 | | class S3ObjStorageClient final : public ObjStorageClient { |
91 | | public: |
92 | | S3ObjStorageClient(std::shared_ptr<Aws::S3::S3Client> client, |
93 | | ObjStorageEndpointInfo config = {}) |
94 | 0 | : _config(std::move(config)), _client(std::move(client)) {} |
95 | 0 | ~S3ObjStorageClient() override = default; |
96 | | ObjStorageUploadResult create_multipart_upload(const ObjStoragePath& opts) override; |
97 | | ObjStorageResponse put_object(const ObjStoragePath& opts, std::string_view stream) override; |
98 | | ObjStorageUploadResult upload_part(const ObjStoragePath& opts, const std::string& upload_id, |
99 | | std::string_view, int partNum) override; |
100 | | ObjStorageResponse complete_multipart_upload( |
101 | | const ObjStoragePath& opts, const std::string& upload_id, |
102 | | const std::vector<ObjStorageCompletedPart>& completed_parts) override; |
103 | | ObjStorageHeadResult head_object(const ObjStoragePath& opts) override; |
104 | | ObjStorageResponse get_object(const ObjStoragePath& opts, void* buffer, size_t offset, |
105 | | size_t bytes_read, size_t* size_return) override; |
106 | | ObjStorageResponse delete_objects(const ObjStoragePath& opts, |
107 | | std::vector<std::string> objs) override; |
108 | | ObjStorageResponse delete_object(const ObjStoragePath& opts) override; |
109 | | std::string generate_presigned_url(const ObjStoragePath& opts, |
110 | | int64_t expiration_secs) override; |
111 | | ObjStorageResponse get_lifecycle(const std::string& bucket, int64_t* expiration_days) override; |
112 | | |
113 | | ObjStorageResponse check_versioning(const std::string& bucket) override; |
114 | | |
115 | | ObjStorageResponse abort_multipart_upload(const ObjStoragePath& opts, |
116 | | const std::string& upload_id) override; |
117 | 4 | ObjStorageCapabilities capabilities() const override { |
118 | 4 | return {.max_delete_batch = 1000, .max_list_page = 1000}; |
119 | 4 | } |
120 | | |
121 | | protected: |
122 | | ObjStorageListPageResult list_objects_page(const ObjStoragePath& opts, |
123 | | std::string_view continuation_token) override; |
124 | | |
125 | | private: |
126 | | ObjStorageEndpointInfo _config; |
127 | | std::shared_ptr<Aws::S3::S3Client> _client; |
128 | | }; |
129 | | |
130 | | } // namespace doris |
131 | | |
132 | | namespace doris::io { |
133 | | using ::doris::S3ObjStorageClient; |
134 | | } // namespace doris::io |