Coverage Report

Created: 2026-10-12 19:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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 <functional>
71
#include <memory>
72
#include <ranges>
73
74
#include "client_bvar.h"
75
#include "cpp/obj_retry_strategy.h"
76
#include "cpp/sync_point.h"
77
#include "obj_storage_client.h"
78
#include "s3_common.h"
79
80
namespace Aws::S3 {
81
class S3Client;
82
namespace Model {
83
class CompletedPart;
84
}
85
} // namespace Aws::S3
86
87
namespace doris {
88
89
ObjStorageStatus s3fs_error(const Aws::S3::S3Error& err, std::string_view msg);
90
91
class S3ObjStorageClient final : public ObjStorageClient {
92
public:
93
    using SignedUrlGenerator = std::function<std::string(const ObjStoragePath&, int64_t)>;
94
95
    S3ObjStorageClient(std::shared_ptr<Aws::S3::S3Client> client,
96
                       ObjStorageEndpointInfo config = {},
97
                       SignedUrlGenerator signed_url_generator = {})
98
            : _config(std::move(config)),
99
              _client(std::move(client)),
100
0
              _signed_url_generator(std::move(signed_url_generator)) {}
101
0
    ~S3ObjStorageClient() override = default;
102
    ObjStorageUploadResult create_multipart_upload(const ObjStoragePath& opts) override;
103
    ObjStorageResponse put_object(const ObjStoragePath& opts, std::string_view stream) override;
104
    ObjStorageUploadResult upload_part(const ObjStoragePath& opts, const std::string& upload_id,
105
                                       std::string_view, int partNum) override;
106
    ObjStorageResponse complete_multipart_upload(
107
            const ObjStoragePath& opts, const std::string& upload_id,
108
            const std::vector<ObjStorageCompletedPart>& completed_parts) override;
109
    ObjStorageHeadResult head_object(const ObjStoragePath& opts) override;
110
    ObjStorageResponse get_object(const ObjStoragePath& opts, void* buffer, size_t offset,
111
                                  size_t bytes_read, size_t* size_return) override;
112
    ObjStorageResponse delete_objects(const ObjStoragePath& opts,
113
                                      std::vector<std::string> objs) override;
114
    ObjStorageResponse delete_object(const ObjStoragePath& opts) override;
115
    std::string generate_presigned_url(const ObjStoragePath& opts,
116
                                       int64_t expiration_secs) override;
117
    ObjStorageResponse get_lifecycle(const std::string& bucket, int64_t* expiration_days) override;
118
119
    ObjStorageResponse check_versioning(const std::string& bucket) override;
120
121
    ObjStorageResponse abort_multipart_upload(const ObjStoragePath& opts,
122
                                              const std::string& upload_id) override;
123
4
    ObjStorageCapabilities capabilities() const override {
124
4
        return {.max_delete_batch = 1000, .max_list_page = 1000};
125
4
    }
126
127
protected:
128
    ObjStorageListPageResult list_objects_page(const ObjStoragePath& opts,
129
                                               std::string_view continuation_token) override;
130
131
private:
132
    ObjStorageEndpointInfo _config;
133
    std::shared_ptr<Aws::S3::S3Client> _client;
134
    SignedUrlGenerator _signed_url_generator;
135
};
136
137
} // namespace doris
138
139
namespace doris::io {
140
using ::doris::S3ObjStorageClient;
141
} // namespace doris::io