From 97599addd903e0de0f5548ed23334ebc48af10ac Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Thu, 6 Apr 2023 16:36:10 +0800 Subject: [PATCH] Make poco client can detect stream end correctly Signed-off-by: JaySon-Huang --- .gitmodules | 2 +- contrib/aws | 2 +- dbms/src/Server/StorageConfigParser.h | 2 +- .../Storages/DeltaMerge/File/DMFileWriter.cpp | 1 + .../DeltaMerge/tests/gtest_dm_file.cpp | 1 + .../Universal/tests/gtest_lock_local_mgr.cpp | 10 +--- dbms/src/Storages/S3/MockS3Client.cpp | 28 ++--------- dbms/src/Storages/S3/PocoHTTPClient.cpp | 6 +-- dbms/src/Storages/S3/PocoHTTPClient.h | 10 ++-- .../src/Storages/S3/PocoHTTPClientFactory.cpp | 2 +- dbms/src/Storages/S3/PocoHTTPClientFactory.h | 2 +- dbms/src/Storages/S3/S3Common.cpp | 50 ++++++++++++++++++- dbms/src/Storages/S3/S3Common.h | 4 ++ dbms/src/Storages/S3/S3RandomAccessFile.cpp | 2 +- dbms/src/Storages/S3/S3RandomAccessFile.h | 2 +- dbms/src/Storages/S3/tests/gtest_s3file.cpp | 11 ++-- .../Storages/S3/tests/gtest_s3gcmanager.cpp | 5 +- dbms/src/Storages/Transaction/TMTContext.cpp | 7 ++- dbms/src/TestUtils/TiFlashTestEnv.cpp | 27 +++++++++- dbms/src/TestUtils/TiFlashTestEnv.h | 8 +-- dbms/src/TestUtils/gtests_dbms_main.cpp | 2 + 21 files changed, 122 insertions(+), 62 deletions(-) diff --git a/.gitmodules b/.gitmodules index f56cf86f8c7..2448ad80ec1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -94,7 +94,7 @@ url = https://github.com/guanzhi/GmSSL.git [submodule "contrib/aws"] path = contrib/aws - url = https://github.com/aws/aws-sdk-cpp.git + url = https://github.com/JaySon-Huang/aws-sdk-cpp.git [submodule "contrib/aws-c-auth"] path = contrib/aws-c-auth url = https://github.com/awslabs/aws-c-auth.git diff --git a/contrib/aws b/contrib/aws index 6b93c6e58fb..75b66422246 160000 --- a/contrib/aws +++ b/contrib/aws @@ -1 +1 @@ -Subproject commit 6b93c6e58fbae0014e31527666ae4e00ddab554c +Subproject commit 75b664222467f1225f79a827b26bbc23a9420fd5 diff --git a/dbms/src/Server/StorageConfigParser.h b/dbms/src/Server/StorageConfigParser.h index cd754638930..727f11b0d63 100644 --- a/dbms/src/Server/StorageConfigParser.h +++ b/dbms/src/Server/StorageConfigParser.h @@ -106,7 +106,7 @@ struct StorageS3Config String secret_access_key; UInt64 max_connections = 4096; UInt64 connection_timeout_ms = 1000; - UInt64 request_timeout_ms = 7000; + UInt64 request_timeout_ms = 30000; UInt64 max_redirections = 10; String root; diff --git a/dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp b/dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp index 44f49b2f671..12c51e24b29 100644 --- a/dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp +++ b/dbms/src/Storages/DeltaMerge/File/DMFileWriter.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #ifndef NDEBUG #include diff --git a/dbms/src/Storages/DeltaMerge/tests/gtest_dm_file.cpp b/dbms/src/Storages/DeltaMerge/tests/gtest_dm_file.cpp index fb35a4b2ab9..37c2eed8c08 100644 --- a/dbms/src/Storages/DeltaMerge/tests/gtest_dm_file.cpp +++ b/dbms/src/Storages/DeltaMerge/tests/gtest_dm_file.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/dbms/src/Storages/Page/V3/Universal/tests/gtest_lock_local_mgr.cpp b/dbms/src/Storages/Page/V3/Universal/tests/gtest_lock_local_mgr.cpp index ae02f4ec161..f9a932341b9 100644 --- a/dbms/src/Storages/Page/V3/Universal/tests/gtest_lock_local_mgr.cpp +++ b/dbms/src/Storages/Page/V3/Universal/tests/gtest_lock_local_mgr.cpp @@ -21,9 +21,7 @@ #include #include #include -#include -#include -#include +#include #include #include @@ -44,13 +42,9 @@ class S3LockLocalManagerTest : public testing::Test {} void SetUp() override - { - ::DB::tests::TiFlashTestEnv::createBucketIfNotExist(*s3_client); - } - - void TearDown() override { ::DB::tests::TiFlashTestEnv::deleteBucket(*s3_client); + ::DB::tests::TiFlashTestEnv::createBucketIfNotExist(*s3_client); } protected: diff --git a/dbms/src/Storages/S3/MockS3Client.cpp b/dbms/src/Storages/S3/MockS3Client.cpp index eb3cf79dd60..d187321b08d 100644 --- a/dbms/src/Storages/S3/MockS3Client.cpp +++ b/dbms/src/Storages/S3/MockS3Client.cpp @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include #include #include @@ -53,10 +52,6 @@ #include #include -namespace DB::FailPoints -{ -extern const char force_set_mocked_s3_object_mtime[]; -} // namespace DB::FailPoints namespace DB::S3::tests { using namespace Aws::S3; @@ -91,7 +86,10 @@ Model::GetObjectOutcome MockS3Client::GetObject(const Model::GetObjectRequest & boost::algorithm::split(v, request.GetRange().substr(prefix.size()), boost::algorithm::is_any_of("-")); RUNTIME_CHECK(v.size() == 2, request.GetRange()); left = std::stoul(v[0]); - right = std::stoul(v[1]); + if (!v[1].empty()) + { + right = std::stoul(v[1]); + } } auto size = right - left + 1; Model::GetObjectResult result; @@ -253,24 +251,6 @@ Model::HeadObjectOutcome MockS3Client::HeadObject(const Model::HeadObjectRequest if (itr_obj != bucket_storage.end()) { auto r = Model::HeadObjectResult{}; - auto try_set_mtime = [&] { - if (auto v = FailPointHelper::getFailPointVal(FailPoints::force_set_mocked_s3_object_mtime); v) - { - auto m = std::any_cast>(v.value()); - const auto req_key = normalizedKey(request.GetKey()); - if (auto iter_m = m.find(req_key); iter_m != m.end()) - { - r.SetLastModified(iter_m->second); - LOG_WARNING(Logger::get(), "failpoint set mtime, key={} mtime={}", req_key, iter_m->second.ToGmtString(Aws::Utils::DateFormat::ISO_8601)); - } - else - { - LOG_WARNING(Logger::get(), "failpoint set mtime failed, key={}", req_key); - } - } - }; - UNUSED(try_set_mtime); - fiu_do_on(FailPoints::force_set_mocked_s3_object_mtime, { try_set_mtime(); }); r.SetContentLength(itr_obj->second.size()); return r; } diff --git a/dbms/src/Storages/S3/PocoHTTPClient.cpp b/dbms/src/Storages/S3/PocoHTTPClient.cpp index 58ce88e7236..ecfa3c60be0 100644 --- a/dbms/src/Storages/S3/PocoHTTPClient.cpp +++ b/dbms/src/Storages/S3/PocoHTTPClient.cpp @@ -77,8 +77,8 @@ namespace DB::S3 { PocoHTTPClientConfiguration::PocoHTTPClientConfiguration( - const RemoteHostFilter & remote_host_filter_, - unsigned int s3_max_redirects_, + const std::shared_ptr & remote_host_filter_, + UInt32 s3_max_redirects_, bool enable_s3_requests_logging_) : remote_host_filter(remote_host_filter_) , s3_max_redirects(s3_max_redirects_) @@ -317,7 +317,7 @@ void PocoHTTPClient::makeRequestInternal( if (poco_response.getStatus() == Poco::Net::HTTPResponse::HTTP_TEMPORARY_REDIRECT) { auto location = poco_response.get("location"); - remote_host_filter.checkURL(Poco::URI(location)); + remote_host_filter->checkURL(Poco::URI(location)); uri = location; if (enable_s3_requests_logging) LOG_DEBUG(log, "Redirecting request to new location: {}", location); diff --git a/dbms/src/Storages/S3/PocoHTTPClient.h b/dbms/src/Storages/S3/PocoHTTPClient.h index 78dee700668..eec1ae6cc8f 100644 --- a/dbms/src/Storages/S3/PocoHTTPClient.h +++ b/dbms/src/Storages/S3/PocoHTTPClient.h @@ -55,16 +55,16 @@ struct PocoHTTPClientConfiguration std::function per_request_configuration = [](const Aws::Http::HttpRequest &) { return ClientConfigurationPerRequest(); }; - const RemoteHostFilter & remote_host_filter; - unsigned int s3_max_redirects; + std::shared_ptr remote_host_filter; + UInt32 s3_max_redirects; bool enable_s3_requests_logging; HTTPHeaderEntries extra_headers; std::function error_report; PocoHTTPClientConfiguration( - const RemoteHostFilter & remote_host_filter_, - unsigned int s3_max_redirects_, + const std::shared_ptr & remote_host_filter_, + UInt32 s3_max_redirects_, bool enable_s3_requests_logging_); /// Constructor of Aws::Client::ClientConfiguration must be called after AWS SDK initialization. @@ -154,7 +154,7 @@ class PocoHTTPClient : public Aws::Http::HttpClient std::function per_request_configuration; std::function error_report; ConnectionTimeouts timeouts; - const RemoteHostFilter & remote_host_filter; + const std::shared_ptr remote_host_filter; const HTTPHeaderEntries extra_headers; UInt32 s3_max_redirects; bool enable_s3_requests_logging; diff --git a/dbms/src/Storages/S3/PocoHTTPClientFactory.cpp b/dbms/src/Storages/S3/PocoHTTPClientFactory.cpp index 2a2139828cf..8af2207cc3c 100644 --- a/dbms/src/Storages/S3/PocoHTTPClientFactory.cpp +++ b/dbms/src/Storages/S3/PocoHTTPClientFactory.cpp @@ -23,7 +23,7 @@ namespace DB::S3 { -PocoHTTPClientFactory::PocoHTTPClientFactory(PocoHTTPClientConfiguration & http_cfg) +PocoHTTPClientFactory::PocoHTTPClientFactory(const PocoHTTPClientConfiguration & http_cfg) : poco_cfg(http_cfg) { } diff --git a/dbms/src/Storages/S3/PocoHTTPClientFactory.h b/dbms/src/Storages/S3/PocoHTTPClientFactory.h index c23ffd77c86..a479b14e53b 100644 --- a/dbms/src/Storages/S3/PocoHTTPClientFactory.h +++ b/dbms/src/Storages/S3/PocoHTTPClientFactory.h @@ -28,7 +28,7 @@ namespace DB::S3 class PocoHTTPClientFactory : public Aws::Http::HttpClientFactory { public: - explicit PocoHTTPClientFactory(PocoHTTPClientConfiguration & http_cfg); + explicit PocoHTTPClientFactory(const PocoHTTPClientConfiguration & http_cfg); ~PocoHTTPClientFactory() override = default; [[nodiscard]] std::shared_ptr diff --git a/dbms/src/Storages/S3/S3Common.cpp b/dbms/src/Storages/S3/S3Common.cpp index 2805163b957..c2a1d2a3901 100644 --- a/dbms/src/Storages/S3/S3Common.cpp +++ b/dbms/src/Storages/S3/S3Common.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include #include @@ -64,6 +65,7 @@ #include #include +#include #include #include #include @@ -153,6 +155,10 @@ namespace pingcap::kv PINGCAP_DEFINE_TRAITS(disaggregated, GetDisaggConfig, GetDisaggConfig); } +namespace DB::FailPoints +{ +extern const char force_set_mocked_s3_object_mtime[]; +} // namespace DB::FailPoints namespace DB::S3 { @@ -276,7 +282,10 @@ void ClientFactory::init(const StorageS3Config & config_, bool mock_s3_) // Override the HTTP client, use PocoHTTPClient instead aws_options.httpOptions.httpClientFactory_create_fn = [&config_] { // TODO: do we need the remote host filter? - PocoHTTPClientConfiguration poco_cfg(RemoteHostFilter(), config_.max_redirections, /*enable_s3_requests_logging_*/ config_.verbose); + PocoHTTPClientConfiguration poco_cfg( + std::make_shared(), + config_.max_redirections, + /*enable_s3_requests_logging_*/ config_.verbose); return std::make_shared(poco_cfg); }; Aws::InitAPI(aws_options); @@ -896,7 +905,30 @@ ObjectInfo tryGetObjectInfo( throw fromS3Error(o.GetError(), "S3 HeadObject failed, bucket={} root={} key={}", client.bucket(), client.root(), key); } // Else the object still exist +#ifndef FIU_ENABLE const auto & res = o.GetResult(); +#else + // handle the failpoint for hijacking the last modified time of returned object + auto & res = o.GetResult(); + auto try_set_mtime = [&] { + if (auto v = FailPointHelper::getFailPointVal(FailPoints::force_set_mocked_s3_object_mtime); v) + { + auto m = std::any_cast>(v.value()); + const auto & req_key = key; + if (auto iter_m = m.find(req_key); iter_m != m.end()) + { + res.SetLastModified(iter_m->second); + LOG_WARNING(Logger::get(), "failpoint set mtime, key={} mtime={}", req_key, iter_m->second.ToGmtString(Aws::Utils::DateFormat::ISO_8601)); + } + else + { + LOG_WARNING(Logger::get(), "failpoint set mtime failed, key={}", req_key); + } + } + }; + UNUSED(try_set_mtime); + fiu_do_on(FailPoints::force_set_mocked_s3_object_mtime, { try_set_mtime(); }); +#endif // "DeleteMark" of S3 service, don't know what will lead to this RUNTIME_CHECK(!res.GetDeleteMarker(), client.bucket(), key); return ObjectInfo{.exist = true, .size = res.GetContentLength(), .last_modification_time = res.GetLastModified()}; @@ -964,4 +996,20 @@ void rawListPrefix( LOG_DEBUG(log, "rawListPrefix bucket={} prefix={} delimiter={} total_keys={} cost={:.2f}s", bucket, prefix, delimiter, num_keys, sw.elapsedSeconds()); } +void rawDeleteObject(const Aws::S3::S3Client & client, const String & bucket, const String & key) +{ + Stopwatch sw; + Aws::S3::Model::DeleteObjectRequest req; + req.WithBucket(bucket).WithKey(key); + ProfileEvents::increment(ProfileEvents::S3DeleteObject); + auto o = client.DeleteObject(req); + if (!o.IsSuccess()) + { + throw fromS3Error(o.GetError(), "S3 DeleteObject failed, bucket={} key={}", bucket, key); + } + const auto & res = o.GetResult(); + UNUSED(res); + GET_METRIC(tiflash_storage_s3_request_seconds, type_delete_object).Observe(sw.elapsedSeconds()); +} + } // namespace DB::S3 diff --git a/dbms/src/Storages/S3/S3Common.h b/dbms/src/Storages/S3/S3Common.h index f182de188ca..00cc6b7b6ff 100644 --- a/dbms/src/Storages/S3/S3Common.h +++ b/dbms/src/Storages/S3/S3Common.h @@ -210,6 +210,10 @@ void rawListPrefix( std::string_view delimiter, std::function pager); +// Unlike `deleteObject` or other method above, this does not handle +// the TiFlashS3Client `root`. +void rawDeleteObject(const Aws::S3::S3Client & client, const String & bucket, const String & key); + template void retryWrapper(F f, const T &... args) { diff --git a/dbms/src/Storages/S3/S3RandomAccessFile.cpp b/dbms/src/Storages/S3/S3RandomAccessFile.cpp index 606258aa506..a4cef81dbfd 100644 --- a/dbms/src/Storages/S3/S3RandomAccessFile.cpp +++ b/dbms/src/Storages/S3/S3RandomAccessFile.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 PingCAP, Ltd. +// Copyright 2023 PingCAP, Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/dbms/src/Storages/S3/S3RandomAccessFile.h b/dbms/src/Storages/S3/S3RandomAccessFile.h index 466d5ab9601..bbd49e6acfd 100644 --- a/dbms/src/Storages/S3/S3RandomAccessFile.h +++ b/dbms/src/Storages/S3/S3RandomAccessFile.h @@ -1,4 +1,4 @@ -// Copyright 2022 PingCAP, Ltd. +// Copyright 2023 PingCAP, Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/dbms/src/Storages/S3/tests/gtest_s3file.cpp b/dbms/src/Storages/S3/tests/gtest_s3file.cpp index ffcb063346c..3f65bdd5815 100644 --- a/dbms/src/Storages/S3/tests/gtest_s3file.cpp +++ b/dbms/src/Storages/S3/tests/gtest_s3file.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -515,10 +516,10 @@ try FailPointHelper::enableFailPoint( FailPoints::force_set_mocked_s3_object_mtime, std::map{ - {s3_client->root() + df_keys[0], test_infos[0].mtime}, - {s3_client->root() + df_keys[1], test_infos[1].mtime}, - {s3_client->root() + df_keys[2], test_infos[2].mtime}, - {s3_client->root() + df_keys[3], test_infos[3].mtime}, + {df_keys[0], test_infos[0].mtime}, + {df_keys[1], test_infos[1].mtime}, + {df_keys[2], test_infos[2].mtime}, + {df_keys[3], test_infos[3].mtime}, }); SCOPE_EXIT({ FailPointHelper::disableFailPoint(FailPoints::force_set_mocked_s3_object_mtime); @@ -529,7 +530,7 @@ try for (size_t idx = 0; idx < test_infos.size(); ++idx) { ASSERT_EQ(remote_files_info.at(lock_keys[idx]).size, test_infos[idx].total_size); - ASSERT_EQ(remote_files_info.at(lock_keys[idx]).mtime, test_infos[idx].mtime); + ASSERT_EQ(remote_files_info.at(lock_keys[idx]).mtime, test_infos[idx].mtime) << fmt::format("remote_mtime:{:%Y-%m-%d %H:%M:%S} test_mtime:{:%Y-%m-%d %H:%M:%S}", remote_files_info.at(lock_keys[idx]).mtime, test_infos[idx].mtime); } ASSERT_EQ(remote_files_info.at(lock_keys[4]).size, -1); // not exist or exception happens diff --git a/dbms/src/Storages/S3/tests/gtest_s3gcmanager.cpp b/dbms/src/Storages/S3/tests/gtest_s3gcmanager.cpp index a92a18badcc..b2fabc3676b 100644 --- a/dbms/src/Storages/S3/tests/gtest_s3gcmanager.cpp +++ b/dbms/src/Storages/S3/tests/gtest_s3gcmanager.cpp @@ -355,11 +355,10 @@ try S3::uploadEmptyFile(*mock_s3_client, df.toFullKey()); S3::uploadEmptyFile(*mock_s3_client, delmark_key); auto delmark_mtime = timepoint - std::chrono::milliseconds(3599 * 1000); - FailPointHelper::enableFailPoint(FailPoints::force_set_mocked_s3_object_mtime, std::map{{mock_s3_client->root() + delmark_key, delmark_mtime}}); + FailPointHelper::enableFailPoint(FailPoints::force_set_mocked_s3_object_mtime, std::map{{delmark_key, delmark_mtime}}); SCOPE_EXIT({ FailPointHelper::disableFailPoint(FailPoints::force_set_mocked_s3_object_mtime); }); - // mock_s3_client->head_result_mtime = delmark_mtime; gc_mgr->cleanOneLock(lock_key, lock_view, timepoint); // lock is deleted, datafile and delmark remain @@ -373,7 +372,7 @@ try S3::uploadEmptyFile(*mock_s3_client, df.toFullKey()); S3::uploadEmptyFile(*mock_s3_client, delmark_key); auto delmark_mtime = timepoint - std::chrono::milliseconds(3601 * 1000); - FailPointHelper::enableFailPoint(FailPoints::force_set_mocked_s3_object_mtime, std::map{{mock_s3_client->root() + delmark_key, delmark_mtime}}); + FailPointHelper::enableFailPoint(FailPoints::force_set_mocked_s3_object_mtime, std::map{{delmark_key, delmark_mtime}}); SCOPE_EXIT({ FailPointHelper::disableFailPoint(FailPoints::force_set_mocked_s3_object_mtime); }); diff --git a/dbms/src/Storages/Transaction/TMTContext.cpp b/dbms/src/Storages/Transaction/TMTContext.cpp index 66c1e5ba5ad..9d1dac6c328 100644 --- a/dbms/src/Storages/Transaction/TMTContext.cpp +++ b/dbms/src/Storages/Transaction/TMTContext.cpp @@ -132,8 +132,11 @@ void TMTContext::updateSecurityConfig(const TiFlashRaftConfig & raft_config, con { // update the client config including pd_client cluster->update(raft_config.pd_addrs, cluster_config); - // update the etcd_client after pd_client get updated - etcd_client->update(cluster_config); + if (etcd_client) + { + // update the etcd_client after pd_client get updated + etcd_client->update(cluster_config); + } } } diff --git a/dbms/src/TestUtils/TiFlashTestEnv.cpp b/dbms/src/TestUtils/TiFlashTestEnv.cpp index fa788a8f580..5a031f001d1 100644 --- a/dbms/src/TestUtils/TiFlashTestEnv.cpp +++ b/dbms/src/TestUtils/TiFlashTestEnv.cpp @@ -30,12 +30,14 @@ #include #include #include +#include #include namespace DB::tests { std::vector TiFlashTestEnv::global_contexts = {}; +bool TiFlashTestEnv::is_mocked_s3_client = true; String TiFlashTestEnv::getTemporaryPath(const std::string_view test_case, bool get_abs) { @@ -262,9 +264,32 @@ bool TiFlashTestEnv::createBucketIfNotExist(::DB::S3::TiFlashS3Client & s3_clien void TiFlashTestEnv::deleteBucket(::DB::S3::TiFlashS3Client & s3_client) { + TiFlashTestEnv::createBucketIfNotExist(s3_client); + if (!is_mocked_s3_client) + { + // All objects (including all object versions and delete markers) + // in the bucket must be deleted before the bucket itself can be + // deleted. + LOG_INFO(s3_client.log, "DeleteBucket, clean all existing objects begin"); + S3::rawListPrefix(s3_client, s3_client.bucket(), s3_client.root(), "", [&](const Aws::S3::Model::ListObjectsV2Result & r) -> S3::PageResult { + for (const auto & obj : r.GetContents()) + { + const auto & key = obj.GetKey(); + LOG_INFO(s3_client.log, "DeleteBucket, clean existing object, key={}", key); + S3::rawDeleteObject(s3_client, s3_client.bucket(), key); + } + return S3::PageResult{.num_keys = r.GetContents().size(), .more = true}; + }); + LOG_INFO(s3_client.log, "DeleteBucket, clean all existing objects done"); + } Aws::S3::Model::DeleteBucketRequest request; request.SetBucket(s3_client.bucket()); - s3_client.DeleteBucket(request); + auto outcome = s3_client.DeleteBucket(request); + if (!outcome.IsSuccess()) + { + const auto & err = outcome.GetError(); + LOG_WARNING(s3_client.log, "DeleteBucket: {}:{}", err.GetExceptionName(), err.GetMessage()); + } } } // namespace DB::tests diff --git a/dbms/src/TestUtils/TiFlashTestEnv.h b/dbms/src/TestUtils/TiFlashTestEnv.h index 2cc5a94701a..0a68c1b3a4c 100644 --- a/dbms/src/TestUtils/TiFlashTestEnv.h +++ b/dbms/src/TestUtils/TiFlashTestEnv.h @@ -76,7 +76,7 @@ class TiFlashTestEnv const static std::vector SEARCH_PATH = {"../tests/testdata/", "/tests/testdata/"}; for (const auto & prefix : SEARCH_PATH) { - String path = prefix + name; + String path = Poco::Path{prefix + name}.absolute().toString(); if (auto f = Poco::File(path); f.exists() && f.isDirectory()) { Strings paths; @@ -105,13 +105,15 @@ class TiFlashTestEnv static FileProviderPtr getMockFileProvider(); + static void setIsMockedS3Client(bool mock) { is_mocked_s3_client = mock; } + static bool isMockedS3Client() { return is_mocked_s3_client; } static bool createBucketIfNotExist(::DB::S3::TiFlashS3Client & s3_client); - static void deleteBucket(::DB::S3::TiFlashS3Client & s3_client); - TiFlashTestEnv() = delete; + TiFlashTestEnv() = delete; // no instance allow private: static std::vector global_contexts; + static bool is_mocked_s3_client; }; } // namespace DB::tests diff --git a/dbms/src/TestUtils/gtests_dbms_main.cpp b/dbms/src/TestUtils/gtests_dbms_main.cpp index c795b21cfec..2331cd77776 100644 --- a/dbms/src/TestUtils/gtests_dbms_main.cpp +++ b/dbms/src/TestUtils/gtests_dbms_main.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -97,6 +98,7 @@ int main(int argc, char ** argv) }; s3config.enable(/*check_requirements*/ false, DB::Logger::get()); Poco::Environment::set("AWS_EC2_METADATA_DISABLED", "true"); // disable to speedup testing + DB::tests::TiFlashTestEnv::setIsMockedS3Client(mock_s3 == "true"); DB::S3::ClientFactory::instance().init(s3config, mock_s3 == "true"); #ifdef FIU_ENABLE