-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-28025][SS] Fix FileContextBasedCheckpointFileManager leaking crc files #25488
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
Conversation
// This check also tests for regressions of SPARK-17475 | ||
val allFiles = new File(metadataLog.metadataPath.toString).listFiles() | ||
.filter(!_.getName.startsWith(".")).toSeq |
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 filter broke the check of regression on SPARK-17475, hence regression came in.
val allFiles = new File(metadataLog.metadataPath.toString).listFiles().toSeq | ||
assert(allFiles.size <= 2) | ||
assert(allFiles.exists(_.getName == "2")) | ||
if (allFiles.size == 2) { |
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.
FileSystemBasedCheckpointFileManager is the case of crc file being left: it's not a leak because the origin file exists. It correctly deletes crc file when origin file is requested to be deleted, hence crc files for 0 and 1 don't exist.
cc. @zsxwing @gaborgsomogyi |
@@ -327,12 +327,14 @@ class FileContextBasedCheckpointFileManager(path: Path, hadoopConf: Configuratio | |||
override def renameTempFile(srcPath: Path, dstPath: Path, overwriteIfPossible: Boolean): Unit = { | |||
import Options.Rename._ | |||
fc.rename(srcPath, dstPath, if (overwriteIfPossible) OVERWRITE else NONE) | |||
mayRemoveCrcFile(srcPath) |
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.
The ideal behavior would be renaming crc file to be matched with dstPath, but in SPARK-17475 seems like we just decided to remove the crc file, so I guess this is OK.
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.
Is it possible to detect whether checksum is enabled? If it's disabled, we can save an exists
call.
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.
NVM. Just saw your latest 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.
Yeah, please feel free to let me know if we prefer alternative approach - I can make a change.
I remember this Hadoop issue but forget the ticket. Do you find the Hadoop ticket for this? Has it been fixed in newer Hadoop version? |
I haven't found Hadoop ticket for this, but if my understanding of SPARK-17475 is correct, SPARK-17475 was needed because rename/delete on Hadoop API didn't care of checksum file, which seems to be resolved as the fix is not needed for FileSystemBasedCheckpointFileManager to pass the modified test. |
And I'm not 100% sure of intention, but if we intended to disable crc via below line, it doesn't seem to work:
@skonto already analyzed relevant part but didn't figure out any Hadoop JIRA issue: |
Test build #109302 has finished for PR 25488 at commit
|
As the issue only occurs from temp file, another possible approach would be removing crc file for temp file when FSOutputSummer is being used as OutputStream:
adding above block after As the annotations of the class describe, |
e27baa9
to
c30b045
Compare
Test build #109365 has finished for PR 25488 at commit
|
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 look goods. Just some minor comments.
@HeartSaVioR could you create an upstream HDFS ticket for this ChecksumFs issue? It would be great that the upstream can fix this so that we can remove this hack in future.
} | ||
|
||
|
||
override def delete(path: Path): Unit = { | ||
try { | ||
fc.delete(path, true) | ||
mayRemoveCrcFile(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.
Looks like org.apache.hadoop.fs.ChecksumFs.delete handles the file deletion correctly, so we don't need this change.
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.
Ah, thanks for pointing out.
I just realized I analyzed incorrectly. I confused classes in stack trace hence confused the root reason of bug. I thought FileContext doesn't seem to pick LocalFs (extends ChecksumFs), but turned out that's not the case. The root reason is, there're two renameInternal
methods:
public void renameInternal(Path src, Path dst)
public void renameInternal(final Path src, final Path dst, boolean overwrite)
which should be overridden to handle all cases but ChecksumFs only overrides method with 2 params, so when latter is called FilterFs.renameInternal(...) is called instead, and it will do rename with RawLocalFs
as underlying filesystem.
I'll update the description of PR and remove this line.
@@ -343,5 +345,17 @@ class FileContextBasedCheckpointFileManager(path: Path, hadoopConf: Configuratio | |||
case _: LocalFs | _: RawLocalFs => true // LocalFs = RawLocalFs + ChecksumFs | |||
case _ => false | |||
} | |||
|
|||
private def mayRemoveCrcFile(path: Path): Unit = { | |||
val checksumFile = new Path(path.getParent, s".${path.getName}.crc") |
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 just found one bug in this Path API: https://issues.apache.org/jira/browse/HDFS-14762
How about wrap the whole block like this
try {
val checksumFile = new Path(path.getParent, s".${path.getName}.crc")
if (exists(checksumFile)) {
// checksum file exists, deleting it
delete(checksumFile)
}
} catch {
case NonFatal(_) => ...
}
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.
Nice finding! HDFS-14762 looks odd but we have to live with it. The suggestion looks great.
Addressed. HADOOP JIRA issue is included in both code comment and PR description. Please take a look again. Thanks in advance! |
Test build #109604 has finished for PR 25488 at commit
|
@HeartSaVioR Thanks! I merged to master. Could you submit a backport PR for branch-2.4? |
Thanks for the quick reviewing and merging! I'll raise PR for branch-2.4 soon. |
…rc files This PR fixes the leak of crc files from CheckpointFileManager when FileContextBasedCheckpointFileManager is being used. Spark hits the Hadoop bug, [HADOOP-16255](https://issues.apache.org/jira/browse/HADOOP-16255) which seems to be a long-standing issue. This is there're two `renameInternal` methods: ``` public void renameInternal(Path src, Path dst) public void renameInternal(final Path src, final Path dst, boolean overwrite) ``` which should be overridden to handle all cases but ChecksumFs only overrides method with 2 params, so when latter is called FilterFs.renameInternal(...) is called instead, and it will do rename with RawLocalFs as underlying filesystem. The bug is related to FileContext, so FileSystemBasedCheckpointFileManager is not affected. [SPARK-17475](https://issues.apache.org/jira/browse/SPARK-17475) took a workaround for this bug, but [SPARK-23966](https://issues.apache.org/jira/browse/SPARK-23966) seemed to bring regression. This PR deletes crc file as "best-effort" when renaming, as failing to delete crc file is not that critical to fail the task. This PR prevents crc files not being cleaned up even purging batches. Too many files in same directory often hurts performance, as well as each crc file occupies more space than its own size so possible to occupy nontrivial amount of space when batches go up to 100000+. No. Some unit tests are modified to check leakage of crc files. Closes apache#25488 from HeartSaVioR/SPARK-28025. Authored-by: Jungtaek Lim (HeartSaVioR) <kabhwan@gmail.com> Signed-off-by: Shixiong Zhu <zsxwing@gmail.com>
What changes were proposed in this pull request?
This PR fixes the leak of crc files from CheckpointFileManager when FileContextBasedCheckpointFileManager is being used.
Spark hits the Hadoop bug, HADOOP-16255 which seems to be a long-standing issue.
This is there're two
renameInternal
methods:which should be overridden to handle all cases but ChecksumFs only overrides method with 2 params, so when latter is called FilterFs.renameInternal(...) is called instead, and it will do rename with RawLocalFs as underlying filesystem.
The bug is related to FileContext, so FileSystemBasedCheckpointFileManager is not affected.
SPARK-17475 took a workaround for this bug, but SPARK-23966 seemed to bring regression.
This PR deletes crc file as "best-effort" when renaming, as failing to delete crc file is not that critical to fail the task.
Why are the changes needed?
This PR prevents crc files not being cleaned up even purging batches. Too many files in same directory often hurts performance, as well as each crc file occupies more space than its own size so possible to occupy nontrivial amount of space when batches go up to 100000+.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Some unit tests are modified to check leakage of crc files.