Skip to content
Merged
Changes from 2 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
19 changes: 17 additions & 2 deletions src/IO/S3/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,19 +703,34 @@ Client::doRequest(RequestType & request, RequestFn request_fn) const
continue;
}

if (error.GetResponseCode() != Aws::Http::HttpResponseCode::MOVED_PERMANENTLY)
/// IllegalLocationConstraintException may indicate that we are working with an opt-in region (e.g. me-south-1)
/// In that case, we need to update the region and try again
if (error.GetResponseCode() != Aws::Http::HttpResponseCode::MOVED_PERMANENTLY && error.GetExceptionName() != "IllegalLocationConstraintException")
return result;

// maybe we detect a correct region
if (!detect_region)
bool new_region_detected = false;
if (!detect_region || error.GetExceptionName() == "IllegalLocationConstraintException")
{
if (auto region = GetErrorMarshaller()->ExtractRegion(error); !region.empty() && region != explicit_region)
{
LOG_INFO(log, "Detected new region: {}", region);
request.overrideRegion(region);
insertRegionOverride(bucket, region);
new_region_detected = true;
}
}

/// special handling for opt-in regions
if (new_region_detected && error.GetExceptionName() == "IllegalLocationConstraintException" && initial_endpoint.substr(11) == "amazonaws.com")
{
S3::URI new_uri(initial_endpoint);
new_uri.addRegionToURI(request.getRegionOverride());
found_new_endpoint = true;
request.overrideURI(new_uri);
continue;
}

// we possibly got new location, need to try with that one
auto new_uri = getURIFromError(error);
if (!new_uri)
Expand Down
Loading