34
34
import java .util .Collections ;
35
35
import java .util .Date ;
36
36
import java .util .EnumSet ;
37
- import java .util .HashMap ;
38
37
import java .util .Iterator ;
39
38
import java .util .List ;
40
39
import java .util .Locale ;
54
53
55
54
import software .amazon .awssdk .core .ResponseInputStream ;
56
55
import software .amazon .awssdk .core .exception .SdkException ;
57
- import software .amazon .awssdk .regions .Region ;
58
56
import software .amazon .awssdk .services .s3 .S3AsyncClient ;
59
57
import software .amazon .awssdk .services .s3 .S3Client ;
60
58
import software .amazon .awssdk .services .s3 .model .CompleteMultipartUploadRequest ;
83
81
import software .amazon .awssdk .services .s3 .model .PutObjectRequest ;
84
82
import software .amazon .awssdk .services .s3 .model .PutObjectResponse ;
85
83
import software .amazon .awssdk .services .s3 .model .S3Error ;
86
- import software .amazon .awssdk .services .s3 .model .S3Exception ;
87
84
import software .amazon .awssdk .services .s3 .model .S3Object ;
88
85
import software .amazon .awssdk .services .s3 .model .SelectObjectContentRequest ;
89
86
import software .amazon .awssdk .services .s3 .model .SelectObjectContentResponseHandler ;
98
95
import software .amazon .awssdk .transfer .s3 .model .FileUpload ;
99
96
import software .amazon .awssdk .transfer .s3 .model .UploadFileRequest ;
100
97
101
- import org .apache .commons .lang3 .StringUtils ;
102
98
import org .apache .hadoop .fs .impl .prefetch .ExecutorServiceFuturePool ;
103
99
import org .slf4j .Logger ;
104
100
import org .slf4j .LoggerFactory ;
246
242
import static org .apache .hadoop .fs .s3a .impl .InternalConstants .CSE_PADDING_LENGTH ;
247
243
import static org .apache .hadoop .fs .s3a .impl .InternalConstants .DEFAULT_UPLOAD_PART_COUNT_LIMIT ;
248
244
import static org .apache .hadoop .fs .s3a .impl .InternalConstants .DELETE_CONSIDERED_IDEMPOTENT ;
249
- import static org .apache .hadoop .fs .s3a .impl .InternalConstants .SC_301_MOVED_PERMANENTLY ;
250
245
import static org .apache .hadoop .fs .s3a .impl .InternalConstants .SC_403_FORBIDDEN ;
251
246
import static org .apache .hadoop .fs .s3a .impl .InternalConstants .SC_404_NOT_FOUND ;
252
247
import static org .apache .hadoop .fs .s3a .impl .InternalConstants .UPLOAD_PART_COUNT_LIMIT ;
@@ -332,8 +327,6 @@ public class S3AFileSystem extends FileSystem implements StreamCapabilities,
332
327
private int executorCapacity ;
333
328
private long multiPartThreshold ;
334
329
public static final Logger LOG = LoggerFactory .getLogger (S3AFileSystem .class );
335
- /** Exactly once log to warn about setting the region in config to avoid probe. */
336
- private static final LogExactlyOnce SET_REGION_WARNING = new LogExactlyOnce (LOG );
337
330
338
331
/** Log to warn of storage class configuration problems. */
339
332
private static final LogExactlyOnce STORAGE_CLASS_WARNING = new LogExactlyOnce (LOG );
@@ -461,8 +454,6 @@ public class S3AFileSystem extends FileSystem implements StreamCapabilities,
461
454
*/
462
455
private String scheme = FS_S3A ;
463
456
464
- private final static Map <String , Region > BUCKET_REGIONS = new HashMap <>();
465
-
466
457
/** Add any deprecated keys. */
467
458
@ SuppressWarnings ("deprecation" )
468
459
private static void addDeprecatedKeys () {
@@ -872,9 +863,6 @@ protected void verifyBucketExists() throws UnknownStoreException, IOException {
872
863
STORE_EXISTS_PROBE , bucket , null , () ->
873
864
invoker .retry ("doesBucketExist" , bucket , true , () -> {
874
865
try {
875
- if (BUCKET_REGIONS .containsKey (bucket )) {
876
- return true ;
877
- }
878
866
s3Client .headBucket (HeadBucketRequest .builder ().bucket (bucket ).build ());
879
867
return true ;
880
868
} catch (AwsServiceException ex ) {
@@ -984,8 +972,6 @@ private void bindAWSClient(URI name, boolean dtEnabled) throws IOException {
984
972
? conf .getTrimmed (AWS_REGION )
985
973
: accessPoint .getRegion ();
986
974
987
- Region region = getS3Region (configuredRegion );
988
-
989
975
S3ClientFactory .S3ClientCreationParameters parameters =
990
976
new S3ClientFactory .S3ClientCreationParameters ()
991
977
.withCredentialSet (credentials )
@@ -1000,7 +986,7 @@ private void bindAWSClient(URI name, boolean dtEnabled) throws IOException {
1000
986
.withMultipartCopyEnabled (isMultipartCopyEnabled )
1001
987
.withMultipartThreshold (multiPartThreshold )
1002
988
.withTransferManagerExecutor (unboundedThreadPool )
1003
- .withRegion (region );
989
+ .withRegion (configuredRegion );
1004
990
1005
991
S3ClientFactory clientFactory = ReflectionUtils .newInstance (s3ClientFactoryClass , conf );
1006
992
s3Client = clientFactory .createS3Client (getUri (), parameters );
@@ -1021,75 +1007,6 @@ private void createS3AsyncClient(S3ClientFactory clientFactory,
1021
1007
s3AsyncClient = clientFactory .createS3AsyncClient (getUri (), parameters );
1022
1008
}
1023
1009
1024
- /**
1025
- * Get the bucket region.
1026
- *
1027
- * @param region AWS S3 Region set in the config. This property may not be set, in which case
1028
- * ask S3 for the region.
1029
- * @return region of the bucket.
1030
- */
1031
- private Region getS3Region (String region ) throws IOException {
1032
-
1033
- if (!StringUtils .isBlank (region )) {
1034
- return Region .of (region );
1035
- }
1036
-
1037
- Region cachedRegion = BUCKET_REGIONS .get (bucket );
1038
-
1039
- if (cachedRegion != null ) {
1040
- LOG .debug ("Got region {} for bucket {} from cache" , cachedRegion , bucket );
1041
- return cachedRegion ;
1042
- }
1043
-
1044
- Region s3Region = trackDurationAndSpan (STORE_REGION_PROBE , bucket , null ,
1045
- () -> invoker .retry ("getS3Region" , bucket , true , () -> {
1046
- try {
1047
-
1048
- SET_REGION_WARNING .warn (
1049
- "Getting region for bucket {} from S3, this will slow down FS initialisation. "
1050
- + "To avoid this, set the region using property {}" , bucket ,
1051
- FS_S3A_BUCKET_PREFIX + bucket + ".endpoint.region" );
1052
-
1053
- // build a s3 client with region eu-west-1 that can be used to get the region of the
1054
- // bucket. Using eu-west-1, as headBucket() doesn't work with us-east-1. This is because
1055
- // us-east-1 uses the endpoint s3.amazonaws.com, which resolves bucket.s3.amazonaws.com
1056
- // to the actual region the bucket is in. As the request is signed with us-east-1 and
1057
- // not the bucket's region, it fails.
1058
- S3Client getRegionS3Client =
1059
- S3Client .builder ().region (Region .EU_WEST_1 ).credentialsProvider (credentials )
1060
- .build ();
1061
-
1062
- HeadBucketResponse headBucketResponse =
1063
- getRegionS3Client .headBucket (HeadBucketRequest .builder ().bucket (bucket ).build ());
1064
-
1065
- Region bucketRegion = Region .of (
1066
- headBucketResponse .sdkHttpResponse ().headers ().get (BUCKET_REGION_HEADER ).get (0 ));
1067
- BUCKET_REGIONS .put (bucket , bucketRegion );
1068
-
1069
- return bucketRegion ;
1070
- } catch (S3Exception exception ) {
1071
- if (exception .statusCode () == SC_301_MOVED_PERMANENTLY ) {
1072
- Region bucketRegion = Region .of (
1073
- exception .awsErrorDetails ().sdkHttpResponse ().headers ().get (BUCKET_REGION_HEADER )
1074
- .get (0 ));
1075
- BUCKET_REGIONS .put (bucket , bucketRegion );
1076
-
1077
- return bucketRegion ;
1078
- }
1079
-
1080
- if (exception .statusCode () == SC_404_NOT_FOUND ) {
1081
- throw new UnknownStoreException ("s3a://" + bucket + "/" ,
1082
- " Bucket does not exist: " + exception ,
1083
- exception );
1084
- }
1085
-
1086
- throw exception ;
1087
- }
1088
- }));
1089
-
1090
- return s3Region ;
1091
- }
1092
-
1093
1010
/**
1094
1011
* Initialize and launch the audit manager and service.
1095
1012
* As this takes the FS IOStatistics store, it must be invoked
0 commit comments