-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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.
Overall looks good, few minor suggestions.
@@ -126,14 +128,38 @@ public URI getDataDirURI() { | |||
} | |||
|
|||
public File getFileUploadTempDir() { | |||
if (!Files.exists(_fileUploadTempDir.toPath())) { |
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.
Extract this logic into a method to avoid replicating it.
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.
+1, create a method ensureUploadTempDirExists
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.
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"); |
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.
Delete these directories in tearDown()
or see if you can use _tempDir
itself
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.
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 { |
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.
nit: revert the formatting
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.
done
@@ -158,7 +175,8 @@ public void testEncryptSegmentIfNeededNoEncryption() { | |||
} | |||
|
|||
@Test | |||
public void testCreateSegmentFileFromBodyPart() throws IOException { | |||
public void testCreateSegmentFileFromBodyPart() |
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.
nit: revert the formatting
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.
done
@@ -249,4 +267,58 @@ public void testValidateMultiPartForBatchSegmentUpload() { | |||
// validate – should not throw exception | |||
PinotSegmentUploadDownloadRestletResource.validateMultiPartForBatchSegmentUpload(bodyParts); | |||
} | |||
|
|||
@Test | |||
public void testUploadSegmentWithMissingTmpDir() |
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 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?
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.
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.
I suppose this error only occurs in tests not production right? |
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
We faced this issue on production |
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.
LGTM, just one minor change.
@@ -126,14 +126,17 @@ public URI getDataDirURI() { | |||
} | |||
|
|||
public File getFileUploadTempDir() { | |||
org.apache.pinot.common.utils.FileUtils.createDirIfNotExists(_fileUploadTempDir.toPath()); |
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.
please import FileUtils
itself
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.
apache.commons.io.FileUtils
is already present
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.
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) |
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.
call it ensureDirectoryExists
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.
done
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.
lgtm otherwise
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