Skip to content

HDDS-15623. Disk check may not completely read test file#10552

Open
adoroszlai wants to merge 3 commits into
apache:masterfrom
adoroszlai:HDDS-15623
Open

HDDS-15623. Disk check may not completely read test file#10552
adoroszlai wants to merge 3 commits into
apache:masterfrom
adoroszlai:HDDS-15623

Conversation

@adoroszlai

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

  1. Disk read/write check may not completely read the test file with InputStream.read().
    // Read data back from the test file.
    byte[] readBytes = new byte[numBytesToWrite];
    try (InputStream fis = Files.newInputStream(testFile.toPath())) {
    int numBytesRead = fis.read(readBytes);
    if (numBytesRead != numBytesToWrite) {
    logError(storageDir, String.format("%d bytes written to file %s " +
    "but %d bytes were read back.", numBytesToWrite,
    testFile.getAbsolutePath(), numBytesRead));
    return false;

    Use IOUtils.read to fully read the input.
  2. Delete the test file even if the check fails for any reason.
  3. Convert File.toPath once.

https://issues.apache.org/jira/browse/HDDS-15623

How was this patch tested?

Updated unit test.

CI:
https://github.com/adoroszlai/ozone/actions/runs/27831059411

@ashishkumar50 ashishkumar50 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adoroszlai Thanks for the patch.

} catch (FileNotFoundException | NoSuchFileException notFoundEx) {
logError(storageDir, String.format("Could not find file %s " +
"for volume check.", testFile.getAbsolutePath()), notFoundEx);
FileUtils.deletePathQuietly(testPath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to delete in finally, instead in each catch exception.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is deleted as part of the check in normal case:

// Delete the file.
if (!testFile.delete()) {
logError(storageDir, String.format("Could not delete file %s " +
"for volume check.", testFile.getAbsolutePath()));
return false;
}
// If all checks passed, the volume is healthy.
return true;

So we cannot delete in finally of read check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, in normal scenario delete is verified.

@ashishkumar50 ashishkumar50 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adoroszlai thanks for the clarification, patch LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants