Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S3 not interruptting #12227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/libstore/s3-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
#include <aws/core/auth/AWSCredentialsProviderChain.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/client/DefaultRetryStrategy.h>
#include <aws/core/http/standard/StandardHttpResponse.h>
#include <aws/core/http/standard/StandardHttpRequest.h>
#include <aws/core/http/HttpClient.h>
#include <aws/core/utils/logging/FormattedLogSystem.h>
#include <aws/core/utils/logging/LogMacros.h>
#include <aws/core/utils/ratelimiter/RateLimiterInterface.h>
#include <aws/core/utils/threading/Executor.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/GetObjectRequest.h>
Expand Down Expand Up @@ -70,6 +74,49 @@ class AwsLogger : public Aws::Utils::Logging::FormattedLogSystem
#endif
};

class AwsHttpClient : public Aws::Http::HttpClient
{
public:
AwsHttpClient(const Aws::Client::ClientConfiguration& clientConfig) : HttpClient() {}

std::shared_ptr<Aws::Http::HttpResponse> MakeRequest(const std::shared_ptr<Aws::Http::HttpRequest>& request,
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const override {
Aws::Http::URI uri = request->GetUri();
Aws::String url = uri.GetURIString();

debug("Making request %s", url);

std::shared_ptr<Aws::Http::Standard::StandardHttpResponse> response = std::make_shared<Aws::Http::Standard::StandardHttpResponse>(request);

if (writeLimiter != nullptr) {
writeLimiter->ApplyAndPayForCost(request->GetSize());
}

FileTransferRequest ftr = FileTransferRequest(url);
getFileTransfer()->download(ftr);
return response;
}
};

class AwsHttpClientFactory : public Aws::Http::HttpClientFactory
{
public:
std::shared_ptr<Aws::Http::HttpClient> CreateHttpClient(const Aws::Client::ClientConfiguration& clientConfiguration) const override {
return std::make_shared<AwsHttpClient>(clientConfiguration);
}

std::shared_ptr<Aws::Http::HttpRequest> CreateHttpRequest(const Aws::String& uri, Aws::Http::HttpMethod method, const Aws::IOStreamFactory& streamFactory) const override {
return CreateHttpRequest(Aws::Http::URI(uri), method, streamFactory);
}

std::shared_ptr<Aws::Http::HttpRequest> CreateHttpRequest(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const Aws::IOStreamFactory& streamFactory) const override {
auto request = std::make_shared<Aws::Http::Standard::StandardHttpRequest>(uri, method);
request->SetResponseStreamFactory(streamFactory);
return request;
}
};

static void initAWS()
{
static std::once_flag flag;
Expand All @@ -80,6 +127,10 @@ static void initAWS()
shared.cc), so don't let aws-sdk-cpp override it. */
options.cryptoOptions.initAndCleanupOpenSSL = false;

options.httpOptions.httpClientFactory_create_fn = []() {
return std::make_shared<AwsHttpClientFactory>();
};

if (verbosity >= lvlDebug) {
options.loggingOptions.logLevel =
verbosity == lvlDebug
Expand Down
Loading