Skip to content

Commit c9a72d6

Browse files
committed
remove getS3Region() from S3AFS
1 parent 81a5133 commit c9a72d6

File tree

3 files changed

+3
-75
lines changed

3 files changed

+3
-75
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
8484
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
8585
import software.amazon.awssdk.services.s3.model.S3Error;
86-
import software.amazon.awssdk.services.s3.model.S3Exception;
8786
import software.amazon.awssdk.services.s3.model.S3Object;
8887
import software.amazon.awssdk.services.s3.model.SelectObjectContentRequest;
8988
import software.amazon.awssdk.services.s3.model.SelectObjectContentResponseHandler;
@@ -98,7 +97,6 @@
9897
import software.amazon.awssdk.transfer.s3.model.FileUpload;
9998
import software.amazon.awssdk.transfer.s3.model.UploadFileRequest;
10099

101-
import org.apache.commons.lang3.StringUtils;
102100
import org.apache.hadoop.fs.impl.prefetch.ExecutorServiceFuturePool;
103101
import org.slf4j.Logger;
104102
import org.slf4j.LoggerFactory;
@@ -249,7 +247,6 @@
249247
import static org.apache.hadoop.fs.s3a.impl.InternalConstants.CSE_PADDING_LENGTH;
250248
import static org.apache.hadoop.fs.s3a.impl.InternalConstants.DEFAULT_UPLOAD_PART_COUNT_LIMIT;
251249
import static org.apache.hadoop.fs.s3a.impl.InternalConstants.DELETE_CONSIDERED_IDEMPOTENT;
252-
import static org.apache.hadoop.fs.s3a.impl.InternalConstants.SC_301_MOVED_PERMANENTLY;
253250
import static org.apache.hadoop.fs.s3a.impl.InternalConstants.SC_403_FORBIDDEN;
254251
import static org.apache.hadoop.fs.s3a.impl.InternalConstants.SC_404_NOT_FOUND;
255252
import static org.apache.hadoop.fs.s3a.impl.InternalConstants.UPLOAD_PART_COUNT_LIMIT;
@@ -334,8 +331,7 @@ public class S3AFileSystem extends FileSystem implements StreamCapabilities,
334331
private int executorCapacity;
335332
private long multiPartThreshold;
336333
public static final Logger LOG = LoggerFactory.getLogger(S3AFileSystem.class);
337-
/** Exactly once log to warn about setting the region in config to avoid probe. */
338-
private static final LogExactlyOnce SET_REGION_WARNING = new LogExactlyOnce(LOG);
334+
339335
private static final Logger PROGRESS =
340336
LoggerFactory.getLogger("org.apache.hadoop.fs.s3a.S3AFileSystem.Progress");
341337
private LocalDirAllocator directoryAllocator;
@@ -1016,74 +1012,6 @@ private synchronized void createS3AsyncClient(S3ClientFactory clientFactory,
10161012
s3AsyncClient = clientFactory.createS3AsyncClient(getUri(), parameters);
10171013
}
10181014

1019-
/**
1020-
* Get the bucket region.
1021-
*
1022-
* @param region AWS S3 Region set in the config. This property may not be set, in which case
1023-
* ask S3 for the region.
1024-
* @return region of the bucket.
1025-
*/
1026-
private Region getS3Region(String region) throws IOException {
1027-
1028-
if (!StringUtils.isBlank(region)) {
1029-
return Region.of(region);
1030-
}
1031-
1032-
Region cachedRegion = BUCKET_REGIONS.get(bucket);
1033-
1034-
if (cachedRegion != null) {
1035-
LOG.debug("Got region {} for bucket {} from cache", cachedRegion, bucket);
1036-
return cachedRegion;
1037-
}
1038-
1039-
Region s3Region = trackDurationAndSpan(STORE_REGION_PROBE, bucket, null,
1040-
() -> invoker.retry("getS3Region", bucket, true, () -> {
1041-
try {
1042-
1043-
SET_REGION_WARNING.warn(
1044-
"Getting region for bucket {} from S3, this will slow down FS initialisation. "
1045-
+ "To avoid this, set the region using property {}", bucket,
1046-
FS_S3A_BUCKET_PREFIX + bucket + ".endpoint.region");
1047-
1048-
// build a s3 client with region eu-west-1 that can be used to get the region of the
1049-
// bucket. Using eu-west-1, as headBucket() doesn't work with us-east-1. This is because
1050-
// us-east-1 uses the endpoint s3.amazonaws.com, which resolves bucket.s3.amazonaws.com
1051-
// to the actual region the bucket is in. As the request is signed with us-east-1 and
1052-
// not the bucket's region, it fails.
1053-
S3Client getRegionS3Client =
1054-
S3Client.builder().region(Region.EU_WEST_1).credentialsProvider(credentials)
1055-
.build();
1056-
1057-
HeadBucketResponse headBucketResponse =
1058-
getRegionS3Client.headBucket(HeadBucketRequest.builder().bucket(bucket).build());
1059-
1060-
Region bucketRegion = Region.of(
1061-
headBucketResponse.sdkHttpResponse().headers().get(BUCKET_REGION_HEADER).get(0));
1062-
BUCKET_REGIONS.put(bucket, bucketRegion);
1063-
1064-
return bucketRegion;
1065-
} catch (S3Exception exception) {
1066-
if (exception.statusCode() == SC_301_MOVED_PERMANENTLY) {
1067-
Region bucketRegion = Region.of(
1068-
exception.awsErrorDetails().sdkHttpResponse().headers().get(BUCKET_REGION_HEADER)
1069-
.get(0));
1070-
BUCKET_REGIONS.put(bucket, bucketRegion);
1071-
1072-
return bucketRegion;
1073-
}
1074-
1075-
if (exception.statusCode() == SC_404_NOT_FOUND) {
1076-
throw new UnknownStoreException("s3a://" + bucket + "/",
1077-
" Bucket does " + "not exist");
1078-
}
1079-
1080-
throw exception;
1081-
}
1082-
}));
1083-
1084-
return s3Region;
1085-
}
1086-
10871015
/**
10881016
* Initialize and launch the audit manager and service.
10891017
* As this takes the FS IOStatistics store, it must be invoked

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Statistic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ public enum Statistic {
539539
"Rate of S3 request throttling",
540540
TYPE_QUANTILE),
541541
STORE_REGION_PROBE(
542-
"store_region_probe",
542+
StoreStatisticNames.STORE_REGION_PROBE,
543543
"Store Region Probe",
544544
TYPE_DURATION
545545
),

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/auth/RoleModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static String[] directory(Path path) {
134134
if (!key.isEmpty()) {
135135
return new String[] {
136136
resource(host, key + "/", true),
137-
resource(host, key, true),
137+
resource(host, key, false),
138138
resource(host, key + "/", false),
139139
};
140140
} else {

0 commit comments

Comments
 (0)