-
Notifications
You must be signed in to change notification settings - Fork 28.7k
SPARK-1656: Fix potential resource leaks #577
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
071fdd1
afc3383
4521d6e
28b90dc
2de96e5
c431095
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 |
---|---|---|
|
@@ -73,7 +73,22 @@ private[spark] class DiskStore(blockManager: BlockManager, diskManager: DiskBloc | |
val startTime = System.currentTimeMillis | ||
val file = diskManager.getFile(blockId) | ||
val outputStream = new FileOutputStream(file) | ||
blockManager.dataSerializeStream(blockId, outputStream, values) | ||
try { | ||
try { | ||
blockManager.dataSerializeStream(blockId, outputStream, values) | ||
} finally { | ||
// Close outputStream here because it should be closed before file is deleted. | ||
outputStream.close() | ||
} | ||
} catch { | ||
case e: Throwable => { | ||
if (file.exists()) { | ||
file.delete() | ||
} | ||
throw e | ||
} | ||
} | ||
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 what you had before was actually clearer. Nested 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 noticed that 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. Hm I'm still not so sure about having the nested 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. The previous codes are: 1 try {
2 blockManager.dataSerializeStream(blockId, outputStream, values)
3 outputStream.close()
4 } catch {
5 case e: Throwable => {
6 outputStream.close()
7 if(file.exists()) {
8 file.delete()
9 }
10 throw e
11 }
12 } My concern is if L6 outputStream.close() throws an exception, 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. @andrewor14 do you agree my concern? 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. Ok, that seems fine. |
||
|
||
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. Why not do the full 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 want to close the stream before deleting the file. 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. On Unix at least that's not necessary. It's possible to delete a file with open fds. The inodes will be released when you close the fd. Don't know if Windows follows the same semantics, though. |
||
val length = file.length | ||
|
||
val timeTaken = System.currentTimeMillis - startTime | ||
|
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 you actually want to handle this case; you should delete the file in case write failed.