-
Notifications
You must be signed in to change notification settings - Fork 593
HDDS-14370. RandomAccessFileChannel to implement Closeable #9628
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
base: master
Are you sure you want to change the base?
Conversation
Gargi-jais11
left a comment
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.
Thanks @rich7420 for the patch.
Please see the inline comment.
| @Override | ||
| public synchronized void close() { | ||
| if (blockFile == null) { | ||
| return; | ||
| } | ||
| blockFile = null; | ||
| try { |
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.
This is not related to your changes but I found a bug over here.
Here, blockFile is set to null before it was used in the catch blocks
for error logging. This would cause log messages to show null instead of the actual file path when closing fails making debugging difficult.
Solution: Save the file reference so that error messages can properly display the file path.
public synchronized void close() {
if (blockFile == null) {
return;
}
final File fileToClose = blockFile;
blockFile = null;
try {
channel.close();
channel = null;
} catch (IOException e) {
LOG.warn("Failed to close channel for {}", fileToClose, e);
}
try {
raf.close();
raf = null;
} catch (IOException e) {
LOG.warn("Failed to close RandomAccessFile for {}", fileToClose, e);
}
}
}
jojochuang
left a comment
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.
Better to have a test file for this class: TestRandomAccessFileChannel
|
Below the few test cases suggestion which I could think as of now:
It would be great @rich7420 if you come up with some more critical tests. |
|
got it! thanks for the review @jojochuang , @Gargi-jais11 ! |
What changes were proposed in this pull request?
The class already had a close() method but didn't implement Closeable, which could lead to resource leaks if developers miss calling close().
What is the link to the Apache JIRA
HDDS-14370
How was this patch tested?
https://github.com/rich7420/ozone/actions/runs/20941407661