Github user andrewor14 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1165#discussion_r15092309
  
    --- Diff: core/src/main/scala/org/apache/spark/CacheManager.scala ---
    @@ -140,14 +144,39 @@ private[spark] class CacheManager(blockManager: 
BlockManager) extends Logging {
               throw new BlockException(key, s"Block manager failed to return 
cached value for $key!")
           }
         } else {
    -      /* This RDD is to be cached in memory. In this case we cannot pass 
the computed values
    +      /*
    +       * This RDD is to be cached in memory. In this case we cannot pass 
the computed values
            * to the BlockManager as an iterator and expect to read it back 
later. This is because
            * we may end up dropping a partition from memory store before 
getting it back, e.g.
    -       * when the entirety of the RDD does not fit in memory. */
    -      val elements = new ArrayBuffer[Any]
    -      elements ++= values
    -      updatedBlocks ++= blockManager.put(key, elements, storageLevel, 
tellMaster = true)
    -      elements.iterator.asInstanceOf[Iterator[T]]
    +       * when the entirety of the RDD does not fit in memory.
    +       *
    +       * In addition, we must be careful to not unfold the entire 
partition in memory at once.
    +       * Otherwise, we may cause an OOM exception if the JVM does not have 
enough space for this
    +       * single partition. Instead, we unfold the values cautiously, 
potentially aborting and
    +       * dropping the partition to disk if applicable.
    +       */
    +      blockManager.memoryStore.unfoldSafely(key, values, updatedBlocks) 
match {
    +        case Left(arrayValues) =>
    +          // We have successfully unfolded the entire partition, so cache 
it in memory
    +          updatedBlocks ++= blockManager.put(key, arrayValues, 
storageLevel, tellMaster = true)
    +          arrayValues.iterator.asInstanceOf[Iterator[T]]
    --- End diff --
    
    We actually can't make `unrollSafely` more specific because arrays are not 
covariant. See my comment elsewhere.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to