Skip to content

Commit 4a9f038

Browse files
author
Bhavay Pahuja
committed
Remove FileStatusAcceptor and Handle all cases for config values
1 parent 9cf4bf2 commit 4a9f038

File tree

3 files changed

+24
-80
lines changed

3 files changed

+24
-80
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,11 +1501,6 @@ private Constants() {
15011501
*/
15021502
public static final String READ_RESTORED_GLACIER_OBJECTS = "fs.s3a.glacier.read.restored.objects";
15031503

1504-
/**
1505-
* Default value of Read Restored Glacier objects config.
1506-
*/
1507-
public static final S3ObjectStorageClassFilter DEFAULT_READ_RESTORED_GLACIER_OBJECTS = S3ObjectStorageClassFilter.READ_ALL;
1508-
15091504
/**
15101505
* The bucket region header.
15111506
*/

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

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import org.apache.hadoop.util.Lists;
2221
import software.amazon.awssdk.services.s3.model.CommonPrefix;
2322
import software.amazon.awssdk.services.s3.model.S3Object;
2423

@@ -130,7 +129,7 @@ public static RemoteIterator<S3AFileStatus> toProvidedFileStatusIterator(
130129
* @param listPath path of the listing
131130
* @param request initial request to make
132131
* @param filter the filter on which paths to accept
133-
* @param acceptors the class/predicate to decide which entries to accept
132+
* @param acceptor the class/predicate to decide which entries to accept
134133
* in the listing based on the full file status.
135134
* @param span audit span for this iterator
136135
* @return the iterator
@@ -141,12 +140,12 @@ public FileStatusListingIterator createFileStatusListingIterator(
141140
Path listPath,
142141
S3ListRequest request,
143142
PathFilter filter,
144-
List<FileStatusAcceptor> acceptors,
143+
FileStatusAcceptor acceptor,
145144
AuditSpan span) throws IOException {
146145
return new FileStatusListingIterator(
147146
createObjectListingIterator(listPath, request, span),
148147
filter,
149-
FileStatusAcceptor.resolveFileStatusAcceptors(acceptors)
148+
acceptor
150149
);
151150
}
152151

@@ -194,14 +193,14 @@ public RemoteIterator<S3ALocatedFileStatus> createSingleStatusIterator(
194193
* List files under a path assuming the path to be a directory.
195194
* @param path input path.
196195
* @param recursive recursive listing?
197-
* @param acceptors file status filter
196+
* @param acceptor file status filter
198197
* @param span audit span for this iterator
199198
* @return an iterator over listing.
200199
* @throws IOException any exception.
201200
*/
202201
public RemoteIterator<S3ALocatedFileStatus> getListFilesAssumingDir(
203202
Path path,
204-
boolean recursive, List<FileStatusAcceptor> acceptors,
203+
boolean recursive, FileStatusAcceptor acceptor,
205204
AuditSpan span) throws IOException {
206205

207206
String key = maybeAddTrailingSlash(pathToKey(path));
@@ -219,7 +218,7 @@ public RemoteIterator<S3ALocatedFileStatus> getListFilesAssumingDir(
219218
delimiter,
220219
span),
221220
ACCEPT_ALL,
222-
acceptors,
221+
acceptor,
223222
span));
224223
}
225224

@@ -241,7 +240,7 @@ public RemoteIterator<S3ALocatedFileStatus> getLocatedFileStatusIteratorForDir(
241240
listingOperationCallbacks
242241
.createListObjectsRequest(key, "/", span),
243242
filter,
244-
Lists.newArrayList(new GlacierStatusAcceptor(s3ObjectStorageClassFilter), new AcceptAllButSelfAndS3nDirs(dir)),
243+
new AcceptAllButSelfAndS3nDirs(dir),
245244
span));
246245
}
247246

@@ -270,8 +269,7 @@ public RemoteIterator<S3ALocatedFileStatus> getLocatedFileStatusIteratorForDir(
270269
path,
271270
request,
272271
ACCEPT_ALL,
273-
Lists.newArrayList(new GlacierStatusAcceptor(s3ObjectStorageClassFilter),
274-
new AcceptAllButSelfAndS3nDirs(path)),
272+
new AcceptAllButSelfAndS3nDirs(path),
275273
span);
276274
}
277275

@@ -491,7 +489,8 @@ private boolean buildNextStatusBatch(S3ListResult objects) {
491489
LOG.debug("{}: {}", keyPath, stringify(s3Object));
492490
}
493491
// Skip over keys that are ourselves and old S3N _$folder$ files
494-
if (acceptor.accept(keyPath, s3Object) && filter.accept(keyPath)) {
492+
// Handle Glacier Storage Class objects based on the config fs.s3a.glacier.read.restored.objects value set
493+
if ( s3ObjectStorageClassFilter.getFilter().apply(s3Object) && acceptor.accept(keyPath, s3Object) && filter.accept(keyPath)) {
495494
S3AFileStatus status = createFileStatus(keyPath, s3Object,
496495
listingOperationCallbacks.getDefaultBlockSize(keyPath),
497496
getStoreContext().getUsername(),
@@ -860,56 +859,6 @@ public boolean accept(FileStatus status) {
860859
}
861860
}
862861

863-
864-
/**
865-
* Accept all entries except unrestored Glacier objects if the config fs.s3a.glacier.read.restored.objects,
866-
* is set to READ_RESTORED_GLACIER_OBJECTS
867-
* Accept all entries except Glacier objects if the config fs.s3a.glacier.read.restored.objects,
868-
* is set to SKIP_ALL_GLACIER
869-
*/
870-
public static class GlacierStatusAcceptor implements FileStatusAcceptor {
871-
872-
private final S3ObjectStorageClassFilter s3ObjectStorageClassFilter;
873-
874-
875-
public GlacierStatusAcceptor(S3ObjectStorageClassFilter s3ObjectStorageClassFilter) {
876-
this.s3ObjectStorageClassFilter = s3ObjectStorageClassFilter;
877-
}
878-
879-
/**
880-
* Reject a s3Object entry with the Glacier storage class if the config fs.s3a.glacier.read.restored.objects is set to SKIP_ALL_GLACIER
881-
* Reject a s3Object entry with the Glacier storage class if the config fs.s3a.glacier.read.restored.objects is set to READ_RESTORED_GLACIER_OBJECTS
882-
* Accept a s3Object entry with the Glacier storage class if the config fs.s3a.glacier.read.restored.objects is set to READ_RESTORED_GLACIER_OBJECTS and the Glacier file is restored completely
883-
* Reject a s3Object entry with any other storage class
884-
* @param keyPath key path of the entry
885-
* @param s3Object s3Object entry
886-
* @return true if the entry is accepted (i.e. that a status entry
887-
* should be generated.)
888-
*/
889-
@Override
890-
public boolean accept(Path keyPath, S3Object s3Object) {
891-
return s3ObjectStorageClassFilter.getFilter().apply(s3Object);
892-
}
893-
894-
/**
895-
* Accept all prefixes
896-
* @param keyPath qualified path to the entry
897-
* @param prefix common prefix in listing.
898-
* @return true if the entry is accepted (i.e. that a status entry
899-
* should be generated.
900-
*/
901-
@Override
902-
public boolean accept(Path keyPath, String prefix) {
903-
return true;
904-
}
905-
906-
@Override
907-
public boolean accept(FileStatus status) {
908-
return true;
909-
}
910-
911-
}
912-
913862
@SuppressWarnings("unchecked")
914863
public static RemoteIterator<LocatedFileStatus> toLocatedFileStatusIterator(
915864
RemoteIterator<? extends LocatedFileStatus> iterator) {

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
import java.util.concurrent.atomic.AtomicBoolean;
5353
import javax.annotation.Nullable;
5454

55-
import org.apache.hadoop.fs.s3a.Listing.AcceptAllButSelfAndS3nDirs;
56-
import org.apache.hadoop.fs.s3a.Listing.GlacierStatusAcceptor;
5755
import software.amazon.awssdk.core.ResponseInputStream;
5856
import software.amazon.awssdk.core.exception.SdkException;
5957
import software.amazon.awssdk.services.s3.S3AsyncClient;
@@ -147,6 +145,7 @@
147145
import org.apache.hadoop.fs.s3a.impl.StatusProbeEnum;
148146
import org.apache.hadoop.fs.s3a.impl.StoreContext;
149147
import org.apache.hadoop.fs.s3a.impl.StoreContextBuilder;
148+
import org.apache.hadoop.fs.s3a.Listing.AcceptAllButSelfAndS3nDirs;
150149
import org.apache.hadoop.fs.s3a.prefetch.S3APrefetchingInputStream;
151150
import org.apache.hadoop.fs.s3a.tools.MarkerToolOperations;
152151
import org.apache.hadoop.fs.s3a.tools.MarkerToolOperationsImpl;
@@ -586,8 +585,10 @@ public void initialize(URI name, Configuration originalConf)
586585
s3aInternals = createS3AInternals();
587586

588587
s3ObjectStorageClassFilter = Optional.ofNullable(conf.get(READ_RESTORED_GLACIER_OBJECTS))
588+
.map(String::trim)
589+
.map(String::toUpperCase)
589590
.map(S3ObjectStorageClassFilter::valueOf)
590-
.orElse(DEFAULT_READ_RESTORED_GLACIER_OBJECTS);
591+
.orElse(S3ObjectStorageClassFilter.READ_ALL);
591592

592593
// look for encryption data
593594
// DT Bindings may override this
@@ -2484,8 +2485,8 @@ public RemoteIterator<S3ALocatedFileStatus> listFilesAndDirectoryMarkers(
24842485
path,
24852486
true,
24862487
includeSelf
2487-
? Lists.newArrayList(new GlacierStatusAcceptor(s3ObjectStorageClassFilter), Listing.ACCEPT_ALL_BUT_S3N)
2488-
: Lists.newArrayList(new GlacierStatusAcceptor(s3ObjectStorageClassFilter), new AcceptAllButSelfAndS3nDirs(path)),
2488+
? Listing.ACCEPT_ALL_BUT_S3N
2489+
: new AcceptAllButSelfAndS3nDirs(path),
24892490
status
24902491
);
24912492
}
@@ -2533,7 +2534,7 @@ public RemoteIterator<S3AFileStatus> listObjects(
25332534
listing.createFileStatusListingIterator(path,
25342535
createListObjectsRequest(key, null),
25352536
ACCEPT_ALL,
2536-
Lists.newArrayList(new GlacierStatusAcceptor(s3ObjectStorageClassFilter), Listing.ACCEPT_ALL_BUT_S3N),
2537+
Listing.ACCEPT_ALL_BUT_S3N,
25372538
auditSpan));
25382539
}
25392540

@@ -3870,8 +3871,7 @@ public S3AFileStatus probePathStatus(final Path path,
38703871
public RemoteIterator<S3ALocatedFileStatus> listFilesIterator(final Path path,
38713872
final boolean recursive) throws IOException {
38723873
return S3AFileSystem.this.innerListFiles(path, recursive,
3873-
Lists.newArrayList(new GlacierStatusAcceptor(s3ObjectStorageClassFilter),
3874-
Listing.ACCEPT_ALL_BUT_S3N), null);
3874+
Listing.ACCEPT_ALL_BUT_S3N, null);
38753875
}
38763876
}
38773877

@@ -5174,7 +5174,7 @@ public RemoteIterator<LocatedFileStatus> listFiles(Path f,
51745174
return toLocatedFileStatusIterator(
51755175
trackDurationAndSpan(INVOCATION_LIST_FILES, path, () ->
51765176
innerListFiles(path, recursive,
5177-
Lists.newArrayList(new GlacierStatusAcceptor(s3ObjectStorageClassFilter), new Listing.AcceptFilesOnly(path)), null)));
5177+
new Listing.AcceptFilesOnly(path), null)));
51785178
}
51795179

51805180
/**
@@ -5192,7 +5192,7 @@ public RemoteIterator<S3ALocatedFileStatus> listFilesAndEmptyDirectories(
51925192
final Path path = qualify(f);
51935193
return trackDurationAndSpan(INVOCATION_LIST_FILES, path, () ->
51945194
innerListFiles(path, recursive,
5195-
Lists.newArrayList(new GlacierStatusAcceptor(s3ObjectStorageClassFilter), Listing.ACCEPT_ALL_BUT_S3N),
5195+
Listing.ACCEPT_ALL_BUT_S3N,
51965196
null));
51975197
}
51985198

@@ -5207,7 +5207,7 @@ public RemoteIterator<S3ALocatedFileStatus> listFilesAndEmptyDirectories(
52075207
*
52085208
* @param f path
52095209
* @param recursive recursive listing?
5210-
* @param acceptors file status filters
5210+
* @param acceptor file status filters
52115211
* @param status optional status of path to list.
52125212
* @return an iterator over the listing.
52135213
* @throws IOException failure
@@ -5216,7 +5216,7 @@ public RemoteIterator<S3ALocatedFileStatus> listFilesAndEmptyDirectories(
52165216
private RemoteIterator<S3ALocatedFileStatus> innerListFiles(
52175217
final Path f,
52185218
final boolean recursive,
5219-
final List<Listing.FileStatusAcceptor> acceptors,
5219+
final Listing.FileStatusAcceptor acceptor,
52205220
final S3AFileStatus status) throws IOException {
52215221
Path path = qualify(f);
52225222
LOG.debug("listFiles({}, {})", path, recursive);
@@ -5233,8 +5233,8 @@ private RemoteIterator<S3ALocatedFileStatus> innerListFiles(
52335233
RemoteIterator<S3ALocatedFileStatus> listFilesAssumingDir =
52345234
listing.getListFilesAssumingDir(path,
52355235
recursive,
5236-
acceptors,
5237-
getActiveAuditSpan());
5236+
acceptor,
5237+
getActiveAuditSpan());
52385238
// If there are no list entries present, we
52395239
// fallback to file existence check as the path
52405240
// can be a file or empty directory.

0 commit comments

Comments
 (0)