Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/11534#discussion_r55613252
--- Diff: core/src/main/scala/org/apache/spark/storage/BlockManager.scala
---
@@ -407,11 +399,49 @@ private[spark] class BlockManager(
}
/**
- * Get block from local block manager.
+ * Get block from local block manager as an iterator of Java objects.
*/
- def getLocal(blockId: BlockId): Option[BlockResult] = {
+ def getLocalValues(blockId: BlockId): Option[BlockResult] = {
logDebug(s"Getting local block $blockId")
- doGetLocal(blockId, asBlockResult =
true).asInstanceOf[Option[BlockResult]]
+ blockInfoManager.lockForReading(blockId) match {
+ case None =>
+ logDebug(s"Block $blockId was not found")
+ None
+ case Some(info) =>
+ val level = info.level
+ logDebug(s"Level for block $blockId is $level")
+ if (level.useMemory && memoryStore.contains(blockId)) {
+ val iter: Iterator[Any] = if (level.deserialized) {
+ memoryStore.getValues(blockId).get
+ } else {
+ dataDeserialize(blockId, memoryStore.getBytes(blockId).get)
+ }
+ val ci = CompletionIterator[Any, Iterator[Any]](iter,
releaseLock(blockId))
+ Some(new BlockResult(ci, DataReadMethod.Memory, info.size))
+ } else if (level.useDisk && diskStore.contains(blockId)) {
+ val valuesFromDisk = dataDeserialize(blockId,
diskStore.getBytes(blockId))
+ val iterToReturn: Iterator[Any] = {
+ if (level.deserialized) {
+ // Cache the values before returning them
+ memoryStore.putIterator(blockId, valuesFromDisk, level)
match {
+ case Left(iter) =>
+ // The memory store put() failed, so it returned the
iterator back to us:
+ iter
+ case Right(_) =>
+ // The put() succeeded, so we can read the values back:
+ memoryStore.getValues(blockId).get
+ }
+ } else {
+ valuesFromDisk
+ }
+ }
+ val ci = CompletionIterator[Any, Iterator[Any]](iterToReturn,
releaseLock(blockId))
+ Some(new BlockResult(ci, DataReadMethod.Disk, info.size))
+ } else {
+ releaseLock(blockId)
--- End diff --
can you add a comment in the javadoc on when the lock will be released?
---
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]