Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/9241#discussion_r43450295
--- 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 --
We probably shouldn't catch `OutOfMemoryError`, since this could lead to
problems in case we catch an OOM thrown by the JVM and not by our own code.
Instead, we might want to throw our own `SparkOutOfMemoryError` exception or
something like that.
---
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]