Skip to content

Commit 2e0c528

Browse files
Sital Kediadavies
authored andcommitted
[SPARK-13958] Executor OOM due to unbounded growth of pointer array in…
## What changes were proposed in this pull request? This change fixes the executor OOM which was recently introduced in PR #11095 (Please fill in changes proposed in this fix) ## How was this patch tested? Tested by running a spark job on the cluster. (Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests) (If this patch involves UI changes, please attach a screenshot; otherwise, remove this) … Sorter Author: Sital Kedia <[email protected]> Closes #11794 from sitalkedia/SPARK-13958.
1 parent 3537782 commit 2e0c528

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

core/src/main/java/org/apache/spark/shuffle/sort/ShuffleExternalSorter.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,18 @@ private void growPointerArrayIfNecessary() throws IOException {
320320
assert(inMemSorter != null);
321321
if (!inMemSorter.hasSpaceForAnotherRecord()) {
322322
long used = inMemSorter.getMemoryUsage();
323-
LongArray array = allocateArray(used / 8 * 2);
323+
LongArray array;
324+
try {
325+
// could trigger spilling
326+
array = allocateArray(used / 8 * 2);
327+
} catch (OutOfMemoryError e) {
328+
// should have trigger spilling
329+
if (!inMemSorter.hasSpaceForAnotherRecord()) {
330+
logger.error("Unable to grow the pointer array");
331+
throw e;
332+
}
333+
return;
334+
}
324335
// check if spilling is triggered or not
325336
if (inMemSorter.hasSpaceForAnotherRecord()) {
326337
freeArray(array);

core/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorter.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,18 @@ private void growPointerArrayIfNecessary() throws IOException {
293293
assert(inMemSorter != null);
294294
if (!inMemSorter.hasSpaceForAnotherRecord()) {
295295
long used = inMemSorter.getMemoryUsage();
296-
LongArray array = allocateArray(used / 8 * 2);
296+
LongArray array;
297+
try {
298+
// could trigger spilling
299+
array = allocateArray(used / 8 * 2);
300+
} catch (OutOfMemoryError e) {
301+
// should have trigger spilling
302+
if (!inMemSorter.hasSpaceForAnotherRecord()) {
303+
logger.error("Unable to grow the pointer array");
304+
throw e;
305+
}
306+
return;
307+
}
297308
// check if spilling is triggered or not
298309
if (inMemSorter.hasSpaceForAnotherRecord()) {
299310
freeArray(array);

0 commit comments

Comments
 (0)