Skip to content

[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

Closed
wants to merge 2 commits into from

Conversation

HeartSaVioR
Copy link
Contributor

@HeartSaVioR HeartSaVioR commented Aug 18, 2019

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:

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 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.

// This check also tests for regressions of SPARK-17475
val allFiles = new File(metadataLog.metadataPath.toString).listFiles()
.filter(!_.getName.startsWith(".")).toSeq
Copy link
Contributor Author

@HeartSaVioR HeartSaVioR Aug 18, 2019

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) {
Copy link
Contributor Author

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.

@HeartSaVioR
Copy link
Contributor Author

cc. @zsxwing @gaborgsomogyi
Also cc. @skonto as @skonto put efforts to analyze this issue in JIRA issue before, so may be able to point out if I'm missing anything.

@@ -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)
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@zsxwing
Copy link
Member

zsxwing commented Aug 19, 2019

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?

@HeartSaVioR
Copy link
Contributor Author

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.

@HeartSaVioR
Copy link
Contributor Author

HeartSaVioR commented Aug 19, 2019

And I'm not 100% sure of intention, but if we intended to disable crc via below line, it doesn't seem to work:

fc.create(path, EnumSet.of(CREATE, OVERWRITE), CreateOpts.checksumParam(ChecksumOpt.createDisabled()))

@skonto already analyzed relevant part but didn't figure out any Hadoop JIRA issue:

https://issues.apache.org/jira/browse/SPARK-28025?focusedCommentId=16862339&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-16862339

@SparkQA
Copy link

SparkQA commented Aug 19, 2019

Test build #109302 has finished for PR 25488 at commit e27baa9.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HeartSaVioR
Copy link
Contributor Author

HeartSaVioR commented Aug 19, 2019

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:

underlyingStream match {
  case e: FSDataOutputStream if e.getWrappedStream.isInstanceOf[FSOutputSummer] =>
    val checksumFile = new Path(tempPath.getParent, s".${tempPath.getName}.crc")
    fm.delete(checksumFile)
  case _ =>
}

adding above block after underlyingStream.close() would also work. This change will touch RenameBasedFSDataOutputStream.

As the annotations of the class describe, FSOutputSummer is Unstable and LimitedPrivate so not sure we would like to rely on this though.

@SparkQA
Copy link

SparkQA commented Aug 19, 2019

Test build #109365 has finished for PR 25488 at commit c30b045.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@zsxwing zsxwing left a 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)
Copy link
Member

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.

Copy link
Contributor Author

@HeartSaVioR HeartSaVioR Aug 23, 2019

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")
Copy link
Member

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(_) => ...
}

Copy link
Contributor Author

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.

@HeartSaVioR
Copy link
Contributor Author

HeartSaVioR commented Aug 23, 2019

Addressed. HADOOP JIRA issue is included in both code comment and PR description. Please take a look again. Thanks in advance!

@SparkQA
Copy link

SparkQA commented Aug 23, 2019

Test build #109604 has finished for PR 25488 at commit 376b7eb.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@asfgit asfgit closed this in 406c533 Aug 23, 2019
@zsxwing
Copy link
Member

zsxwing commented Aug 23, 2019

@HeartSaVioR Thanks! I merged to master. Could you submit a backport PR for branch-2.4?

@HeartSaVioR
Copy link
Contributor Author

Thanks for the quick reviewing and merging! I'll raise PR for branch-2.4 soon.

HeartSaVioR added a commit to HeartSaVioR/spark that referenced this pull request Aug 23, 2019
…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>
@HeartSaVioR HeartSaVioR deleted the SPARK-28025 branch August 23, 2019 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants