@@ -238,7 +238,7 @@ public class S3AFileSystem extends FileSystem implements StreamCapabilities,
238238 private volatile boolean isClosed = false ;
239239 private MetadataStore metadataStore ;
240240 private boolean allowAuthoritativeMetadataStore ;
241- private Collection <String > allowAuthoritativePaths = new ArrayList <>() ;
241+ private Collection <String > allowAuthoritativePaths ;
242242
243243 /** Delegation token integration; non-empty when DT support is enabled. */
244244 private Optional <S3ADelegationTokens > delegationTokens = Optional .empty ();
@@ -400,15 +400,7 @@ public void initialize(URI name, Configuration originalConf)
400400 setMetadataStore (S3Guard .getMetadataStore (this ));
401401 allowAuthoritativeMetadataStore = conf .getBoolean (METADATASTORE_AUTHORITATIVE ,
402402 DEFAULT_METADATASTORE_AUTHORITATIVE );
403-
404- String [] authoritativePaths =
405- conf .getTrimmedStrings (AUTHORITATIVE_PATH , DEFAULT_AUTHORITATIVE_PATH );
406- if (authoritativePaths .length > 0 ) {
407- for (int i = 0 ; i < authoritativePaths .length ; i ++) {
408- Path qualified = qualify (new Path (authoritativePaths [i ]));
409- allowAuthoritativePaths .add (maybeAddTrailingSlash (qualified .toString ()));
410- }
411- }
403+ allowAuthoritativePaths = S3Guard .getAuthoritativePaths (this );
412404
413405 if (hasMetadataStore ()) {
414406 LOG .debug ("Using metadata store {}, authoritative store={}, authoritative path={}" ,
@@ -421,23 +413,6 @@ public void initialize(URI name, Configuration originalConf)
421413
422414 }
423415
424- @ VisibleForTesting
425- boolean allowAuthoritative (Path p ) {
426- String haystack = maybeAddTrailingSlash (p .toString ());
427- if (allowAuthoritativeMetadataStore ) {
428- return true ;
429- }
430- if (!allowAuthoritativePaths .isEmpty ()) {
431- for (String needle : allowAuthoritativePaths ) {
432-
433- if (haystack .startsWith (needle )) {
434- return true ;
435- }
436- }
437- }
438- return false ;
439- }
440-
441416 /**
442417 * Initialize the thread pool.
443418 * This must be re-invoked after replacing the S3Client during test
@@ -868,7 +843,8 @@ public String pathToKey(Path path) {
868843 * @param key s3 key or ""
869844 * @return the with a trailing "/", or, if it is the root key, "",
870845 */
871- private String maybeAddTrailingSlash (String key ) {
846+ @ InterfaceAudience .Private
847+ public String maybeAddTrailingSlash (String key ) {
872848 if (!key .isEmpty () && !key .endsWith ("/" )) {
873849 return key + '/' ;
874850 } else {
@@ -2426,7 +2402,9 @@ public FileStatus[] innerListStatus(Path f) throws FileNotFoundException,
24262402
24272403 DirListingMetadata dirMeta =
24282404 S3Guard .listChildrenWithTtl (metadataStore , path , ttlTimeProvider );
2429- if (allowAuthoritative (f ) && dirMeta != null && dirMeta .isAuthoritative ()) {
2405+ boolean allowAuthoritative = S3Guard .allowAuthoritative (f , this ,
2406+ allowAuthoritativeMetadataStore , allowAuthoritativePaths );
2407+ if (allowAuthoritative && dirMeta != null && dirMeta .isAuthoritative ()) {
24302408 return S3Guard .dirMetaToStatuses (dirMeta );
24312409 }
24322410
@@ -2443,8 +2421,9 @@ public FileStatus[] innerListStatus(Path f) throws FileNotFoundException,
24432421 result .add (files .next ());
24442422 }
24452423 // merge the results. This will update the store as needed
2424+
24462425 return S3Guard .dirListingUnion (metadataStore , path , result , dirMeta ,
2447- allowAuthoritative ( f ) , ttlTimeProvider );
2426+ allowAuthoritative , ttlTimeProvider );
24482427 } else {
24492428 LOG .debug ("Adding: rd (not a dir): {}" , path );
24502429 FileStatus [] stats = new FileStatus [1 ];
@@ -2657,8 +2636,10 @@ S3AFileStatus innerGetFileStatus(final Path f,
26572636 // dest is also a directory, there's no difference.
26582637 // TODO After HADOOP-16085 the modification detection can be done with
26592638 // etags or object version instead of modTime
2639+ boolean allowAuthoritative = S3Guard .allowAuthoritative (f , this ,
2640+ allowAuthoritativeMetadataStore , allowAuthoritativePaths );
26602641 if (!pm .getFileStatus ().isDirectory () &&
2661- !allowAuthoritative ( f ) ) {
2642+ !allowAuthoritative ) {
26622643 LOG .debug ("Metadata for {} found in the non-auth metastore." , path );
26632644 final long msModTime = pm .getFileStatus ().getModificationTime ();
26642645
@@ -3823,13 +3804,16 @@ private RemoteIterator<S3ALocatedFileStatus> innerListFiles(Path f, boolean
38233804 key , delimiter );
38243805 final RemoteIterator <S3AFileStatus > cachedFilesIterator ;
38253806 final Set <Path > tombstones ;
3807+ boolean allowAuthoritative = S3Guard .allowAuthoritative (f , this ,
3808+ allowAuthoritativeMetadataStore , allowAuthoritativePaths );
38263809 if (recursive ) {
38273810 final PathMetadata pm = metadataStore .get (path , true );
38283811 // shouldn't need to check pm.isDeleted() because that will have
38293812 // been caught by getFileStatus above.
3813+
38303814 MetadataStoreListFilesIterator metadataStoreListFilesIterator =
38313815 new MetadataStoreListFilesIterator (metadataStore , pm ,
3832- allowAuthoritative ( f ) );
3816+ allowAuthoritative );
38333817 tombstones = metadataStoreListFilesIterator .listTombstones ();
38343818 cachedFilesIterator = metadataStoreListFilesIterator ;
38353819 } else {
@@ -3842,7 +3826,7 @@ private RemoteIterator<S3ALocatedFileStatus> innerListFiles(Path f, boolean
38423826 }
38433827 cachedFilesIterator = listing .createProvidedFileStatusIterator (
38443828 S3Guard .dirMetaToStatuses (meta ), ACCEPT_ALL , acceptor );
3845- if (allowAuthoritative ( f ) && meta != null && meta .isAuthoritative ()) {
3829+ if (allowAuthoritative && meta != null && meta .isAuthoritative ()) {
38463830 // metadata listing is authoritative, so return it directly
38473831 return listing .createLocatedFileStatusIterator (cachedFilesIterator );
38483832 }
@@ -3915,7 +3899,9 @@ public RemoteIterator<LocatedFileStatus> listLocatedStatus(final Path f,
39153899 final RemoteIterator <S3AFileStatus > cachedFileStatusIterator =
39163900 listing .createProvidedFileStatusIterator (
39173901 S3Guard .dirMetaToStatuses (meta ), filter , acceptor );
3918- return (allowAuthoritative (f ) && meta != null
3902+ boolean allowAuthoritative = S3Guard .allowAuthoritative (f , this ,
3903+ allowAuthoritativeMetadataStore , allowAuthoritativePaths );
3904+ return (allowAuthoritative && meta != null
39193905 && meta .isAuthoritative ())
39203906 ? listing .createLocatedFileStatusIterator (
39213907 cachedFileStatusIterator )
0 commit comments