-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Move deleted files to Hadoop trash if configured #14501
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
Merged
Merged
Changes from all commits
Commits
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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -28,8 +28,11 @@ | |
| import java.util.function.Function; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.LocalFileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.fs.RemoteIterator; | ||
| import org.apache.hadoop.fs.Trash; | ||
| import org.apache.hadoop.hdfs.DistributedFileSystem; | ||
| import org.apache.iceberg.exceptions.RuntimeIOException; | ||
| import org.apache.iceberg.io.BulkDeletionFailureException; | ||
| import org.apache.iceberg.io.DelegateFileIO; | ||
|
|
@@ -102,7 +105,7 @@ public void deleteFile(String path) { | |
| Path toDelete = new Path(path); | ||
| FileSystem fs = Util.getFs(toDelete, getConf()); | ||
| try { | ||
| fs.delete(toDelete, false /* not recursive */); | ||
| deletePath(fs, toDelete, false); | ||
| } catch (IOException e) { | ||
| throw new RuntimeIOException(e, "Failed to delete file: %s", path); | ||
| } | ||
|
|
@@ -167,7 +170,7 @@ public void deletePrefix(String prefix) { | |
| FileSystem fs = Util.getFs(prefixToDelete, getConf()); | ||
|
|
||
| try { | ||
| fs.delete(prefixToDelete, true /* recursive */); | ||
| deletePath(fs, prefixToDelete, true); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
|
|
@@ -211,6 +214,16 @@ private ExecutorService executorService() { | |
| return executorService; | ||
| } | ||
|
|
||
| private void deletePath(FileSystem fs, Path toDelete, boolean recursive) throws IOException { | ||
| Trash trash = new Trash(fs, getConf()); | ||
| if ((fs instanceof LocalFileSystem || fs instanceof DistributedFileSystem) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
| && trash.isEnabled()) { | ||
| trash.moveToTrash(toDelete); | ||
| } else { | ||
| fs.delete(toDelete, recursive); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This class is a simple adaptor to allow for using Hadoop's RemoteIterator as an Iterator. | ||
| * | ||
|
|
||
This file contains hidden or 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
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.
I'm concerned about number of Trash objects we create. Does Hadoop API ensure we can reuse the trash object for a given (fs, conf)?
I couldn't tell from https://hadoop.apache.org/docs/stable/api/org/apache/hadoop/fs/Trash.html#Trash-org.apache.hadoop.fs.FileSystem-org.apache.hadoop.conf.Configuration-
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's a good call. I've added a new toggle that can be put in the hadoop configuration to determine if we want to use the trash for iceberg, following Russel Spitzer's example in other HadoopFileIO changes.
I've taken a look regarding object reuse. The trash can change due to lots of changes in configuration (meaning I'd have to create a cache based on 5+ configuration values which are susceptible to change in the future), unlike the file system (Key doesn't actually rely on conf, just relies on the URI and user group information). With that being said, the change that I made to check for hadoop configuration first makes it so that we don't create the Trash object unless specifically opted into. I hope that this is good enough for now - an iceberg user will now have to opt into this change to experience any possible object churn.