-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24225][CORE] Support closing AutoClosable objects in MemoryStore #21322
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
f254f94
62d46d3
94512e6
790c906
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import java.io.OutputStream | |
| import java.nio.ByteBuffer | ||
| import java.util.LinkedHashMap | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
| import scala.collection.mutable | ||
| import scala.collection.mutable.ArrayBuffer | ||
| import scala.reflect.ClassTag | ||
|
|
@@ -384,15 +385,30 @@ private[spark] class MemoryStore( | |
| } | ||
| } | ||
|
|
||
| private def maybeReleaseResources(resource: (BlockId, MemoryEntry[_])): Unit = { | ||
| maybeReleaseResources(resource._1, resource._2) | ||
| } | ||
|
|
||
| private def maybeReleaseResources(blockId: BlockId, entry: MemoryEntry[_]): Unit = { | ||
| entry match { | ||
| case SerializedMemoryEntry(buffer, _, _) => buffer.dispose() | ||
| case DeserializedMemoryEntry(values: Array[Any], _, _) => maybeCloseValues(values, blockId) | ||
| case _ => | ||
| } | ||
| } | ||
|
|
||
| private def maybeCloseValues(values: Array[Any], blockId: BlockId): Unit = { | ||
| if (blockId.isBroadcast) { | ||
| values.foreach(value => Utils.tryClose(value)) | ||
|
Member
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. Just a style thing, but could be |
||
| } | ||
| } | ||
|
|
||
| def remove(blockId: BlockId): Boolean = memoryManager.synchronized { | ||
| val entry = entries.synchronized { | ||
| entries.remove(blockId) | ||
| } | ||
| if (entry != null) { | ||
| entry match { | ||
| case SerializedMemoryEntry(buffer, _, _) => buffer.dispose() | ||
| case _ => | ||
| } | ||
| maybeReleaseResources(blockId, entry) | ||
| memoryManager.releaseStorageMemory(entry.size, entry.memoryMode) | ||
| logDebug(s"Block $blockId of size ${entry.size} dropped " + | ||
| s"from memory (free ${maxMemory - blocksMemoryUsed})") | ||
|
|
@@ -404,6 +420,7 @@ private[spark] class MemoryStore( | |
|
|
||
| def clear(): Unit = memoryManager.synchronized { | ||
| entries.synchronized { | ||
| entries.asScala.foreach(maybeReleaseResources) | ||
| entries.clear() | ||
| } | ||
| onHeapUnrollMemoryMap.clear() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1930,6 +1930,18 @@ private[spark] object Utils extends Logging { | |
| } | ||
| } | ||
|
|
||
| def tryClose(value: Any): Unit = { | ||
|
Member
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. This should accept at best |
||
| value match { | ||
| case closable: AutoCloseable => | ||
| try { | ||
| closable.close() | ||
| } catch { | ||
| case ex: Exception => logError(s"Failed to close AutoClosable $closable", ex) | ||
| } | ||
| case _ => | ||
| } | ||
| } | ||
|
|
||
| /** Returns true if the given exception was fatal. See docs for scala.util.control.NonFatal. */ | ||
| def isFatalError(e: Throwable): Boolean = { | ||
| e match { | ||
|
|
||
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.
Why not just make these case classes
Closeableand then you can close them consistently