Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/9241#discussion_r43458691
--- 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 --
Couldn't this leave the JVM in an inconsistent state? Or is the idea that
`OutOfMemoryError`s thrown in this thread will perhaps be recoverable? If we're
really running low on memory, I suppose there's a good chance that other
threads could hit OOM as well. I guess that those threads won't have their OOMs
caught and will still be able to halt the JVM.
---
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]