-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-35027][CORE] Close the inputStream in FileAppender when writin… #33263
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,12 @@ import org.apache.spark.util.{IntParam, Utils} | |
/** | ||
* Continuously appends the data from an input stream into the given file. | ||
*/ | ||
private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSize: Int = 8192) | ||
extends Logging { | ||
private[spark] class FileAppender( | ||
inputStream: InputStream, | ||
file: File, | ||
bufferSize: Int = 8192, | ||
closeStreams: Boolean = false | ||
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 name it 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. Look at this again. When will we explicitly set |
||
) extends Logging { | ||
@volatile private var outputStream: FileOutputStream = null | ||
@volatile private var markedForStop = false // has the appender been asked to stopped | ||
|
||
|
@@ -76,7 +80,13 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi | |
} | ||
} | ||
} { | ||
closeFile() | ||
try { | ||
if (closeStreams) { | ||
inputStream.close() | ||
} | ||
Ngone51 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} finally { | ||
closeFile() | ||
} | ||
} | ||
} catch { | ||
case e: Exception => | ||
|
@@ -113,7 +123,12 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi | |
private[spark] object FileAppender extends Logging { | ||
|
||
/** Create the right appender based on Spark configuration */ | ||
def apply(inputStream: InputStream, file: File, conf: SparkConf): FileAppender = { | ||
srowen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def apply( | ||
inputStream: InputStream, | ||
file: File, | ||
conf: SparkConf, | ||
closeStreams: Boolean = false | ||
) : FileAppender = { | ||
|
||
val rollingStrategy = conf.get(config.EXECUTOR_LOGS_ROLLING_STRATEGY) | ||
val rollingSizeBytes = conf.get(config.EXECUTOR_LOGS_ROLLING_MAX_SIZE) | ||
|
@@ -141,27 +156,29 @@ private[spark] object FileAppender extends Logging { | |
validatedParams.map { | ||
case (interval, pattern) => | ||
new RollingFileAppender( | ||
inputStream, file, new TimeBasedRollingPolicy(interval, pattern), conf) | ||
inputStream, file, new TimeBasedRollingPolicy(interval, pattern), conf, | ||
closeStreams = closeStreams) | ||
}.getOrElse { | ||
new FileAppender(inputStream, file) | ||
new FileAppender(inputStream, file, closeStreams = closeStreams) | ||
} | ||
} | ||
|
||
def createSizeBasedAppender(): FileAppender = { | ||
rollingSizeBytes match { | ||
case IntParam(bytes) => | ||
logInfo(s"Rolling executor logs enabled for $file with rolling every $bytes bytes") | ||
new RollingFileAppender(inputStream, file, new SizeBasedRollingPolicy(bytes), conf) | ||
new RollingFileAppender( | ||
inputStream, file, new SizeBasedRollingPolicy(bytes), conf, closeStreams = closeStreams) | ||
case _ => | ||
logWarning( | ||
s"Illegal size [$rollingSizeBytes] for rolling executor logs, rolling logs not enabled") | ||
new FileAppender(inputStream, file) | ||
new FileAppender(inputStream, file, closeStreams = closeStreams) | ||
} | ||
} | ||
|
||
rollingStrategy match { | ||
case "" => | ||
new FileAppender(inputStream, file) | ||
new FileAppender(inputStream, file, closeStreams = closeStreams) | ||
case "time" => | ||
createTimeBasedAppender() | ||
case "size" => | ||
|
@@ -170,7 +187,7 @@ private[spark] object FileAppender extends Logging { | |
logWarning( | ||
s"Illegal strategy [$rollingStrategy] for rolling executor logs, " + | ||
s"rolling logs not enabled") | ||
new FileAppender(inputStream, file) | ||
new FileAppender(inputStream, file, closeStreams = closeStreams) | ||
} | ||
} | ||
} | ||
|
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.