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 () {
@@ -870,9 +861,6 @@ protected void verifyBucketExists() throws UnknownStoreException, IOException {
870
861
STORE_EXISTS_PROBE , bucket , null , () ->
871
862
invoker .retry ("doesBucketExist" , bucket , true , () -> {
872
863
try {
873
- if (BUCKET_REGIONS .containsKey (bucket )) {
874
- return true ;
875
- }
876
864
s3Client .headBucket (HeadBucketRequest .builder ().bucket (bucket ).build ());
877
865
return true ;
878
866
} catch (AwsServiceException ex ) {
@@ -982,8 +970,6 @@ private void bindAWSClient(URI name, boolean dtEnabled) throws IOException {
982
970
? conf .getTrimmed (AWS_REGION )
983
971
: accessPoint .getRegion ();
984
972
985
- Region region = getS3Region (configuredRegion );
986
-
987
973
S3ClientFactory .S3ClientCreationParameters parameters =
988
974
new S3ClientFactory .S3ClientCreationParameters ()
989
975
.withCredentialSet (credentials )
@@ -998,7 +984,7 @@ private void bindAWSClient(URI name, boolean dtEnabled) throws IOException {
998
984
.withMultipartCopyEnabled (isMultipartCopyEnabled )
999
985
.withMultipartThreshold (multiPartThreshold )
1000
986
.withTransferManagerExecutor (unboundedThreadPool )
1001
- .withRegion (region );
987
+ .withRegion (configuredRegion );
1002
988
1003
989
S3ClientFactory clientFactory = ReflectionUtils .newInstance (s3ClientFactoryClass , conf );
1004
990
s3Client = clientFactory .createS3Client (getUri (), parameters );
@@ -1019,75 +1005,6 @@ private void createS3AsyncClient(S3ClientFactory clientFactory,
1019
1005
s3AsyncClient = clientFactory .createS3AsyncClient (getUri (), parameters );
1020
1006
}
1021
1007
1022
- /**
1023
- * Get the bucket region.
1024
- *
1025
- * @param region AWS S3 Region set in the config. This property may not be set, in which case
1026
- * ask S3 for the region.
1027
- * @return region of the bucket.
1028
- */
1029
- private Region getS3Region (String region ) throws IOException {
1030
-
1031
- if (!StringUtils .isBlank (region )) {
1032
- return Region .of (region );
1033
- }
1034
-
1035
- Region cachedRegion = BUCKET_REGIONS .get (bucket );
1036
-
1037
- if (cachedRegion != null ) {
1038
- LOG .debug ("Got region {} for bucket {} from cache" , cachedRegion , bucket );
1039
- return cachedRegion ;
1040
- }
1041
-
1042
- Region s3Region = trackDurationAndSpan (STORE_REGION_PROBE , bucket , null ,
1043
- () -> invoker .retry ("getS3Region" , bucket , true , () -> {
1044
- try {
1045
-
1046
- SET_REGION_WARNING .warn (
1047
- "Getting region for bucket {} from S3, this will slow down FS initialisation. "
1048
- + "To avoid this, set the region using property {}" , bucket ,
1049
- FS_S3A_BUCKET_PREFIX + bucket + ".endpoint.region" );
1050
-
1051
- // build a s3 client with region eu-west-1 that can be used to get the region of the
1052
- // bucket. Using eu-west-1, as headBucket() doesn't work with us-east-1. This is because
1053
- // us-east-1 uses the endpoint s3.amazonaws.com, which resolves bucket.s3.amazonaws.com
1054
- // to the actual region the bucket is in. As the request is signed with us-east-1 and
1055
- // not the bucket's region, it fails.
1056
- S3Client getRegionS3Client =
1057
- S3Client .builder ().region (Region .EU_WEST_1 ).credentialsProvider (credentials )
1058
- .build ();
1059
-
1060
- HeadBucketResponse headBucketResponse =
1061
- getRegionS3Client .headBucket (HeadBucketRequest .builder ().bucket (bucket ).build ());
1062
-
1063
- Region bucketRegion = Region .of (
1064
- headBucketResponse .sdkHttpResponse ().headers ().get (BUCKET_REGION_HEADER ).get (0 ));
1065
- BUCKET_REGIONS .put (bucket , bucketRegion );
1066
-
1067
- return bucketRegion ;
1068
- } catch (S3Exception exception ) {
1069
- if (exception .statusCode () == SC_301_MOVED_PERMANENTLY ) {
1070
- Region bucketRegion = Region .of (
1071
- exception .awsErrorDetails ().sdkHttpResponse ().headers ().get (BUCKET_REGION_HEADER )
1072
- .get (0 ));
1073
- BUCKET_REGIONS .put (bucket , bucketRegion );
1074
-
1075
- return bucketRegion ;
1076
- }
1077
-
1078
- if (exception .statusCode () == SC_404_NOT_FOUND ) {
1079
- throw new UnknownStoreException ("s3a://" + bucket + "/" ,
1080
- " Bucket does not exist: " + exception ,
1081
- exception );
1082
- }
1083
-
1084
- throw exception ;
1085
- }
1086
- }));
1087
-
1088
- return s3Region ;
1089
- }
1090
-
1091
1008
/**
1092
1009
* Initialize and launch the audit manager and service.
1093
1010
* As this takes the FS IOStatistics store, it must be invoked
0 commit comments