-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-27188][SS] FileStreamSink: provide a new option to have retention on output files #24128
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
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
[SPARK-27188][SS] Introduce retention of output entities for FileStre…
…amSink
- Loading branch information
commit 92f9b7b0f20b12a80281c70d7b85d72d9fa657d8
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ import org.apache.spark.sql.internal.SQLConf | |
| * @param blockReplication the block replication. | ||
| * @param blockSize the block size. | ||
| * @param action the file action. Must be either "add" or "delete". | ||
| * @param commitTime the time which batch for the file is committed | ||
| */ | ||
| case class SinkFileStatus( | ||
| path: String, | ||
|
|
@@ -45,7 +46,20 @@ case class SinkFileStatus( | |
| modificationTime: Long, | ||
| blockReplication: Int, | ||
| blockSize: Long, | ||
| action: String) { | ||
| action: String, | ||
| commitTime: Long) { | ||
|
|
||
| def this( | ||
| path: String, | ||
| size: Long, | ||
| isDir: Boolean, | ||
| modificationTime: Long, | ||
| blockReplication: Int, | ||
| blockSize: Long, | ||
| action: String) { | ||
| // use modification time if we don't know about exact commit time | ||
| this(path, size, isDir, modificationTime, blockReplication, blockSize, action, modificationTime) | ||
| } | ||
|
|
||
| def toFileStatus: FileStatus = { | ||
| new FileStatus( | ||
|
|
@@ -62,7 +76,8 @@ object SinkFileStatus { | |
| modificationTime = f.getModificationTime, | ||
| blockReplication = f.getReplication, | ||
| blockSize = f.getBlockSize, | ||
| action = FileStreamSinkLog.ADD_ACTION) | ||
| action = FileStreamSinkLog.ADD_ACTION, | ||
| commitTime = f.getModificationTime) | ||
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -81,7 +96,8 @@ object SinkFileStatus { | |
| class FileStreamSinkLog( | ||
| metadataLogVersion: Int, | ||
| sparkSession: SparkSession, | ||
| path: String) | ||
| path: String, | ||
| outputTimeToLiveMs: Option[Long] = None) | ||
| extends CompactibleFileStreamLog[SinkFileStatus](metadataLogVersion, sparkSession, path) { | ||
|
|
||
| private implicit val formats = Serialization.formats(NoTypeHints) | ||
|
|
@@ -97,8 +113,13 @@ class FileStreamSinkLog( | |
| s"Please set ${SQLConf.FILE_SINK_LOG_COMPACT_INTERVAL.key} (was $defaultCompactInterval) " + | ||
| "to a positive value.") | ||
|
|
||
| private val ttlMs = outputTimeToLiveMs.getOrElse(Long.MaxValue) | ||
|
|
||
| override def compactLogs(logs: Seq[SinkFileStatus]): Seq[SinkFileStatus] = { | ||
| val deletedFiles = logs.filter(_.action == FileStreamSinkLog.DELETE_ACTION).map(_.path).toSet | ||
| val curTime = System.currentTimeMillis() | ||
| val deletedFiles = logs.filter { log => | ||
| log.action == FileStreamSinkLog.DELETE_ACTION || (curTime - log.commitTime) > ttlMs | ||
| }.map(_.path).toSet | ||
| if (deletedFiles.isEmpty) { | ||
| logs | ||
| } else { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we concern about dealing with Hadoop timestamp / timezone, we can just set it to
Long.MaxValue. This means existing entries in metadata will not be affected by the 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.
Just changed it. Retention logic completely relies on commit timestamp and not relevant to individual file's modification time.