Merge pull request #66332 from ClickHouse/backport/24.6/65403

Backport #65403 to 24.6: Use tryGetS3StorageClient to avoid raising an exception when logging s3
This commit is contained in:
robot-ch-test-poll1 2024-07-10 17:46:53 +04:00 committed by GitHub
commit 01c707837c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 34 additions and 20 deletions

View File

@ -355,6 +355,8 @@ public:
{
return delegate->getS3StorageClient();
}
std::shared_ptr<const S3::Client> tryGetS3StorageClient() const override { return delegate->tryGetS3StorageClient(); }
#endif
private:

View File

@ -478,6 +478,8 @@ public:
"Method getS3StorageClient() is not implemented for disk type: {}",
getDataSourceDescription().toString());
}
virtual std::shared_ptr<const S3::Client> tryGetS3StorageClient() const { return nullptr; }
#endif

View File

@ -138,6 +138,11 @@ public:
{
return object_storage->getS3StorageClient();
}
std::shared_ptr<const S3::Client> tryGetS3StorageClient() override
{
return object_storage->tryGetS3StorageClient();
}
#endif
private:

View File

@ -587,6 +587,11 @@ std::shared_ptr<const S3::Client> DiskObjectStorage::getS3StorageClient() const
{
return object_storage->getS3StorageClient();
}
std::shared_ptr<const S3::Client> DiskObjectStorage::tryGetS3StorageClient() const
{
return object_storage->tryGetS3StorageClient();
}
#endif
DiskPtr DiskObjectStorageReservation::getDisk(size_t i) const

View File

@ -214,6 +214,7 @@ public:
#if USE_AWS_S3
std::shared_ptr<const S3::Client> getS3StorageClient() const override;
std::shared_ptr<const S3::Client> tryGetS3StorageClient() const override;
#endif
private:

View File

@ -269,6 +269,7 @@ public:
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "This function is only implemented for S3ObjectStorage");
}
virtual std::shared_ptr<const S3::Client> tryGetS3StorageClient() { return nullptr; }
#endif

View File

@ -634,6 +634,10 @@ std::shared_ptr<const S3::Client> S3ObjectStorage::getS3StorageClient()
return client.get();
}
std::shared_ptr<const S3::Client> S3ObjectStorage::tryGetS3StorageClient()
{
return client.get();
}
}
#endif

View File

@ -169,6 +169,7 @@ public:
bool isReadOnly() const override { return s3_settings.get()->read_only; }
std::shared_ptr<const S3::Client> getS3StorageClient() override;
std::shared_ptr<const S3::Client> tryGetS3StorageClient() override;
private:
void setNewSettings(std::unique_ptr<S3ObjectStorageSettings> && s3_settings_);

View File

@ -233,9 +233,7 @@ void ServerAsynchronousMetrics::updateImpl(TimePoint update_time, TimePoint curr
}
#if USE_AWS_S3
try
{
if (auto s3_client = disk->getS3StorageClient())
if (auto s3_client = disk->tryGetS3StorageClient())
{
if (auto put_throttler = s3_client->getPutRequestThrottler())
{
@ -252,11 +250,6 @@ void ServerAsynchronousMetrics::updateImpl(TimePoint update_time, TimePoint curr
"Number of GetObject requests that can be currently issued without hitting throttling limit on the disk (virtual filesystem). Local filesystems may not provide this information." };
}
}
}
catch (...) // NOLINT(bugprone-empty-catch)
{
// Skip disk that do not have s3 throttlers
}
#endif
}
}