Skip to content
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

Adds check if controller tmp dir exists #14503

Merged
merged 15 commits into from
Nov 30, 2024
Merged

Conversation

Harnoor7
Copy link
Contributor

@Harnoor7 Harnoor7 commented Nov 20, 2024

Problem: Have observed rare exception: java.io.FileNotFoundException: /tmp/pinot-controller-tmp/fileUploadTemp/tmp-<id> (No such file or directory). Assumption is that OS might have deleted older file under tmp directory and hence deleted controllder tmp dir files.

Solution: Add validation to ensure the temp dirs are present whenever they are accessed. If absent then pinot should create them.
solution is based on : https://howtodoinjava.com/java/io/create-directories/#2-1-files-createdirectory

@Harnoor7 Harnoor7 marked this pull request as ready for review November 24, 2024 15:44
@Harnoor7 Harnoor7 changed the title [WIP] Adds check if controller tmp dir exists Adds check if controller tmp dir exists Nov 24, 2024
Copy link
Collaborator

@shounakmk219 shounakmk219 left a comment

Choose a reason for hiding this comment

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

Overall looks good, few minor suggestions.

@@ -126,14 +128,38 @@ public URI getDataDirURI() {
}

public File getFileUploadTempDir() {
if (!Files.exists(_fileUploadTempDir.toPath())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Extract this logic into a method to avoid replicating it.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, create a method ensureUploadTempDirExists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added method to FileUtils.

private static final String PORT = "12345";
private static final File DATA_DIR =
new File(FileUtils.getTempDirectory(), "PinotSegmentUploadDownloadRestletResourceTest");
private static final File LOCAL_TEMP_DIR = new File(DATA_DIR, "localTemp");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete these directories in tearDown() or see if you can use _tempDir itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added logic in teardown

_tempDir = new File(FileUtils.getTempDirectory(), "test-" + UUID.randomUUID());
FileUtils.forceMkdir(_tempDir);
}

@AfterMethod
public void tearDown() throws IOException {
public void tearDown()
throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: revert the formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -158,7 +175,8 @@ public void testEncryptSegmentIfNeededNoEncryption() {
}

@Test
public void testCreateSegmentFileFromBodyPart() throws IOException {
public void testCreateSegmentFileFromBodyPart()
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: revert the formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -249,4 +267,58 @@ public void testValidateMultiPartForBatchSegmentUpload() {
// validate – should not throw exception
PinotSegmentUploadDownloadRestletResource.validateMultiPartForBatchSegmentUpload(bodyParts);
}

@Test
public void testUploadSegmentWithMissingTmpDir()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see this test adding anymore value than the one created in ControllerFilePathProviderTest , maybe you can add an integration test in SegmentUploadIntegrationTest to validate the segment upload flow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

name of this test method was wrong have corrected it. This method was the one from where we received a runtime exception. Hence covering this method specifically.

@xiangfu0
Copy link
Contributor

I suppose this error only occurs in tests not production right?

@codecov-commenter
Copy link

codecov-commenter commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Project coverage is 63.92%. Comparing base (59551e4) to head (b75d029).
Report is 1403 commits behind head on master.

Files with missing lines Patch % Lines
.../java/org/apache/pinot/common/utils/FileUtils.java 66.66% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14503      +/-   ##
============================================
+ Coverage     61.75%   63.92%   +2.17%     
- Complexity      207     1570    +1363     
============================================
  Files          2436     2681     +245     
  Lines        133233   147089   +13856     
  Branches      20636    22568    +1932     
============================================
+ Hits          82274    94025   +11751     
- Misses        44911    46131    +1220     
- Partials       6048     6933     +885     
Flag Coverage Δ
custom-integration1 100.00% <ø> (+99.99%) ⬆️
integration 100.00% <ø> (+99.99%) ⬆️
integration1 100.00% <ø> (+99.99%) ⬆️
integration2 0.00% <ø> (ø)
java-11 63.90% <77.77%> (+2.19%) ⬆️
java-21 63.81% <77.77%> (+2.19%) ⬆️
skip-bytebuffers-false 63.92% <77.77%> (+2.17%) ⬆️
skip-bytebuffers-true 63.78% <77.77%> (+36.06%) ⬆️
temurin 63.92% <77.77%> (+2.17%) ⬆️
unittests 63.91% <77.77%> (+2.17%) ⬆️
unittests1 55.65% <0.00%> (+8.76%) ⬆️
unittests2 34.53% <77.77%> (+6.80%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Harnoor7
Copy link
Contributor Author

I suppose this error only occurs in tests not production right?

We faced this issue on production

Copy link
Collaborator

@shounakmk219 shounakmk219 left a comment

Choose a reason for hiding this comment

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

LGTM, just one minor change.

@@ -126,14 +126,17 @@ public URI getDataDirURI() {
}

public File getFileUploadTempDir() {
org.apache.pinot.common.utils.FileUtils.createDirIfNotExists(_fileUploadTempDir.toPath());
Copy link
Collaborator

Choose a reason for hiding this comment

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

please import FileUtils itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

apache.commons.io.FileUtils is already present

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh sorry my bad!

@@ -134,4 +136,15 @@ public static File concatAndValidateFile(File folderDir, String filename, String

return filePath;
}

public static void createDirIfNotExists(Path path)
Copy link
Contributor

Choose a reason for hiding this comment

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

call it ensureDirectoryExists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@xiangfu0 xiangfu0 left a comment

Choose a reason for hiding this comment

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

lgtm otherwise

@xiangfu0 xiangfu0 merged commit afd4c95 into apache:master Nov 30, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants