-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HADOOP-18679. Add API for bulk/paged delete of files #6726
Merged
steveloughran
merged 19 commits into
apache:trunk
from
mukund-thakur:bulk-delete-mukund-HADOOP-18679
May 20, 2024
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
507d7c6
HADOOP-18679. Add API for bulk/paged object deletion
steveloughran fbef70b
HADOOP-18679. Bulk Delete: utility methods
steveloughran 910dd76
HADOOP-18679. ?: values the wrong way round
steveloughran 07df662
HADOOP-18679. Bulk Delete: initial S3AStore interface/impl
steveloughran ec5625c
HADOOP-18679. Bulk Delete getting the API simpler
steveloughran a61f139
Adding some contract tests. This will evolve.
mukund-thakur 8ef09f7
HADOOP-18679. My changes based on iceberg PoC
steveloughran 9ad220b
Refactoring and review comments and adding more tests
mukund-thakur 7415427
Adding default impl for bulk delete for other file systems
mukund-thakur 27b16f9
review comments
mukund-thakur 86544f2
add path capability
mukund-thakur 88c8623
Some more tests and docs
mukund-thakur 0339eeb
self review comments
mukund-thakur 0776025
checkstyle
mukund-thakur 01b2ae8
some more fixes
mukund-thakur 89e87d4
review comments
mukund-thakur 058d099
BulkDeleteSource to be implemented by base FileSystem
mukund-thakur e37d88f
Removing default impl from BulkDeleteSource
mukund-thakur b80a8e6
doc fixes and reflection friendly api names
mukund-thakur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDelete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.fs; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience; | ||
import org.apache.hadoop.classification.InterfaceStability; | ||
import org.apache.hadoop.fs.statistics.IOStatisticsSource; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* API for bulk deletion of objects/files, | ||
* <i>but not directories</i>. | ||
* After use, call {@code close()} to release any resources and | ||
* to guarantee store IOStatistics are updated. | ||
* <p> | ||
* Callers MUST have no expectation that parent directories will exist after the | ||
* operation completes; if an object store needs to explicitly look for and create | ||
* directory markers, that step will be omitted. | ||
* <p> | ||
* Be aware that on some stores (AWS S3) each object listed in a bulk delete counts | ||
* against the write IOPS limit; large page sizes are counterproductive here, as | ||
* are attempts at parallel submissions across multiple threads. | ||
* @see <a href="https://issues.apache.org/jira/browse/HADOOP-16823">HADOOP-16823. | ||
* Large DeleteObject requests are their own Thundering Herd</a> | ||
*/ | ||
@InterfaceAudience.Public | ||
@InterfaceStability.Unstable | ||
public interface BulkDelete extends IOStatisticsSource, Closeable { | ||
|
||
/** | ||
* The maximum number of objects/files to delete in a single request. | ||
* @return a number greater than zero. | ||
*/ | ||
int pageSize(); | ||
|
||
/** | ||
* Base path of a bulk delete operation. | ||
* All paths submitted in {@link #bulkDelete(Collection)} must be under this path. | ||
* @return base path of a bulk delete operation. | ||
*/ | ||
Path basePath(); | ||
|
||
/** | ||
* Delete a list of files/objects. | ||
* <ul> | ||
* <li>Files must be under the path provided in {@link #basePath()}.</li> | ||
* <li>The size of the list must be equal to or less than the page size | ||
* declared in {@link #pageSize()}.</li> | ||
* <li>Directories are not supported; the outcome of attempting to delete | ||
* directories is undefined (ignored; undetected, listed as failures...).</li> | ||
* <li>The operation is not atomic.</li> | ||
* <li>The operation is treated as idempotent: network failures may | ||
* trigger resubmission of the request -any new objects created under a | ||
* path in the list may then be deleted.</li> | ||
* <li>There is no guarantee that any parent directories exist after this call. | ||
* </li> | ||
* </ul> | ||
* @param paths list of paths which must be absolute and under the base path. | ||
* provided in {@link #basePath()}. | ||
* @return a list of paths which failed to delete, with the exception message. | ||
* @throws IOException IO problems including networking, authentication and more. | ||
* @throws IllegalArgumentException if a path argument is invalid. | ||
*/ | ||
List<Map.Entry<Path, String>> bulkDelete(Collection<Path> paths) | ||
throws IOException, IllegalArgumentException; | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.fs; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience; | ||
import org.apache.hadoop.classification.InterfaceStability; | ||
|
||
/** | ||
* Interface for bulk deletion. | ||
* Filesystems which support bulk deletion should implement this interface | ||
* and MUST also declare their support in the path capability | ||
* {@link CommonPathCapabilities#BULK_DELETE}. | ||
* Exporting the interface does not guarantee that the operation is supported; | ||
* returning a {@link BulkDelete} object from the call {@link #createBulkDelete(Path)} | ||
* is. | ||
*/ | ||
@InterfaceAudience.Public | ||
@InterfaceStability.Unstable | ||
public interface BulkDeleteSource { | ||
mukund-thakur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Create a bulk delete operation. | ||
* There is no network IO at this point, simply the creation of | ||
* a bulk delete object. | ||
* A path must be supplied to assist in link resolution. | ||
* @param path path to delete under. | ||
* @return the bulk delete. | ||
* @throws UnsupportedOperationException bulk delete under that path is not supported. | ||
* @throws IllegalArgumentException path not valid. | ||
* @throws IOException problems resolving paths | ||
*/ | ||
BulkDelete createBulkDelete(Path path) | ||
throws UnsupportedOperationException, IllegalArgumentException, IOException; | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.fs; | ||
|
||
import java.util.Collection; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.apache.hadoop.util.Preconditions.checkArgument; | ||
|
||
/** | ||
* Utility class for bulk delete operations. | ||
*/ | ||
public final class BulkDeleteUtils { | ||
mukund-thakur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private BulkDeleteUtils() { | ||
} | ||
|
||
/** | ||
* Preconditions for bulk delete paths. | ||
* @param paths paths to delete. | ||
* @param pageSize maximum number of paths to delete in a single operation. | ||
* @param basePath base path for the delete operation. | ||
*/ | ||
public static void validateBulkDeletePaths(Collection<Path> paths, int pageSize, Path basePath) { | ||
requireNonNull(paths); | ||
checkArgument(paths.size() <= pageSize, | ||
"Number of paths (%d) is larger than the page size (%d)", paths.size(), pageSize); | ||
paths.forEach(p -> { | ||
checkArgument(p.isAbsolute(), "Path %s is not absolute", p); | ||
checkArgument(validatePathIsUnderParent(p, basePath), | ||
"Path %s is not under the base path %s", p, basePath); | ||
}); | ||
} | ||
|
||
/** | ||
* Check if a path is under a base path. | ||
* @param p path to check. | ||
* @param basePath base path. | ||
* @return true if the path is under the base path. | ||
*/ | ||
public static boolean validatePathIsUnderParent(Path p, Path basePath) { | ||
while (p.getParent() != null) { | ||
if (p.getParent().equals(basePath)) { | ||
return true; | ||
} | ||
p = p.getParent(); | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...ect/hadoop-common/src/main/java/org/apache/hadoop/fs/impl/DefaultBulkDeleteOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.fs.impl; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.hadoop.fs.BulkDelete; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.util.functional.Tuples; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.apache.hadoop.fs.BulkDeleteUtils.validateBulkDeletePaths; | ||
|
||
/** | ||
* Default implementation of the {@link BulkDelete} interface. | ||
*/ | ||
public class DefaultBulkDeleteOperation implements BulkDelete { | ||
|
||
private static Logger LOG = LoggerFactory.getLogger(DefaultBulkDeleteOperation.class); | ||
|
||
/** Default page size for bulk delete. */ | ||
private static final int DEFAULT_PAGE_SIZE = 1; | ||
|
||
/** Base path for the bulk delete operation. */ | ||
private final Path basePath; | ||
|
||
/** Delegate File system make actual delete calls. */ | ||
private final FileSystem fs; | ||
|
||
public DefaultBulkDeleteOperation(Path basePath, | ||
FileSystem fs) { | ||
this.basePath = requireNonNull(basePath); | ||
this.fs = fs; | ||
} | ||
|
||
@Override | ||
public int pageSize() { | ||
return DEFAULT_PAGE_SIZE; | ||
} | ||
|
||
@Override | ||
public Path basePath() { | ||
return basePath; | ||
} | ||
|
||
/** | ||
* {@inheritDoc}. | ||
* The default impl just calls {@code FileSystem.delete(path, false)} | ||
* on the single path in the list. | ||
*/ | ||
@Override | ||
public List<Map.Entry<Path, String>> bulkDelete(Collection<Path> paths) | ||
throws IOException, IllegalArgumentException { | ||
validateBulkDeletePaths(paths, DEFAULT_PAGE_SIZE, basePath); | ||
List<Map.Entry<Path, String>> result = new ArrayList<>(); | ||
if (!paths.isEmpty()) { | ||
// As the page size is always 1, this should be the only one | ||
// path in the collection. | ||
Path pathToDelete = paths.iterator().next(); | ||
try { | ||
fs.delete(pathToDelete, false); | ||
} catch (IOException ex) { | ||
LOG.debug("Couldn't delete {} - exception occurred: {}", pathToDelete, ex); | ||
result.add(Tuples.pair(pathToDelete, ex.toString())); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
|
||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is great that we call this out, but can we do better at the API level?
Had the API took
Collection<FileStatus>
, we could make the operation idempotent in most clouds by passing the version/generationid/etag in the request.