Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Mar 25, 2024
1 parent 3492cc3 commit d862a6a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cpp/src/arrow/filesystem/s3fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1005,14 +1005,14 @@ class InitOnceEndpointProvider : public Aws::S3::S3EndpointProviderBase {
// A class that instantiates a single EndpointProvider per distinct endpoint
// configuration and initializes it in a thread-safe way. See earlier comments
// for rationale.
class EndpointProviderBuilder {
class EndpointProviderCache {
public:
std::shared_ptr<Aws::S3::S3EndpointProviderBase> Lookup(
const Aws::S3::S3ClientConfiguration& config) {
auto key = EndpointConfigKey(config);
CacheValue* value;
{
std::unique_lock lock(cache_mutex_);
std::unique_lock lock(mutex_);
value = &cache_[std::move(key)];
}
std::call_once(value->once, [&]() {
Expand All @@ -1025,24 +1025,24 @@ class EndpointProviderBuilder {
}

void Reset() {
std::unique_lock lock(cache_mutex_);
std::unique_lock lock(mutex_);
cache_.clear();
}

static EndpointProviderBuilder* Instance() {
static EndpointProviderBuilder instance;
static EndpointProviderCache* Instance() {
static EndpointProviderCache instance;
return &instance;
}

protected:
EndpointProviderBuilder() = default;
private:
EndpointProviderCache() = default;

struct CacheValue {
std::once_flag once;
std::shared_ptr<Aws::S3::S3EndpointProviderBase> endpoint_provider;
};

std::mutex cache_mutex_;
std::mutex mutex_;
std::unordered_map<EndpointConfigKey, CacheValue> cache_;
};

Expand Down Expand Up @@ -1127,7 +1127,7 @@ class ClientBuilder {

#ifdef ARROW_S3_HAS_S3CLIENT_CONFIGURATION
client_config_.useVirtualAddressing = use_virtual_addressing;
auto endpoint_provider = EndpointProviderBuilder::Instance()->Lookup(client_config_);
auto endpoint_provider = EndpointProviderCache::Instance()->Lookup(client_config_);
auto client = std::make_shared<S3Client>(credentials_provider_, endpoint_provider,
client_config_);
#else
Expand Down Expand Up @@ -3096,7 +3096,7 @@ struct AwsInstance {
}
GetClientFinalizer()->Finalize();
#ifdef ARROW_S3_HAS_S3CLIENT_CONFIGURATION
EndpointProviderBuilder::Instance()->Reset();
EndpointProviderCache::Instance()->Reset();
#endif
Aws::ShutdownAPI(aws_options_);
}
Expand Down

0 comments on commit d862a6a

Please sign in to comment.