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

    https://github.com/apache/spark/pull/9241#discussion_r43451271
  
    --- Diff: 
core/src/main/java/org/apache/spark/shuffle/sort/ShuffleExternalSorter.java ---
    @@ -353,15 +320,22 @@ private void growPointerArrayIfNecessary() throws 
IOException {
         assert(inMemSorter != null);
         if (!inMemSorter.hasSpaceForAnotherRecord()) {
           logger.debug("Attempting to expand sort pointer array");
    -      final long oldPointerArrayMemoryUsage = inMemSorter.getMemoryUsage();
    -      final long memoryToGrowPointerArray = oldPointerArrayMemoryUsage * 2;
    -      final long memoryAcquired = 
taskMemoryManager.acquireExecutionMemory(memoryToGrowPointerArray);
    -      if (memoryAcquired < memoryToGrowPointerArray) {
    -        taskMemoryManager.releaseExecutionMemory(memoryAcquired);
    -        spill();
    -      } else {
    -        inMemSorter.expandPointerArray();
    -        
taskMemoryManager.releaseExecutionMemory(oldPointerArrayMemoryUsage);
    +      long used = inMemSorter.getMemoryUsage();
    +      long needed = inMemSorter.getMemoryToExpand();
    +      try {
    +        acquireMemory(used + needed);  // could trigger spilling
    +        if (inMemSorter.hasSpaceForAnotherRecord()) {
    +          releaseMemory(used + needed);
    +        } else {
    +          logger.debug("Expand sort pointer array");
    +          inMemSorter.expandPointerArray();
    +          releaseMemory(used);
    +        }
    +      } catch (OutOfMemoryError oom) {
    --- End diff --
    
    Actual it's better to also catch the OOM from JVM, in the case that we 
thought we have enough memory but actually it's not. I hit this problem during 
higher workload test.


---
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]

Reply via email to