Github user massie commented on a diff in the pull request:
https://github.com/apache/spark/pull/6423#discussion_r32746147
--- Diff:
core/src/main/scala/org/apache/spark/storage/ShuffleBlockFetcherIterator.scala
---
@@ -290,22 +287,15 @@ final class ShuffleBlockFetcherIterator(
sendRequest(fetchRequests.dequeue())
}
- val iteratorTry: Try[Iterator[Any]] = result match {
+ val iteratorTry: Try[InputStream] = result match {
case FailureFetchResult(_, e) =>
Failure(e)
case SuccessFetchResult(blockId, _, buf) =>
// There is a chance that createInputStream can fail (e.g.
fetching a local file that does
// not exist, SPARK-4085). In that case, we should propagate the
right exception so
// the scheduler gets a FetchFailedException.
- Try(buf.createInputStream()).map { is0 =>
- val is = blockManager.wrapForCompression(blockId, is0)
- val iter =
serializerInstance.deserializeStream(is).asKeyValueIterator
- CompletionIterator[Any, Iterator[Any]](iter, {
- // Once the iterator is exhausted, release the buffer and set
currentResult to null
- // so we don't release it again in cleanup.
- currentResult = null
- buf.release()
- })
+ Try(buf.createInputStream()).map { inputStream =>
--- End diff --
We don't need to worry about a memory leak when the task exits with success
or failure since there is a cleanup method registered with the task context,
e.g.
```
// Add a task completion callback (called in both success case and failure
case) to cleanup.
context.addTaskCompletionListener(_ => cleanup())
```
However, you're correct that there would be a memory (and file handle)
leak, if the `InputStream` isn't closed in the `ShuffleReader`. This PR
prevents that since
`serializerInstance.deserializeStream(wrappedStream).asKeyValueIterator`
returns a `NextIterator` which closes the stream when the last record is read.
To be more defensive and potentially simplify the code, it might make sense
to have a call to `ShuffleBlockFetcherIterator.next()` to not just return the
next `InputStream` but also `close()` the last one. This would prevent callers
from having more than one `InputStream` open at a time but I don't think we
want that anyway?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]