-
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 #28363
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 1 commit
686fc6d
9bc07e3
61f9089
5739592
c8b6d24
e1834ea
8aceb86
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 |
|---|---|---|
|
|
@@ -136,8 +136,9 @@ class FileStreamSink( | |
| private val basePath = new Path(path) | ||
| private val logPath = getMetadataLogPath(basePath.getFileSystem(hadoopConf), basePath, | ||
| sparkSession.sessionState.conf) | ||
| private val fileLog = | ||
| new FileStreamSinkLog(FileStreamSinkLog.VERSION, sparkSession, logPath.toString) | ||
| private val outputTimeToLive = options.get("outputRetentionMs").map(_.toLong) | ||
|
||
| private val fileLog = new FileStreamSinkLog(FileStreamSinkLog.VERSION, sparkSession, | ||
| logPath.toString, outputTimeToLive) | ||
|
|
||
| private def basicWriteJobStatsTracker: BasicWriteJobStatsTracker = { | ||
| val serializableHadoopConf = new SerializableConfiguration(hadoopConf) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,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) | ||
|
|
@@ -96,6 +97,19 @@ class FileStreamSinkLog( | |
| require(defaultCompactInterval > 0, | ||
| 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 shouldRetain(log: SinkFileStatus): Boolean = { | ||
| val curTime = System.currentTimeMillis() | ||
|
||
| if (curTime - log.modificationTime > ttlMs) { | ||
| logDebug(s"${log.path} excluded by retention - current time: $curTime / " + | ||
| s"modification time: ${log.modificationTime} / TTL: $ttlMs.") | ||
| false | ||
| } else { | ||
| true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object FileStreamSinkLog { | ||
|
|
||
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.
There are 2 time fields in
SinkFileStatus,modificationTimeandcommitTime. Maybe worth to mention the exact field which is used for comparison to make it 100% clear.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 guess we avoid exposing the implementation details in docs. e.g. If I'm not mistaken, there's no explanation of the format of the metadata, hence it would be confusing which field is being used because end users even don't know what they are.
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.
You're right and we're not explaining metadata details to users. What users would like to understand though what the reference TTL is bound to. As half developer and half user I was a bit confused which field
SinkFileStatuswe would like to refer to. Since we've removed the (in my view) duplicate field I'm fine here.