-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33298][CORE] Introduce new API to FileCommitProtocol allow flexible file naming #33012
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,35 @@ abstract class FileCommitProtocol extends Logging { | |
| */ | ||
| def newTaskTempFile(taskContext: TaskAttemptContext, dir: Option[String], ext: String): String | ||
|
|
||
| /** | ||
| * Notifies the commit protocol to add a new file, and gets back the full path that should be | ||
| * used. Must be called on the executors when running tasks. | ||
| * | ||
| * Note that the returned temp file may have an arbitrary path. The commit protocol only | ||
| * promises that the file will be at the location specified by the arguments after job commit. | ||
| * | ||
| * The "dir" parameter specifies the sub-directory within the base path, used to specify | ||
| * partitioning. The "spec" parameter specifies the file name. The rest are left to the commit | ||
| * protocol implementation to decide. | ||
| * | ||
| * Important: it is the caller's responsibility to add uniquely identifying content to "spec" | ||
| * if a task is going to write out multiple files to the same dir. The file commit protocol only | ||
| * guarantees that files written by different tasks will not conflict. | ||
| * | ||
| * This API should be implemented and called, instead of | ||
| * [[newTaskTempFile(taskContest, dir, ext)]]. Provide a default implementation here to be | ||
| * backward compatible with custom [[FileCommitProtocol]] implementations before Spark 3.2.0. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should mark this as an API (e.g.,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit weird to say about "backward compatible" here. If this isn't an API, we should explicitly mention that this isn't an API at least here to avoid giving a false impression to dev.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HyukjinKwon - will it look better as below?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we mark it as
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @cloud-fan to get more feedback
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine to mark it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. Let me create a PR now. |
||
| */ | ||
| def newTaskTempFile( | ||
| taskContext: TaskAttemptContext, dir: Option[String], spec: FileNameSpec): String = { | ||
| if (spec.prefix.isEmpty) { | ||
| newTaskTempFile(taskContext, dir, spec.suffix) | ||
| } else { | ||
| throw new UnsupportedOperationException(s"${getClass.getSimpleName}.newTaskTempFile does " + | ||
| s"not support file name prefix: ${spec.prefix}") | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Similar to newTaskTempFile(), but allows files to committed to an absolute output location. | ||
| * Depending on the implementation, there may be weaker guarantees around adding files this way. | ||
|
|
@@ -103,6 +132,34 @@ abstract class FileCommitProtocol extends Logging { | |
| def newTaskTempFileAbsPath( | ||
| taskContext: TaskAttemptContext, absoluteDir: String, ext: String): String | ||
|
|
||
| /** | ||
| * Similar to newTaskTempFile(), but allows files to committed to an absolute output location. | ||
| * Depending on the implementation, there may be weaker guarantees around adding files this way. | ||
| * | ||
| * The "absoluteDir" parameter specifies the final absolute directory of file. The "spec" | ||
| * parameter specifies the file name. The rest are left to the commit protocol implementation to | ||
| * decide. | ||
| * | ||
| * Important: it is the caller's responsibility to add uniquely identifying content to "spec" | ||
| * if a task is going to write out multiple files to the same dir. The file commit protocol only | ||
| * guarantees that files written by different tasks will not conflict. | ||
| * | ||
| * This API should be implemented and called, instead of | ||
| * [[newTaskTempFileAbsPath(taskContest, absoluteDir, ext)]]. Provide a default implementation | ||
| * here to be backward compatible with custom [[FileCommitProtocol]] implementations before | ||
| * Spark 3.2.0. | ||
| */ | ||
| def newTaskTempFileAbsPath( | ||
| taskContext: TaskAttemptContext, absoluteDir: String, spec: FileNameSpec): String = { | ||
| if (spec.prefix.isEmpty) { | ||
| newTaskTempFileAbsPath(taskContext, absoluteDir, spec.suffix) | ||
| } else { | ||
| throw new UnsupportedOperationException( | ||
| s"${getClass.getSimpleName}.newTaskTempFileAbsPath does not support file name prefix: " + | ||
| s"${spec.prefix}") | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Commits a task after the writes succeed. Must be called on the executors when running tasks. | ||
| */ | ||
|
|
@@ -174,3 +231,12 @@ object FileCommitProtocol extends Logging { | |
| new Path(path, ".spark-staging-" + jobId) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The specification for Spark output file name. | ||
| * This is used by [[FileCommitProtocol]] to create full path of file. | ||
| * | ||
| * @param prefix Prefix of file. | ||
| * @param suffix Suffix of file. | ||
| */ | ||
| final case class FileNameSpec(prefix: String, suffix: String) | ||
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 is not true, commit protocol needs to guarantee name uniqueness, as caller side only gives prefix and suffix
Uh oh!
There was an error while loading. Please reload this page.
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 whole sentence is:
I think this refers to the case when in one task, caller calls newTaskTempFile() multiple times with same
spec, the caller should not expect commit protocol returning unique different file path every time. The current implementation ofHadoopMapReduceCommitProtocolwould return same path ifextbeing same. This is a copy-paste from original comment ofnewTaskTempFile.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 see!