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

fix potential fd leakage for SegmentProcessorFramework #9797

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,31 @@ public List<File> process()
for (Map.Entry<String, GenericRowFileManager> entry : partitionToFileManagerMap.entrySet()) {
String partitionId = entry.getKey();
GenericRowFileManager fileManager = entry.getValue();
GenericRowFileReader fileReader = fileManager.getFileReader();
int numRows = fileReader.getNumRows();
int numSortFields = fileReader.getNumSortFields();
LOGGER.info("Start creating segments on partition: {}, numRows: {}, numSortFields: {}", partitionId, numRows,
numSortFields);
GenericRowFileRecordReader recordReader = fileReader.getRecordReader();
for (int startRowId = 0; startRowId < numRows; startRowId += maxNumRecordsPerSegment, sequenceId++) {
int endRowId = Math.min(startRowId + maxNumRecordsPerSegment, numRows);
LOGGER.info("Start creating segment of sequenceId: {} with row range: {} to {}", sequenceId, startRowId,
endRowId);
observer.accept(String.format(
"Creating segment of sequentId: %d with data from partition: %s and row range: [%d, %d) out of [0, %d)",
sequenceId, partitionId, startRowId, endRowId, numRows));
generatorConfig.setSequenceId(sequenceId);
GenericRowFileRecordReader recordReaderForRange = recordReader.getRecordReaderForRange(startRowId, endRowId);
SegmentIndexCreationDriverImpl driver = new SegmentIndexCreationDriverImpl();
driver.init(generatorConfig, new RecordReaderSegmentCreationDataSource(recordReaderForRange),
TransformPipeline.getPassThroughPipeline());
driver.build();
outputSegmentDirs.add(driver.getOutputDirectory());
try {
GenericRowFileReader fileReader = fileManager.getFileReader();
int numRows = fileReader.getNumRows();
int numSortFields = fileReader.getNumSortFields();
LOGGER.info("Start creating segments on partition: {}, numRows: {}, numSortFields: {}", partitionId, numRows,
numSortFields);
GenericRowFileRecordReader recordReader = fileReader.getRecordReader();
for (int startRowId = 0; startRowId < numRows; startRowId += maxNumRecordsPerSegment, sequenceId++) {
int endRowId = Math.min(startRowId + maxNumRecordsPerSegment, numRows);
LOGGER.info("Start creating segment of sequenceId: {} with row range: {} to {}", sequenceId, startRowId,
endRowId);
observer.accept(String.format(
"Creating segment of sequentId: %d with data from partition: %s and row range: [%d, %d) out of [0, %d)",
sequenceId, partitionId, startRowId, endRowId, numRows));
generatorConfig.setSequenceId(sequenceId);
GenericRowFileRecordReader recordReaderForRange = recordReader.getRecordReaderForRange(startRowId, endRowId);
SegmentIndexCreationDriverImpl driver = new SegmentIndexCreationDriverImpl();
driver.init(generatorConfig, new RecordReaderSegmentCreationDataSource(recordReaderForRange),
TransformPipeline.getPassThroughPipeline());
driver.build();
outputSegmentDirs.add(driver.getOutputDirectory());
}
} finally {
fileManager.cleanUp();
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like we can assert _mapperOutputDir is cleaned in SegmentProcessorFramework before calling FileUtils.cleanDirectory(workingDir);?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_mapperOutputDir and _reducerOutputDir are internal to this framework, so the caller can't check their existence. And when the issue happened, the files were deleted (file names were gone from the file system). But as it's still opened by the process via mmap, so the file (inode, disk space) was not released cleanly.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 ok

}
fileManager.cleanUp();
}
FileUtils.deleteDirectory(_mapperOutputDir);
FileUtils.deleteDirectory(_reducerOutputDir);
Expand Down