-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Detect and close I/O leaks in the native FS implementations #26087
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
177 changes: 177 additions & 0 deletions
177
lib/trino-filesystem/src/main/java/io/trino/filesystem/tracking/TrackingFileSystem.java
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 |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| /* | ||
| * Licensed 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 io.trino.filesystem.tracking; | ||
|
|
||
| import io.airlift.units.Duration; | ||
| import io.trino.filesystem.FileIterator; | ||
| import io.trino.filesystem.Location; | ||
| import io.trino.filesystem.TrinoFileSystem; | ||
| import io.trino.filesystem.TrinoInputFile; | ||
| import io.trino.filesystem.TrinoOutputFile; | ||
| import io.trino.filesystem.UriLocation; | ||
| import io.trino.filesystem.encryption.EncryptionKey; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.ref.Cleaner; | ||
| import java.time.Instant; | ||
| import java.util.Collection; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class TrackingFileSystem | ||
| implements TrinoFileSystem | ||
| { | ||
| private final TrinoFileSystem delegate; | ||
| private final Cleaner cleaner; | ||
|
|
||
| public TrackingFileSystem(TrinoFileSystem delegate, Cleaner cleaner) | ||
| { | ||
| this.delegate = requireNonNull(delegate, "delegate is null"); | ||
| this.cleaner = requireNonNull(cleaner, "cleaner is null"); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoInputFile newInputFile(Location location) | ||
| { | ||
| return new TrackingInputFile(delegate.newInputFile(location), cleaner); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoInputFile newInputFile(Location location, long length) | ||
| { | ||
| return new TrackingInputFile(delegate.newInputFile(location, length), cleaner); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoInputFile newInputFile(Location location, long length, Instant lastModified) | ||
| { | ||
| return new TrackingInputFile(delegate.newInputFile(location, length, lastModified), cleaner); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoOutputFile newOutputFile(Location location) | ||
| { | ||
| return new TrackingOutputFile(delegate.newOutputFile(location), cleaner); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteFile(Location location) | ||
| throws IOException | ||
| { | ||
| delegate.deleteFile(location); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteDirectory(Location location) | ||
| throws IOException | ||
| { | ||
| delegate.deleteDirectory(location); | ||
| } | ||
|
|
||
| @Override | ||
| public void renameFile(Location source, Location target) | ||
| throws IOException | ||
| { | ||
| delegate.renameFile(source, target); | ||
| } | ||
|
|
||
| @Override | ||
| public FileIterator listFiles(Location location) | ||
| throws IOException | ||
| { | ||
| return delegate.listFiles(location); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Boolean> directoryExists(Location location) | ||
| throws IOException | ||
| { | ||
| return delegate.directoryExists(location); | ||
| } | ||
|
|
||
| @Override | ||
| public void createDirectory(Location location) | ||
| throws IOException | ||
| { | ||
| delegate.createDirectory(location); | ||
| } | ||
|
|
||
| @Override | ||
| public void renameDirectory(Location source, Location target) | ||
| throws IOException | ||
| { | ||
| delegate.renameDirectory(source, target); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<Location> listDirectories(Location location) | ||
| throws IOException | ||
| { | ||
| return delegate.listDirectories(location); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Location> createTemporaryDirectory(Location targetPath, String temporaryPrefix, String relativePrefix) | ||
| throws IOException | ||
| { | ||
| return delegate.createTemporaryDirectory(targetPath, temporaryPrefix, relativePrefix); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoInputFile newEncryptedInputFile(Location location, EncryptionKey key) | ||
| { | ||
| return new TrackingInputFile(delegate.newEncryptedInputFile(location, key), cleaner); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoInputFile newEncryptedInputFile(Location location, long length, EncryptionKey key) | ||
| { | ||
| return new TrackingInputFile(delegate.newEncryptedInputFile(location, length, key), cleaner); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoInputFile newEncryptedInputFile(Location location, long length, Instant lastModified, EncryptionKey key) | ||
| { | ||
| return new TrackingInputFile(delegate.newEncryptedInputFile(location, length, lastModified, key), cleaner); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoOutputFile newEncryptedOutputFile(Location location, EncryptionKey key) | ||
| { | ||
| return new TrackingOutputFile(delegate.newEncryptedOutputFile(location, key), cleaner); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteFiles(Collection<Location> locations) | ||
| throws IOException | ||
| { | ||
| delegate.deleteFiles(locations); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<UriLocation> preSignedUri(Location location, Duration ttl) | ||
| throws IOException | ||
| { | ||
| return delegate.preSignedUri(location, ttl); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<UriLocation> encryptedPreSignedUri(Location location, Duration ttl, EncryptionKey key) | ||
| throws IOException | ||
| { | ||
| return delegate.encryptedPreSignedUri(location, ttl, key); | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
...rino-filesystem/src/main/java/io/trino/filesystem/tracking/TrackingFileSystemFactory.java
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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Licensed 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 io.trino.filesystem.tracking; | ||
|
|
||
| import io.trino.filesystem.TrinoFileSystem; | ||
| import io.trino.filesystem.TrinoFileSystemFactory; | ||
| import io.trino.spi.connector.ConnectorSession; | ||
| import io.trino.spi.security.ConnectorIdentity; | ||
|
|
||
| import java.lang.ref.Cleaner; | ||
|
|
||
| import static io.airlift.concurrent.Threads.daemonThreadsNamed; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class TrackingFileSystemFactory | ||
| implements TrinoFileSystemFactory | ||
| { | ||
| private final TrinoFileSystemFactory delegate; | ||
|
|
||
| public TrackingFileSystemFactory(TrinoFileSystemFactory delegate) | ||
| { | ||
| this.delegate = requireNonNull(delegate, "delegate is null"); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoFileSystem create(ConnectorIdentity identity) | ||
| { | ||
| return new TrackingFileSystem(delegate.create(identity), createCleaner()); | ||
| } | ||
|
|
||
| @Override | ||
| public TrinoFileSystem create(ConnectorSession session) | ||
| { | ||
| return new TrackingFileSystem(delegate.create(session), createCleaner()); | ||
| } | ||
|
|
||
| private static Cleaner createCleaner() | ||
| { | ||
| return Cleaner.create(daemonThreadsNamed("fs-leak-detector-%s")); | ||
| } | ||
| } |
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.
You can make this the default for the config, allowing it to be overridden in either case.
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.
Will follow up