Skip to content

Commit e2cb51e

Browse files
committed
[fix](recycler) Process self-defined domain names for s3 storage vault (#45072)
1 parent 43f06a5 commit e2cb51e

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

cloud/src/recycler/s3_accessor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ std::optional<S3Conf> S3Conf::from_obj_store_info(const ObjectStoreInfoPB& obj_i
205205
s3_conf.region = obj_info.region();
206206
s3_conf.bucket = obj_info.bucket();
207207
s3_conf.prefix = obj_info.prefix();
208+
s3_conf.use_virtual_addressing = !obj_info.use_path_style();
208209

209210
return s3_conf;
210211
}
@@ -289,7 +290,7 @@ int S3Accessor::init() {
289290
auto s3_client = std::make_shared<Aws::S3::S3Client>(
290291
std::move(aws_cred), std::move(aws_config),
291292
Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never,
292-
true /* useVirtualAddressing */);
293+
conf_.use_virtual_addressing /* useVirtualAddressing */);
293294
obj_client_ = std::make_shared<S3ObjClient>(std::move(s3_client), conf_.endpoint);
294295
return 0;
295296
}

cloud/src/recycler/s3_accessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct S3Conf {
6969
std::string region;
7070
std::string bucket;
7171
std::string prefix;
72+
bool use_virtual_addressing {true};
7273

7374
enum Provider : uint8_t {
7475
S3,

cloud/src/recycler/s3_obj_client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ ObjectStorageResponse S3ObjClient::delete_object(ObjectStoragePathRef path) {
284284
SCOPED_BVAR_LATENCY(s3_bvar::s3_delete_object_latency);
285285
return s3_client_->DeleteObject(request);
286286
});
287+
TEST_SYNC_POINT_CALLBACK("S3ObjClient::delete_object", &outcome);
287288
if (!outcome.IsSuccess()) {
288289
LOG_WARNING("failed to delete object")
289290
.tag("endpoint", endpoint_)

cloud/test/s3_accessor_test.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
#include "recycler/s3_accessor.h"
1919

20+
#include <aws/s3/S3Client.h>
2021
#include <aws/s3/model/ListObjectsV2Request.h>
2122
#include <butil/guid.h>
23+
#include <gen_cpp/cloud.pb.h>
2224
#include <gtest/gtest.h>
2325

2426
#include <azure/storage/blobs/blob_options.hpp>
@@ -320,4 +322,70 @@ TEST(S3AccessorTest, gcs) {
320322
test_s3_accessor(*accessor);
321323
}
322324

325+
TEST(S3AccessorTest, path_style_test) {
326+
ObjectStoreInfoPB obj_info;
327+
obj_info.set_prefix("doris-debug-instance-prefix");
328+
obj_info.set_provider(ObjectStoreInfoPB_Provider_S3);
329+
obj_info.set_ak("dummy_ak");
330+
obj_info.set_sk("dummy_sk");
331+
obj_info.set_endpoint("dummy-bucket");
332+
obj_info.set_region("cn-north-1");
333+
obj_info.set_bucket("dummy-bucket");
334+
config::max_s3_client_retry = 0;
335+
336+
auto* sp = SyncPoint::get_instance();
337+
sp->enable_processing();
338+
std::vector<SyncPoint::CallbackGuard> guards;
339+
340+
std::string base_domain = "s3.cn-north-1.amazonaws.com.cn";
341+
std::string domain_ip = "54.222.51.71"; // first ip of base_domain
342+
// to test custom_domain, add ${domain_ip} ${custom_domain} to /etc/hosts
343+
// otherwise the related cases will fail
344+
std::string custom_domain = "gavin.s3.aws.com";
345+
// clang-format off
346+
// http code 403 means there is nothing wrong the given domain in objinfo
347+
// domain, use_path_style, http_code
348+
std::vector<std::tuple<std::string, bool, int>> inputs {
349+
{base_domain , false , 403}, // works
350+
{base_domain , true , 403}, // works
351+
{"http://" + base_domain , false , 403}, // works
352+
{"http://" + base_domain , true , 403}, // works
353+
{"https://" + base_domain , false , 403}, // works
354+
{"https://" + base_domain , true , 403}, // works
355+
{"http://" + domain_ip , false , 301}, // works, ip with virtual addressing
356+
{"http://" + domain_ip , true , 301}, // works, ip with path style
357+
{custom_domain , false , -1} , // custom_domain could not resolve with virtual addressing
358+
{custom_domain , true , 403}, // custom_domain working with path style
359+
{"http://" + custom_domain , false , -1} , // custom_domain could not resolve with virtual addressing
360+
{"https://" + custom_domain, true , -1}, // certificate issue, custom_domain does not attached with any certs
361+
// {"https://54.222.51.71" , false , -1} , // certificate issue
362+
// {"https://54.222.51.71" , true , -1} , // certificate issue
363+
};
364+
365+
int case_idx = 0;
366+
sp->set_call_back("S3ObjClient::delete_object",
367+
[&case_idx, &inputs](auto&& args) {
368+
auto* res = try_any_cast<Aws::S3::Model::DeleteObjectOutcome*>(args[0]);
369+
EXPECT_EQ(std::get<2>(inputs[case_idx]), static_cast<int>(res->GetError().GetResponseCode())) << "<<<<<<<<<<<<<<<<<<<<< " << case_idx;
370+
case_idx++;
371+
},
372+
&guards.emplace_back());
373+
// clang-format on
374+
375+
for (auto& i : inputs) {
376+
obj_info.set_endpoint(std::get<0>(i));
377+
obj_info.set_use_path_style(std::get<1>(i));
378+
auto s3_conf = S3Conf::from_obj_store_info(obj_info);
379+
EXPECT_EQ(s3_conf->use_virtual_addressing, !obj_info.use_path_style()) << case_idx;
380+
std::shared_ptr<S3Accessor> accessor;
381+
int ret = S3Accessor::create(*s3_conf, &accessor);
382+
EXPECT_EQ(ret, 0) << "<<<<<<<<<<<<<<<<<<<<< " << case_idx;
383+
ret = accessor->init();
384+
EXPECT_EQ(ret, 0) << "<<<<<<<<<<<<<<<<<<<<< " << case_idx;
385+
// this function call will trigger syncpoint callback to increment case_idx
386+
accessor->delete_file("abc"); // try to delete a nonexisted file, ignore the result
387+
// EXPECT_EQ(ret, exp) << "<<<<<<<<<<<<<<<<<<<<< " << case_idx << " domain " << std::get<0>(i);
388+
}
389+
}
390+
323391
} // namespace doris::cloud

0 commit comments

Comments
 (0)